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

Conversation

greywolve
Copy link
Contributor

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.

Fixes #692

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.
@@ -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 👍

@tonyo tonyo merged commit 04ea85a into getsentry:master Sep 7, 2023
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Otel] SpanProcessor panic on shutdown with background context
2 participants