Repository navigation
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/node
SDK Version
7.109.0
Framework Version
Hapi v21.3.7
Link to Sentry event
SDK Setup
Sentry.init({
env: 'local',
dsn: process.env.SENTRY_DSN,
tracesSampleRate: 1.0,
integrations: [
new Sentry.Integrations.Hapi({server}),
],
beforeSend(event) {
// Logging to disk so as not generate any extra breadcrumbs
fs.appendFileSync(debug.${TEST_NAME}.json, JSON.stringify({event}, null, ' ') + '\n');
return event;
},
});
Steps to Reproduce
I've created a repo to illustrate the issue. Simply follow the readme instructions to reproduce.
In a nutshell, two parallel requests made to different endpoints will result in the state of breadcrumbs and tags.transaction being mixed together. There are three test scenarios each of which exhibits a slightly different set of behaviors.
- Synchronous Request handlers
- Asynchronous request handlers
- Asynchronous request handlers where the handler is wrapped with Sentry.runWithAsyncContext
Expected Result
That sentry events have state that is isolated per request.
Actual Result
The state of the Sentry events being captured contains state from other requests. The aforementioned repo shows three different ways this can happen, each of which has a slightly different behavior. Here are basic descriptions of these scenarios and links to actual Sentry events produced.
Synchronous Request Handlers: One event is correct, but one event contains the breadcrumbs that weren't produced by the request.
Asynchronous Request Handlers: The breadcrumbs for the events are mixed, and tags.transaction shows the incorrect value for one event.
- Breadcrumbs from another request included and wrong transaction
- breadcrumbs from another request included
Asynchronous Requests Handlers Wrapped with Sentry.runWithAsyncContext: The breadcrumbs are lost, and tag.transaction is incorrect.
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsNo status
Activity
AbhiPrasad commentedon Apr 3, 2024
Hey @dschom thanks for writing in!
I think this is because we aren't wrapping stuff in async context properly with Hapi.
sentry-javascript/packages/node/src/integrations/hapi/index.ts
Line 66 in 9bfadb5
For now to unblock yourself, you can wrap request handling middleware with
Sentry.runWithAsyncContextas per https://docs.sentry.io/platforms/node/configuration/async-context/. This will ensure requests get isolated.We might not fix this in v7 because we have a new v8 major releasing very soon, and that dramatically improves the Hapi instrumentation experience. I would give this a try:
v8alpha: https://github.com/getsentry/sentry-javascript/releases/tag/8.0.0-alpha.7migration guide: https://github.com/getsentry/sentry-javascript/blob/8.0.0-alpha.7/MIGRATION.md
In v8 setting up hapi works like the following:
Marsup commentedon Apr 26, 2024
I have tried about every possible way to hook
runWithAsyncContextto the request, has anyone succeeded using it?hapi 21 not being instrumented in the beta (open-telemetry/opentelemetry-js-contrib#1985), it's also not an option we can currently use unfortunately.
mydea commentedon Apr 26, 2024
I think at this point we can hope that a new
@opentelemetry/instrumentation-hapiis released soon with the fix for the new hapi version 😬 I made sure to watch that PR as well so we can bump it as soon as they release a fix 🤞feat(node): Support hapi v21 & fix E2E test (#11906)
mydea commentedon May 6, 2024
The next release of the SDK will support v21 of hapi properly!
Marsup commentedon May 6, 2024
Cool, I have tried enforcing the new release with a pnpm override but it didn't have any breadcrumbs, I hope the full release will 🤞🏻