Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sunnybak opened this issue Dec 22, 2024 · 3 comments
Open

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

sunnybak opened this issue Dec 22, 2024 · 3 comments
Labels
Package: node Issues related to the Sentry Node SDK Package-Meta: OpenTelemetry

Comments

@sunnybak
Copy link

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.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 22, 2024
@Lms24
Copy link
Member

Lms24 commented Dec 23, 2024

Hi @sunnybak thanks for writing in! This is indeed a noteworthy change in the next Otel SDK major version and we'll probably need to adapt our strategy how to enable adding processors.

This is currently blocking our production customers

Is this actually hard-blocking you? The new Otel SDK version isn't released yet, so right now, adding a span processor via addSpanProcessors() is only deprecated but should still work. I understand this is not ideal but I'm just trying to assess priority here :)

Otherwise, your proposed API makes sense to me. I'll also tag @mydea - thoughts?

Btw, for the next time, please use our issue templates. They're there for a reason. Thanks!

@Lms24
Copy link
Member

Lms24 commented Dec 23, 2024

Another thought: Have you tried using a custom Otel Setup where you add Sentry components instead of using the Sentry setup and adding additional Otel components? Maybe this can also unblock you.

@mydea
Copy link
Member

mydea commented Dec 23, 2024

Imho we can add a config similar to what we did for additional otel instrumentation to also pass in more span processors to sentry init! But agree, for now using the deprecated methods should be fine, we will work on a suitable replacement in early January then :)

@Lms24 Lms24 added Package: node Issues related to the Sentry Node SDK Package-Meta: OpenTelemetry labels Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: node Issues related to the Sentry Node SDK Package-Meta: OpenTelemetry
Projects
Status: No status
Development

No branches or pull requests

3 participants