Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions docs/platforms/javascript/common/opentelemetry/custom-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,40 @@ Initialize your OpenTelemetry provider before calling `Sentry.init()`.

Add an OTLP exporter to your existing provider. Install `@opentelemetry/exporter-trace-otlp-http` if you do not already use it. `Sentry.getOtlpTracesEndpoint()` supplies the endpoint URL and authentication headers for your DSN.

This example uses `NodeTracerProvider`. Add the same span processor to `spanProcessors` if you use `NodeSDK` instead. Keep your existing sampler, propagator, context manager, and instrumentation; do not register a second provider.
Pick the tab that matches your OpenTelemetry JS version. Keep your existing sampler, propagator, context manager, and instrumentation; do not register a second provider.

```javascript {filename: instrument.mjs}
```javascript {tabTitle:OpenTelemetry JS v3} {filename: instrument.mjs}
import * as Sentry from "___SDK_PACKAGE___";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
import { NodeSDK } from "@opentelemetry/sdk-node";
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace";

const dsn = "___PUBLIC_DSN___";
const endpoint = Sentry.getOtlpTracesEndpoint(dsn);

if (!endpoint) {
throw new Error("Could not parse the Sentry DSN");
}

const sdk = new NodeSDK({
spanProcessors: [
new BatchSpanProcessor({ exporter: new OTLPTraceExporter(endpoint) }),
// Keep any other span processors you already use.
],
// Keep your existing instrumentations, sampler, and propagator.
});

sdk.start();

Sentry.init({
dsn,
enableOpenTelemetrySetup: false,
// Leave tracesSampleRate and tracesSampler unset. OpenTelemetry owns tracing.
integrations: [Sentry.openTelemetryIntegration()],
});
```

```javascript {tabTitle:OpenTelemetry JS v2} {filename: instrument.mjs}
import * as Sentry from "___SDK_PACKAGE___";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
Expand Down Expand Up @@ -50,7 +81,7 @@ Sentry.init({

## Use Sentry for Error Monitoring Only

If your traces go elsewhere, keep your existing OpenTelemetry exporter and omit the Sentry OTLP exporter from the example above. The `Sentry.init()` configuration stays the same. `openTelemetryIntegration()` links Sentry errors to the active OpenTelemetry trace without sending spans to Sentry.
If your traces go elsewhere, keep your existing OpenTelemetry exporter and omit the Sentry OTLP exporter from the examples above. The `Sentry.init()` configuration stays the same. `openTelemetryIntegration()` links Sentry errors to the active OpenTelemetry trace without sending spans to Sentry.

## Configure Sampling

Expand Down
Loading