Skip to content

Sentry creates three traces for a single http request (ESM, custom opentelemetry setup) #14065

Closed
@nlochschmidt

Description

@nlochschmidt

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

8.35.0

Framework Version

hapi 21.3.10

Link to Sentry event

No response

Reproduction Example/SDK Setup

https://github.com/nlochschmidt/sentry-duplicate-tracing-bug

Steps to Reproduce

  1. I've setup Sentry and a custom otel setup as described in the docs we are not using Sentry for tracing but another service
  2. Running the server I can see from the logs that instrumentations are setup
  3. When I call the server e.g. curl localhost:3000 I get a spanId and traceId from inside the handler
  4. The ConsoleSpanExporter will print the traces and spans collected after a short time.

Expected Result

I expect to get a single trace with two spans (one for http and one for hapi).

Actual Result

What actually happens is that there are three traces and only one of them (traceId: 9dbf48ed9eee5aa66cba36df77eef90b) has the two spans that are expected, while the other two traces have only a single http root span.

I can see some odd instrumentation scopes @opentelemetry_sentry-patched/instrumentation-http, but interestingly the @opentelemetry/instrumentation-http is on one of the traces with a single span.

Here is the output cleaned up a bit (full output in the example repo README):

{
  traceId: '9dbf48ed9eee5aa66cba36df77eef90b',
  id: '86279d018d1d20f4',
  parentId: 'bb6216be501f6924',
  instrumentationScope: {
    name: '@opentelemetry/instrumentation-hapi',
  },

  name: 'route - /',
  kind: 0,
  attributes: {
    'sentry.sample_rate': 1
  },
  status: { code: 0 },
}
{
  traceId: '04de96dc9304e6376ac87ffa038e53f4',
  id: 'e68a07918c660533',
  parentId: undefined,
  instrumentationScope: {
    name: '@opentelemetry/instrumentation-http',
  },
  name: 'GET',
  kind: 1,
  attributes: {
    'sentry.sample_rate': 1,
    'sentry.parentIsRemote': true,
  },
  status: { code: 0 },
}
{
  traceId: 'e82eb8fe28439cad4cb409199d1759f3',
  id: '01cf0d4b96a81e61',
  parentId: undefined,
  instrumentationScope: {
    name: '@opentelemetry_sentry-patched/instrumentation-http',
  },
  name: 'GET',
  kind: 1,
  attributes: {
    'sentry.sample_rate': 1,
    'sentry.parentIsRemote': true,
    'sentry.origin': 'auto.http.otel.http',
  },
  status: { code: 0 },
  events: [],
  links: []
}
{
  traceId: '9dbf48ed9eee5aa66cba36df77eef90b',
  id: 'bb6216be501f6924',
  parentId: undefined,
  instrumentationScope: {
    name: '@opentelemetry_sentry-patched/instrumentation-http',
  },
  name: 'GET',
  kind: 1,
  attributes: {
    'sentry.sample_rate': 1,
    'sentry.parentIsRemote': true,
    'sentry.origin': 'auto.http.otel.http',
  },
  status: { code: 0 },
}

It works as expected when removing Sentry

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions