Skip to content

feat(otel): add NextJS OpenTelemetry docs #5855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Alert level="info" title="Note">

OpenTelemetry support is only supported for server-side instrumentation.

</Alert>

```bash {tabTitle:npm}
npm install @sentry/nextjs @sentry/opentelemetry-node
```

```bash {tabTitle:yarn}
yarn add @sentry/nextjs @sentry/opentelemetry-node
```

<Note>

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

</Note>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
You need to register `SentrySpanProcessor` and `SentryPropagator` with your OpenTelemetry installation in your `sentry.server.config.js` file:

```javascript {filename:sentry.server.config.js}
const Sentry = require("@sentry/nextjs");
const {
SentrySpanProcessor,
SentryPropagator,
} = require("@sentry/opentelemetry-node");

const opentelemetry = require("@opentelemetry/sdk-node");
const otelApi = require("@opentelemetry/api");
const {
getNodeAutoInstrumentations,
} = require("@opentelemetry/auto-instrumentations-node");
const {
OTLPTraceExporter,
} = require("@opentelemetry/exporter-trace-otlp-grpc");

// Make sure to call `Sentry.init` BEFORE initializing the OpenTelemetry SDK
Sentry.init({
dsn: "__DSN__",
tracesSampleRate: 1.0,
// set the instrumenter to use OpenTelemetry instead of Sentry
instrumenter: "otel",
// ...
});

const sdk = new opentelemetry.NodeSDK({
// Existing config
traceExporter: new OTLPTraceExporter(),
instrumentations: [getNodeAutoInstrumentations()],

// Sentry config
spanProcessor: new SentrySpanProcessor(),
});

otelApi.propagation.setGlobalPropagator(new SentryPropagator());

sdk.start();
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: OpenTelemetry Support
sidebar_order: 20
supported:
- node
- javascript.nextjs
notSupported:
- javascript
- python
Expand Down