Skip to content

JandaTheMan/Sentry-OpenTelemetry-Issue-Reproduction

Repository files navigation

Sentry + OpenTelemetry Issue Reproduction

Issue: Sentry SDK interferes with OpenTelemetry fetch spans in Node.js even with skipOpenTelemetrySetup: true

Problem Description

When initializing Sentry SDK alongside OpenTelemetry instrumentation, Nextjs fetch spans stop being generated, despite:

  • Setting skipOpenTelemetrySetup: true in Sentry configuration
  • Properly configuring OpenTelemetry auto-instrumentations
  • Loading OpenTelemetry before Sentry initialization

Environment

  • Node.js: v22.17.1
  • Next.js: 15.5.2
  • @sentry/nextjs: ^10.11.0
  • @opentelemetry/auto-instrumentations-node: ^0.63.0
  • OS: macOS Darwin 24.6.0

Reproduction Steps

Prerequisites

  1. Clone this repository

  2. Install dependencies:

    npm install
  3. Start the local observability stack (OpenTelemetry Collector + Tempo + Grafana):

    npm run observability:up

    This will start:

    Note: First login to Grafana requires username: admin and password: admin

Test Case 1: Without Sentry (✅ Expected behavior)

  1. Ensure SENTRY_DSN is not set in .env
  2. Start the server:
    npm run dev
  3. Open http://localhost:3000
  4. Check traces in Grafana at http://localhost:3003/explore (tempo as source). Pre-configured url for traces search.
  5. Result: OpenTelemetry spans are generated and visible grafana. Fetch spans are present.

Test Case 2: With Sentry (❌ Broken behavior)

  1. Set SENTRY_DSN in .env file:
    SENTRY_DSN=your-sentry-dsn-here
    
  2. Restart the server:
    npm run dev
  3. Click "Make Fetch Request" button
  4. Check traces in Grafana at http://localhost:3003/explore (tempo as source). Pre-configured url for traces search.
  5. Result: OpenTelemetry spans are generated and visible grafana. Fetch spans are not present.

Configuration Details

OpenTelemetry Setup (instrumentation.node.ts)

  • Uses @opentelemetry/auto-instrumentations-node with HTTP instrumentation enabled
  • Properly configured before Sentry initialization

Sentry Configuration (sentry.server.config.ts)

Sentry.init({
  dsn: process.env.SENTRY_DSN,
  skipOpenTelemetrySetup: true, // Should prevent interference
  integrations: [Sentry.httpIntegration({spans: false})],
});

Load Order

  1. OpenTelemetry SDK initializes first (instrumentation.node.ts)
  2. Sentry initializes conditionally based on SENTRY_DSN environment variable

Expected Behavior

OpenTelemetry Nextjs fetch instrumentation should continue generating spans when Sentry is enabled with skipOpenTelemetrySetup: true.

Actual Behavior

Fetch spans disappear completely when Sentry SDK is initialized, regardless of the skipOpenTelemetrySetup setting.

Package Dependencies

{
  "@opentelemetry/api": "^1.9.0",
  "@opentelemetry/auto-instrumentations-node": "^0.63.0",
  "@opentelemetry/context-async-hooks": "^2.1.0",
  "@opentelemetry/exporter-trace-otlp-grpc": "^0.204.0",
  "@opentelemetry/sdk-node": "^0.204.0",
  "@sentry/nextjs": "^10.11.0",
  "next": "15.5.2"
}

Observability Stack

Cleanup

To stop the observability stack:

npm run observability:down

Trace Visualization

After running tests, view traces in Grafana:


This minimal reproduction case demonstrates the conflict between Sentry and OpenTelemetry instrumentation that prevents proper observability setup.

About

Project to reproduce open telemetry nextjs fetch spans disappearance when sentry is enabled

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors