Skip to content
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
46 changes: 1 addition & 45 deletions docs/platforms/javascript/common/opentelemetry/custom-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,51 +34,7 @@ If you are looking to simply add individual OpenTelemetry instrumentation to you

</Alert>

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:

```javascript
const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
const Sentry = require("@sentry/node");
const {
SentrySpanProcessor,
SentryPropagator,
SentrySampler,
} = require("@sentry/opentelemetry");

const sentryClient = Sentry.init({
dsn: "___DSN___",
skipOpenTelemetrySetup: true,

// The SentrySampler will use this to determine which traces to sample
tracesSampleRate: 1.0,
});

// Note: This could be BasicTracerProvider or any other provider depending on
// how you are using the OpenTelemetry SDK
const provider = new NodeTracerProvider({
// Ensure the correct subset of traces is sent to Sentry
// This also ensures trace propagation works as expected
sampler: sentryClient ? new SentrySampler(sentryClient) : undefined,
spanProcessors: [
// Ensure spans are correctly linked & sent to Sentry
new SentrySpanProcessor(),
// Add additional processors here
],
});

provider.register({
// Ensure trace propagation works
// This relies on the SentrySampler for correct propagation
propagator: new SentryPropagator(),
// Ensure context & request isolation are correctly managed
contextManager: new Sentry.SentryContextManager(),
});

// Validate that the setup is correct
Sentry.validateOpenTelemetrySetup();
```

Make sure that all [Required OpenTelemetry Instrumentation](./#required-instrumentation) is set up correctly. Otherwise, the Sentry SDK may not work as expected.
<PlatformContent includePath="performance/opentelemetry-setup" />

## Using Sentry for Error Monitoring Only

Expand Down
78 changes: 78 additions & 0 deletions platform-includes/performance/opentelemetry-setup/javascript.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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:

```javascript {tabTitle: NodeTracerProvider}
const Sentry = require("@sentry/node");
const { SentrySpanProcessor, SentryPropagator, SentrySampler } = require("@sentry/opentelemetry");

const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");

const sentryClient = Sentry.init({
dsn: "___DSN___",
skipOpenTelemetrySetup: true,

// The SentrySampler will use this to determine which traces to sample
tracesSampleRate: 1.0,
});

// Note: This could be BasicTracerProvider or any other provider depending on
// how you are using the OpenTelemetry SDK
const provider = new NodeTracerProvider({
// Ensure the correct subset of traces is sent to Sentry
// This also ensures trace propagation works as expected
sampler: sentryClient ? new SentrySampler(sentryClient) : undefined,
spanProcessors: [
// Ensure spans are correctly linked & sent to Sentry
new SentrySpanProcessor(),
// Add additional processors here
],
});

provider.register({
// Ensure trace propagation works
// This relies on the SentrySampler for correct propagation
propagator: new SentryPropagator(),
// Ensure context & request isolation are correctly managed
contextManager: new Sentry.SentryContextManager(),
});

// Validate that the setup is correct
Sentry.validateOpenTelemetrySetup();
```

```javascript {tabTitle: NodeSDK}
const Sentry = require("@sentry/node");
const { SentrySpanProcessor, SentryPropagator, SentrySampler } = require("@sentry/opentelemetry");

const { NodeSDK } = require("@opentelemetry/sdk-node")

const sentryClient = Sentry.init({
dsn: "___PUBLIC_DSN___",
skipOpenTelemetrySetup: true,

// The SentrySampler will use this to determine which traces to sample
tracesSampleRate: 1.0,
});

const sdk = new NodeSDK({
// Ensure the correct subset of traces is sent to Sentry
// This also ensures trace propagation works as expected
sampler: sentryClient ? new SentrySampler(sentryClient) : undefined,
spanProcessors: [
// Ensure spans are correctly linked & sent to Sentry
new SentrySpanProcessor(),
// Add additional processors here
],
// Ensure trace propagation works
// This relies on the SentrySampler for correct propagation
textMapPropagator: new SentryPropagator(),
// Ensure context & request isolation are correctly managed
contextManager: new Sentry.SentryContextManager()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: NodeSDK Configuration Errors

The NodeSDK configuration contains two errors:

  1. It uses spanProcessors (plural) instead of the expected spanProcessor (singular), which prevents Sentry from correctly processing spans.
  2. A comma is missing after the contextManager property, causing a syntax error.
Fix in Cursor Fix in Web

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spanProcessor is a deprecated option - spanProcessors should be used instead.

});

sdk.start();

// Validate that the setup is correct
Sentry.validateOpenTelemetrySetup();
```

Make sure that all [Required OpenTelemetry Instrumentation](./#required-instrumentation) is set up correctly. Otherwise, the Sentry SDK may not work as expected.

This file was deleted.