Skip to content

Commit c42267d

Browse files
committed
fix(otel): prevent panic in shutdown
Shutdown panics when passed a background context, or any context which doesn't contain a hub. Returning the current hub if no hub is found on the context prevents this.
1 parent 54d884a commit c42267d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

otel/span_processor.go

+4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ func (ssp *sentrySpanProcessor) ForceFlush(ctx context.Context) error {
103103

104104
func flushSpanProcessor(ctx context.Context) error {
105105
hub := sentry.GetHubFromContext(ctx)
106+
if hub == nil {
107+
hub = sentry.CurrentHub()
108+
}
109+
106110
// TODO(michi) should we make this configurable?
107111
defer hub.Flush(2 * time.Second)
108112
return nil

otel/span_processor_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func TestNewSentrySpanProcessor(t *testing.T) {
7272

7373
func TestSpanProcessorShutdown(t *testing.T) {
7474
spanProcessor, _, tracer := setupSpanProcessorTest()
75-
ctx := emptyContextWithSentry()
75+
ctx := context.Background()
7676
tracer.Start(emptyContextWithSentry(), "spanName")
7777

7878
assertEqual(t, sentrySpanMap.Len(), 1)

0 commit comments

Comments
 (0)