|
| 1 | +To use an existing OpenTelemetry setup, set `skipOpenTelemetrySetup: true` in your `init({})` config, then set up all the components that Sentry needs yourself. Finish by installing `@sentry/opentelemetry` and adding the following: |
| 2 | + |
| 3 | +```javascript {tabTitle: NodeTracerProvider} |
| 4 | +const Sentry = require("@sentry/node"); |
| 5 | +const { SentrySpanProcessor, SentryPropagator, SentrySampler } = require("@sentry/opentelemetry"); |
| 6 | + |
| 7 | +const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node"); |
| 8 | + |
| 9 | +const sentryClient = Sentry.init({ |
| 10 | + dsn: "___DSN___", |
| 11 | + skipOpenTelemetrySetup: true, |
| 12 | + |
| 13 | + // The SentrySampler will use this to determine which traces to sample |
| 14 | + tracesSampleRate: 1.0, |
| 15 | +}); |
| 16 | + |
| 17 | +// Note: This could be BasicTracerProvider or any other provider depending on |
| 18 | +// how you are using the OpenTelemetry SDK |
| 19 | +const provider = new NodeTracerProvider({ |
| 20 | + // Ensure the correct subset of traces is sent to Sentry |
| 21 | + // This also ensures trace propagation works as expected |
| 22 | + sampler: sentryClient ? new SentrySampler(sentryClient) : undefined, |
| 23 | + spanProcessors: [ |
| 24 | + // Ensure spans are correctly linked & sent to Sentry |
| 25 | + new SentrySpanProcessor(), |
| 26 | + // Add additional processors here |
| 27 | + ], |
| 28 | +}); |
| 29 | + |
| 30 | +provider.register({ |
| 31 | + // Ensure trace propagation works |
| 32 | + // This relies on the SentrySampler for correct propagation |
| 33 | + propagator: new SentryPropagator(), |
| 34 | + // Ensure context & request isolation are correctly managed |
| 35 | + contextManager: new Sentry.SentryContextManager(), |
| 36 | +}); |
| 37 | + |
| 38 | +// Validate that the setup is correct |
| 39 | +Sentry.validateOpenTelemetrySetup(); |
| 40 | +``` |
| 41 | + |
| 42 | +```javascript {tabTitle: NodeSDK} |
| 43 | +const Sentry = require("@sentry/node"); |
| 44 | +const { SentrySpanProcessor, SentryPropagator, SentrySampler } = require("@sentry/opentelemetry"); |
| 45 | + |
| 46 | +const { NodeSDK } = require("@opentelemetry/sdk-node") |
| 47 | + |
| 48 | +const sentryClient = Sentry.init({ |
| 49 | + dsn: "___PUBLIC_DSN___", |
| 50 | + skipOpenTelemetrySetup: true, |
| 51 | + |
| 52 | + // The SentrySampler will use this to determine which traces to sample |
| 53 | + tracesSampleRate: 1.0, |
| 54 | +}); |
| 55 | + |
| 56 | +const sdk = new NodeSDK({ |
| 57 | + // Ensure the correct subset of traces is sent to Sentry |
| 58 | + // This also ensures trace propagation works as expected |
| 59 | + sampler: sentryClient ? new SentrySampler(sentryClient) : undefined, |
| 60 | + spanProcessors: [ |
| 61 | + // Ensure spans are correctly linked & sent to Sentry |
| 62 | + new SentrySpanProcessor(), |
| 63 | + // Add additional processors here |
| 64 | + ], |
| 65 | + // Ensure trace propagation works |
| 66 | + // This relies on the SentrySampler for correct propagation |
| 67 | + textMapPropagator: new SentryPropagator(), |
| 68 | + // Ensure context & request isolation are correctly managed |
| 69 | + contextManager: new Sentry.SentryContextManager() |
| 70 | +}); |
| 71 | + |
| 72 | +sdk.start(); |
| 73 | + |
| 74 | +// Validate that the setup is correct |
| 75 | +Sentry.validateOpenTelemetrySetup(); |
| 76 | +``` |
| 77 | + |
| 78 | +Make sure that all [Required OpenTelemetry Instrumentation](./#required-instrumentation) is set up correctly. Otherwise, the Sentry SDK may not work as expected. |
0 commit comments