Skip to content

Unable to pass additional span processors to OTEL Node client #14826

@sunnybak

Description

@sunnybak

Goal: add additional span processors to Sentry Node and Sentry NextJS. This is currently blocking our production customers, so urgency would be appreciated!

TLDR:

  • To add additional span processors, the recommended approach is to use client.traceProvider.addSpanProcessors([...]) as documented here.
  • However, in this PR from a month back OTEL deprecated the addSpanProcessors API to add processors.
  • Therefore, there is currently no way to add additional span processors in the latest Sentry version of @sentry/node or @sentry/nextjs

Proposed Solution:

  • OTEL's recommendation is to add all the spanProcessors when the TraceProvider is initialized, which would be here
  • While initializing the Sentry client for Node or NextJS, the spanProcessors can be passed as a constructor option.
  • This option (of type NodeOption) can be read and added to the spanProcessors when initializing OTEL in Sentry

Proposed code change in initOtel.ts:

    spanProcessors: [
      new SentrySpanProcessor({
        timeout: _clampSpanProcessorTimeout(client.getOptions().maxSpanWaitDuration),
      }),
      ...client.getOptions().spanProcessors,
    ],

and the user would do something like this:

const client = Sentry.init({
  dsn: "https://9ee4c...31168",

  // Add optional integrations for additional features
  integrations: [
    Sentry.replayIntegration(),
  ],

  tracesSampleRate: 1,

  replaysSessionSampleRate: 0.1,

  replaysOnErrorSampleRate: 1.0,

  debug: false,

  // This is the recommend approach after the deprecation of client.traceProviders.addSpanProcessors([...]) 
  // PR https://github.com/open-telemetry/opentelemetry-js/issues/4792
 // However, this is not picked up in https://github.com/getsentry/sentry-javascript/blob/develop/packages/node/src/sdk/initOtel.ts#L143-L147

  spanProcessors: [
    new BatchSpanProcessor(new OTLPTraceExporter(
      {
        url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
      },
    )),
  ],
} as Sentry.NodeOptions) as Sentry.NodeClient;

Please let us know if you need anything.

Metadata

Metadata

Assignees

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions