Skip to content

Sentry.Hapi.Integration mixes event state between requests #11411

@dschom

Description

@dschom

Is there an existing issue for this?

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

https://mozilla.sentry.io/issues/5137492864/?project=6231058&query=is%3Aunresolved&referrer=issue-stream&statsPeriod=1h&stream_index=2

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.

Asynchronous Requests Handlers Wrapped with Sentry.runWithAsyncContext: The breadcrumbs are lost, and tag.transaction is incorrect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPackage: nodeIssues related to the Sentry Node SDK

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions