Sentry
If your service already reports errors to Sentry, SpanSlice can send the traces it keeps to the same Sentry project. The two tools have separate jobs:
- SpanSlice traces the service. It owns OpenTelemetry, applies your rules, and exports the kept traces to Sentry over OTLP.
- Sentry reports errors. Each error names the span that was active when it happened, and the issue links to that trace.
Sentry’s Node SDK v8, v9, v10 and v11 all work this way. Only the Sentry.init options differ.
Add Sentry as an exporter
Section titled “Add Sentry as an exporter”- In the app, go to Organization settings › Exporters, choose Add exporter, and pick Sentry.
- Paste the DSN from your Sentry project’s Client Keys (DSN) settings. SpanSlice builds the OTLP endpoint and its auth header from it. DSNs from self-hosted Sentry work too, including those with a port or a base path.
- A new exporter is on for every project. To limit it to some services or environments, use Project settings › Exporters.
Only traces are sent, because Sentry’s OTLP ingest doesn’t accept metrics.
Initialize Sentry for errors only
Section titled “Initialize Sentry for errors only”Initialize Sentry first and SpanSlice second, in the same file that you load with --import. Leave tracesSampleRate
and tracesSampler unset. SpanSlice decides which traces are kept, and Sentry shouldn’t record spans of its own.
Sentry v11
Section titled “Sentry v11”import * as Sentry from '@sentry/node'import { spanSliceInit } from 'spanslice'import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'
Sentry.init({ dsn: process.env.SENTRY_DSN, integrations: [Sentry.openTelemetryIntegration()],})
const telemetry = spanSliceInit({ service: 'api', instrumentations: [new HttpInstrumentation()],})await telemetry.readyopenTelemetryIntegration() stamps each error with the active OpenTelemetry span. Without it, every error starts a trace
of its own.
Sentry v8, v9 and v10
Section titled “Sentry v8, v9 and v10”Sentry.init({ dsn: process.env.SENTRY_DSN, skipOpenTelemetrySetup: true, integrations: [Sentry.httpIntegration({ spans: false })],})Then call spanSliceInit as above. These versions link errors to the active span without openTelemetryIntegration().
Set both of these options:
skipOpenTelemetrySetup: truestops Sentry from registering its own OpenTelemetry tracer provider. OpenTelemetry keeps whichever provider is registered first. Without this option, Sentry’s provider gets every span, and SpanSlice sees none. The SDK logs a warning when this happens:another OpenTelemetry tracer provider was registered first.httpIntegration({ spans: false })stops Sentry from tracing HTTP requests itself. On v8, Sentry’s HTTP instrumentation otherwise replaces or duplicates yours.
What carries over
Section titled “What carries over”- Errors link to traces. An error captured inside a span carries that span’s trace and span ID. SpanSlice exports that trace.
- Downstream services stay on one trace. Outgoing requests carry
traceparent. Sentry v9 and later also sendsentry-traceandbaggage, on the same trace ID. - Sentry’s own requests aren’t traced. Uploading events to Sentry doesn’t add spans to your traces.
Sentry’s OTLP ingest is in beta. It drops span events. Span links and array attributes aren’t searchable.
Traces that start in the browser
Section titled “Traces that start in the browser”SpanSlice continues a trace from an incoming traceparent header. Sentry’s browser SDK sends sentry-trace and
baggage. From v10, it also sends traceparent when you set propagateTraceparent, to the hosts in
tracePropagationTargets. Your API’s CORS settings must allow the header:
Sentry.init({ dsn: '…', propagateTraceparent: true,})