Skip to content

Commit

Permalink
fix(otel): prevent panic in shutdown (#711)
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 authored Sep 7, 2023
1 parent 7232f7e commit 04ea85a
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 04ea85a

Please sign in to comment.