Skip to content

Commit 1462e5d

Browse files
committed
feat(node): Improve docs for errors-only OTEL setup
1 parent b65e408 commit 1462e5d

File tree

1 file changed

+49
-3
lines changed

1 file changed

+49
-3
lines changed

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

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,52 @@ In order for the Sentry SDK to work as expected, and for it to be in sync with O
102102
</PlatformLink>
103103
</Note>
104104

105+
The following code snippet shows how to set up Sentry for error monitoring only:
106+
107+
```javascript
108+
const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
109+
const Sentry = require("@sentry/node");
110+
const { SentryPropagator, SentrySampler } = require("@sentry/opentelemetry");
111+
const { registerInstrumentations } = require("@opentelemetry/instrumentation");
112+
113+
const sentryClient = Sentry.init({
114+
dsn: "___DSN___",
115+
skipOpenTelemetrySetup: true,
116+
117+
// Important: We do not define a tracesSampleRate here at all!
118+
// This leads to tracing being disabled
119+
120+
// Disable emitting of spans in the httpIntegration
121+
integrations: [Sentry.httpIntegration({ spans: false })],
122+
});
123+
124+
// Create and configure e.g. NodeTracerProvider
125+
const provider = new NodeTracerProvider({
126+
// This ensures trace propagation works as expected
127+
sampler: sentryClient ? new SentrySampler(sentryClient) : undefined,
128+
});
129+
130+
provider.addSpanProcessor(
131+
new BatchSpanProcessor(
132+
new OTLPTraceExporter({
133+
url: "http://OTLP-ENDPOINT.com/api",
134+
})
135+
)
136+
);
137+
138+
// Initialize the provider
139+
provider.register({
140+
propagator: new SentryPropagator(),
141+
contextManager: new Sentry.SentryContextManager(),
142+
});
143+
144+
registerInstrumentations({
145+
instrumentations: [
146+
// Add OTEL instrumentation here
147+
],
148+
});
149+
```
150+
105151
## Required Instrumentation
106152

107153
By default, Sentry will register OpenTelemetry instrumentation to automatically capture spans for traces spanning incoming and outgoing HTTP requests, DB queries, and more.
@@ -110,8 +156,8 @@ If tracing is not enabled (no `tracesSampleRate` is defined in the SDK configura
110156

111157
{/* prettier-ignore-start */}
112158

113-
- <PlatformLink to="/configuration/integrations/http/">httpIntegration</PlatformLink> registers [@opentelemetry/instrumentation-http](https://www.npmjs.com/package/@opentelemetry/instrumentation-http)
114-
- <PlatformLink to="/configuration/integrations/nodefetch/">nativeNodeFetchIntegration</PlatformLink> registers [opentelemetry-instrumentation-fetch-node](https://www.npmjs.com/package/opentelemetry-instrumentation-fetch-node)
159+
- A Sentry-specific HTTP instrumentation that handles request isolation and trace propagation. This can work in parallel with [@opentelemetry/instrumentation-http](https://www.npmjs.com/package/@opentelemetry/instrumentation-http), if you register it.
160+
- <PlatformLink to="/configuration/integrations/nodefetch/">nativeNodeFetchIntegration</PlatformLink> registers [opentelemetry-instrumentation-fetch-node](https://www.npmjs.com/package/opentelemetry-instrumentation-fetch-node) which is needed for trace propagation.
115161

116162
{/* prettier-ignore-end */}
117163

@@ -125,7 +171,6 @@ If tracing is not enabled (no `tracesSampleRate` is defined in the SDK configura
125171
<PlatformLink to="/configuration/tree-shaking/#setting-up-sentry-without-performance-integrations">
126172
Set up Sentry without Performance Integrations
127173
</PlatformLink>
128-
.
129174
</Note>
130175
</PlatformSection>
131176

@@ -215,6 +260,7 @@ You can do so by setting `registerEsmLoaderHooks` to `false` and [setting up ESM
215260

216261
```javascript
217262
Sentry.init({
263+
dsn: "___DSN___",
218264
skipOpenTelemetrySetup: true,
219265
registerEsmLoaderHooks: false,
220266
});

0 commit comments

Comments
 (0)