File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ const defaultTimeout = 10 * time.Second
1212
1313var  exp  trace.SpanExporter 
1414
15- // Wait allows span exporter to inhibit application shutdown until it sends all traces 
15+ // Wait allows span exporter to inhibit application shutdown until it sends all traces.  
1616func  Wait (ctx  context.Context ) (err  error ) {
1717	if  exp  !=  nil  {
1818		<- ctx .Done ()
@@ -28,3 +28,19 @@ func Wait(ctx context.Context) (err error) {
2828	}
2929	return  nil 
3030}
31+ 
32+ // Shutdown forces exporter to save all spans and turn off. 
33+ func  Shutdown (ctx  context.Context ) (err  error ) {
34+ 	if  exp  !=  nil  {
35+ 		shutdownContext , cancel  :=  context .WithTimeout (ctx , defaultTimeout )
36+ 		defer  cancel ()
37+ 		err  =  exp .Shutdown (shutdownContext )
38+ 		if  err  !=  nil  {
39+ 			log .Error ().Err (err ).Msgf ("Error saving telemetry spans: %s" , err )
40+ 			return  err 
41+ 		}
42+ 		log .Debug ().Msgf ("All spans are saved" )
43+ 		return  nil 
44+ 	}
45+ 	return  nil 
46+ }
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments