OpenTelemetry Support
You can configure your OpenTelemetry SDK to send traces and spans to Sentry.
Note
OpenTelemetry support is only available for server-side instrumentation on Node runtimes.
npm install @sentry/nextjs @sentry/opentelemetry-node
The minimum required version of the @sentry/node
and the @sentry/opentelemetry-node
package is 7.20.0
and their versions should always be aligned.
Note that @sentry/opentelemetry-node depends on the following peer dependencies:
- @opentelemetry/api, version 1.0.0 or greater
- @opentelemetry/sdk-trace-base, version 1.0.0 or greater, or a package that implements it, like @opentelemetry/sdk-node
Follow the Next.js instructions to set up a manual OpenTelemetry configuration.
Check to make sure you've added
instrumentation.{js,ts}
andinstrumentation.node.{js,ts}
files to your application. Note that, until this feature moves out of the experimental phase, Next.js requires you to setexperimental.instrumentationHook: true
in yournext.config.js
to enable these files.Enable your
sentry.server.config.js
file to be able to use the OpenTelemetry instrumenter option.
sentry.server.config.js
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
tracesSampleRate: 1.0,
// set the instrumenter to use OpenTelemetry instead of Sentry
instrumenter: "otel",
// ...
});
- Update your
instrumentation.node.{js,ts}
so that it uses Sentry's OpenTelemetrySpanProcessor
andSpanPropagator
.
instrumentation.node.js
import { trace, context } from "@opentelemetry/api";
import { NodeSDK } from "@opentelemetry/sdk-node";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
import { Resource } from "@opentelemetry/resources";
import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
import { SimpleSpanProcessor } from "@opentelemetry/sdk-trace-node";
import {
SentrySpanProcessor,
SentryPropagator,
} from "@sentry/opentelemetry-node";
const sdk = new NodeSDK({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: "next-app",
}),
// Sentry config
spanProcessor: new SentrySpanProcessor(),
textMapPropagator: new SentryPropagator(),
});
sdk.start();
With Sentry’s OpenTelemetry SDK, an OpenTelemetry Span
becomes a Sentry Transaction
or Span
. The first Span
sent through the Sentry SpanProcessor
is a Transaction
, and any child Span
gets attached to the first Transaction
upon checking the parent Span
context. This is true for the OpenTelemetry root Span
and any top level Span
in the system. For example, a request sent from frontend to backend will create an OpenTelemetry root Span
with a corresponding Sentry Transaction
. The backend request will create a new Sentry Transaction
for the OpenTelemetry Span
. The Sentry Transaction
and Span
are linked as a trace for navigation and error tracking purposes.
If you need more fine grained control over Sentry, take a look at the Configuration page. In case you'd like to filter out transactions before sending them to Sentry (to get rid of health checks, for example), you may find the Filtering page helpful.
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").