Skip to content

feat(node-experimental): Sync OTEL context with Sentry AsyncContext #8797

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

Merged
merged 3 commits into from
Sep 1, 2023

Conversation

mydea
Copy link
Member

@mydea mydea commented Aug 11, 2023

This PR implements a strategy to sync the OpenTelemetry Context with our own Hub forking for AsyncContext.

This works by fully relying on OpenTelemetry to handle async context isolation/forking.

  1. We implement a custom OTEL ContextManager that wraps the default AsyncHooks manager, but makes sure to also fork the hub for each context change & puts the hub on the OTEL context so we can retrieve it.
  2. Then, we also have a custom Sentry AsyncContextStrategy which just refers to OTEL context and picks the hub from there we put there in 1.

This means we do not need to do any context forking ourselves anymore, so no need for e.g. Sentry.Handlers.requestHandler() and stuff like this.

It should also mean that Sentry & OTEL should be as in sync as possible.

Some notes:

  • Currently only works for AsyncHooks, which should be fine I guess. Could also be exteded to work with other implementations as well.

@mydea mydea requested a review from AbhiPrasad August 11, 2023 08:43
@mydea mydea self-assigned this Aug 11, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 11, 2023

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 75.32 KB (0%)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 31.21 KB (0%)
@sentry/browser - Webpack (gzipped) 21.83 KB (0%)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 69.84 KB (0%)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 28.16 KB (-0.01% 🔽)
@sentry/browser - ES6 CDN Bundle (gzipped) 20.16 KB (0%)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 220.72 KB (0%)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 85 KB (0%)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 59.71 KB (0%)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 31.06 KB (0%)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 75.34 KB (0%)
@sentry/react - Webpack (gzipped) 21.86 KB (0%)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 93.2 KB (0%)
@sentry/nextjs Client - Webpack (gzipped) 50.79 KB (0%)

@mydea mydea force-pushed the fn/node-otel-context branch from dc30b4d to 09aca72 Compare August 30, 2023 08:25
@mydea mydea changed the title feat(node-experimental): Provide otel-powered async context strategy (Draft) feat(node-experimental): Provide otel-powered async context strategy Aug 30, 2023
@mydea mydea marked this pull request as ready for review August 30, 2023 15:02
@mydea mydea changed the title feat(node-experimental): Provide otel-powered async context strategy feat(node-experimental): Sync OTEL context with Sentry AsyncContext Aug 31, 2023
@mydea mydea force-pushed the fn/node-otel-context branch from 09aca72 to 94cfae2 Compare August 31, 2023 08:15
return getHubFromCarrier(carrier);
}

/** TODO docs */
Copy link
Member

Choose a reason for hiding this comment

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

l: shall we add them now, or wait till after?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, will add a little bit of docs!

@mydea mydea force-pushed the fn/node-otel-context branch from 94cfae2 to b111b97 Compare September 1, 2023 08:20
@mydea mydea merged commit 2d7a0d3 into develop Sep 1, 2023
@mydea mydea deleted the fn/node-otel-context branch September 1, 2023 08:50
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.

2 participants