Skip to content

Commit 370453d

Browse files
committed
tracing.Shutdown
1 parent 77fa0f8 commit 370453d

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

tracing/exporter.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const defaultTimeout = 10 * time.Second
1212

1313
var 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.
1616
func 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+
}

0 commit comments

Comments
 (0)