Skip to content

Duplicate auto-instrumented spans in traces #15803

Closed
@serglom21

Description

@serglom21

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

9.1.0

Framework Version

Express 4.21.2

Link to Sentry event

No response

Reproduction Example/SDK Setup

Sentry.init({
    enabled: environment !== 'local' || process.env.SENTRY_ENABLED?.toLowerCase() === 'true',
    environment,
    dsn: process.env.SENTRY_DSN,
    // Mark the release, this will help us pinpoint the source of issues
    release: process.env.SHORT_SHA,
    debug: process.env.SENTRY_DEBUG?.toLowerCase() === 'true',
    tracesSampleRate: Number(process.env.SENTRY_TRACES_SAMPLE_RATE ?? 0.01),
    profilesSampleRate: Number(process.env.SENTRY_PROFILES_SAMPLE_RATE ?? 0.01),
    normalizeDepth: 10,
    initialScope: {
        tags: {
            location: process.env.LOCATION ?? 'unknown',
            container_name: process.env.CONTAINER_NAME ?? 'unknown',
        },
    },
    integrations: [Sentry.prismaIntegration(), nodeProfilingIntegration()],
    beforeBreadcrumb: (breadcrumb, _) => {
        if (breadcrumb.category === 'http') {
            // Ignore spans/breadcrumbs calling apm
            const url = breadcrumb.data?.url;
            if (url?.includes('.split.io/') || url?.includes('ingest.sentry.io/')) {
                return null;
            }
        }
        return breadcrumb;
    },
    beforeSendTransaction: (event, _) => {
        // redact x-access-token from transactions
        if (event.request?.headers && event.request?.headers['x-access-token']) {
            event.request.headers['x-access-token'] = 'REDACTED';
        }
        return event;
    },
    ignoreTransactions: [/GET \/_health/, /GET \/_ready/, /GET \/_startup/, /OPTIONS \//],
});

Steps to Reproduce

  1. Capture traces with [email protected].
  2. Look at thehttp.serverspans
  3. Note the presence of two spans for the same endpoint within the same trace.
  4. Compare the two spans:
    • The first span lacks child middleware spans (no expandable '+' indicator).
    • The second span includes child middleware spans.
    • The second span contains additional custom tags absent in the first span.

Expected Result

  • Each unique operation (span) should be recorded only once per trace.
  • All relevant context and middleware information should be consistently captured within a single span.

Actual Result

Duplicate spans for the same HTTP operation

More information on internal customer case

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Waiting for: Community

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions