Skip to content

Commit

Permalink
fix(otel): prevent panic in shutdown
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
greywolve committed Sep 6, 2023
1 parent 54d884a commit c42267d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions otel/span_processor.go
Expand Up @@ -103,6 +103,10 @@ func (ssp *sentrySpanProcessor) ForceFlush(ctx context.Context) error {

func flushSpanProcessor(ctx context.Context) error {
hub := sentry.GetHubFromContext(ctx)
if hub == nil {
hub = sentry.CurrentHub()
}

// TODO(michi) should we make this configurable?
defer hub.Flush(2 * time.Second)
return nil
Expand Down
2 changes: 1 addition & 1 deletion otel/span_processor_test.go
Expand Up @@ -72,7 +72,7 @@ func TestNewSentrySpanProcessor(t *testing.T) {

func TestSpanProcessorShutdown(t *testing.T) {
spanProcessor, _, tracer := setupSpanProcessorTest()
ctx := emptyContextWithSentry()
ctx := context.Background()
tracer.Start(emptyContextWithSentry(), "spanName")

assertEqual(t, sentrySpanMap.Len(), 1)
Expand Down

0 comments on commit c42267d

Please sign in to comment.