Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(otel): prevent panic in shutdown #711

Merged
merged 1 commit into from Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 {
Copy link
Contributor Author

@greywolve greywolve Sep 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess one question is if anyone is actually going to pass a context in here that contains a hub?

Seems more like this will almost always be something like context.Background() with no hub. I think the original purpose here, at least looking at the otel project, is to allow the user to pass in a context with a timeout. The flush method though already has a timeout, so context passed here isn't really useful to us.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it's not ideal, and relying on people passing the right context is not a good approach.

It might be still good to let people pass sentry.Hub via context (for more flexibility, and maybe in the future allowing multiple span processor instances?), so your fix should be good for now 👍

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