Skip to content

Commit 70ba6d0

Browse files
authored
docs(node): Add snippet for OTel setup with NodeSDK (#14582)
## DESCRIBE YOUR PR Adds docs for the setup with `NodeSDK` of OpenTelemetry. There was already a "platform include" for the setup which I reused for this purpose. It was not used anywhere. ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [ ] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs)
1 parent 2462336 commit 70ba6d0

File tree

3 files changed

+79
-142
lines changed

3 files changed

+79
-142
lines changed

docs/platforms/javascript/common/opentelemetry/custom-setup.mdx

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -34,51 +34,7 @@ If you are looking to simply add individual OpenTelemetry instrumentation to you
3434

3535
</Alert>
3636

37-
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:
38-
39-
```javascript
40-
const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
41-
const Sentry = require("@sentry/node");
42-
const {
43-
SentrySpanProcessor,
44-
SentryPropagator,
45-
SentrySampler,
46-
} = require("@sentry/opentelemetry");
47-
48-
const sentryClient = Sentry.init({
49-
dsn: "___DSN___",
50-
skipOpenTelemetrySetup: true,
51-
52-
// The SentrySampler will use this to determine which traces to sample
53-
tracesSampleRate: 1.0,
54-
});
55-
56-
// Note: This could be BasicTracerProvider or any other provider depending on
57-
// how you are using the OpenTelemetry SDK
58-
const provider = new NodeTracerProvider({
59-
// Ensure the correct subset of traces is sent to Sentry
60-
// This also ensures trace propagation works as expected
61-
sampler: sentryClient ? new SentrySampler(sentryClient) : undefined,
62-
spanProcessors: [
63-
// Ensure spans are correctly linked & sent to Sentry
64-
new SentrySpanProcessor(),
65-
// Add additional processors here
66-
],
67-
});
68-
69-
provider.register({
70-
// Ensure trace propagation works
71-
// This relies on the SentrySampler for correct propagation
72-
propagator: new SentryPropagator(),
73-
// Ensure context & request isolation are correctly managed
74-
contextManager: new Sentry.SentryContextManager(),
75-
});
76-
77-
// Validate that the setup is correct
78-
Sentry.validateOpenTelemetrySetup();
79-
```
80-
81-
Make sure that all [Required OpenTelemetry Instrumentation](./#required-instrumentation) is set up correctly. Otherwise, the Sentry SDK may not work as expected.
37+
<PlatformContent includePath="performance/opentelemetry-setup" />
8238

8339
## Using Sentry for Error Monitoring Only
8440

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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.

platform-includes/performance/opentelemetry-setup/javascript.node.mdx

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)