Giter Site home page Giter Site logo

Comments (10)

adam187 avatar adam187 commented on August 27, 2024

Looks like it could be related to #11625

from sentry-javascript.

lforst avatar lforst commented on August 27, 2024

Hi, I am trying to better understand your desired outcome. What do traces look for you, and what would you like them to look like?

from sentry-javascript.

adam187 avatar adam187 commented on August 27, 2024

Hi, I am trying to better understand your desired outcome. What do traces look for you, and what would you like them to look like?

Sorry for late reply.

The desired outcome would be to have all spans from single request assigned to same trace id.
Now Sentry creates own context so all spans created by sentry and within sentry context are not assigned to original trace.

For us it's problematic since we can't see full trace by original trace id.

from sentry-javascript.

chargome avatar chargome commented on August 27, 2024

Hi @adam187, I talked with @lforst and there are a few things to unpack:

from sentry-javascript.

adam187 avatar adam187 commented on August 27, 2024

Hey @chargome, sorry for late replay.

The main issue here is not missing spans, I could live with that since I filter some of them myself. The main issue here is that it looks like that sentry create it's own isolated context and ignores tracing from the origin.

So if I make a request with some traceparent header (for example from load balancer)
curl 'http://localhost:3000' -H 'traceparent: 00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01'

Then trace id from origin (0af7651916cd43dd8448eb211c80319c) is used for next spans but not for the sentry spans.

span.spanContext().traceId 0af7651916cd43dd8448eb211c80319c 65073143ff8e8137 next.js
span.spanContext().traceId 0af7651916cd43dd8448eb211c80319c fd2126cfa6b28748 next.js
span.spanContext().traceId 343e1e0631bfb3841a90e43e1852ce66 f0ee3f56c7b50523 @sentry/node
span.spanContext().traceId 343e1e0631bfb3841a90e43e1852ce66 1e93ba38b4669365 @sentry/node
span.spanContext().traceId 0af7651916cd43dd8448eb211c80319c 7d54d9af00b36793 next.js

I wanted to check if it's working the same as in example from docs but for some reason I But I'm getting error:

  ▲ Next.js 14.2.5
  - Local:        http://localhost:3000
  - Experiments (use with caution):
    · instrumentationHook

 ✓ Starting...
 ○ Compiling /instrumentation ...
 ⨯ node:child_process
Module build failed: UnhandledSchemeError: Reading from "node:child_process" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
Import trace for requested module:
node:child_process
./node_modules/@sentry/node/build/esm/integrations/context.js
./node_modules/@sentry/node/build/esm/index.js
 ✓ Ready in 2s

https://github.com/adam187/nextjs-sentry-otel-example/tree/sentry-example-otel

When I tried to use @sentry/nextjs insted of @sentry/node I got it compiled with some errors but still I don't see trace id to be propagated properly from request header.
https://github.com/adam187/nextjs-sentry-otel-example/tree/sentry-example-otel-2

Even if I explicitly add W3C propagators like

  const propagator = new CompositePropagator({
    propagators: [
      new SentryPropagator(),
      new W3CTraceContextPropagator(),
      new W3CBaggagePropagator(),
    ],
  });

I see the same effect, traceparent is reflected on next.js spans but sentry use own context and trace id.
https://github.com/adam187/nextjs-sentry-otel-example/tree/sentry-example-otel-3

For now I reverted back to v7

from sentry-javascript.

lforst avatar lforst commented on August 27, 2024

Hi, the Sentry SDK doesn't speak the traceparent header, which is why the SDK might send disconnected traces from the rest of your OTEL setup. As a bare minimum, the SDK uses a proprietary sentry-trace header with an optional but strongly recommended baggage header. This is mostly due to historical (implementation pre-dating the wider adoption of OTEL within the ecosystem), but also technical reasons (more involved serverside sampling rules). If you have other components in your system that you want to have traced with Sentry, you need to install the Sentry SDK there too. Does this make sense?

from sentry-javascript.

adam187 avatar adam187 commented on August 27, 2024

I don't want to use Sentry to trace our whole system. We already using OTEL and W3C Tracing across our system. We're only using Sentry for error reporting from frontend part of the stack.

from sentry-javascript.

lforst avatar lforst commented on August 27, 2024

That's fair. You don't have to. But then you need to set up trace propagation yourself. We have documented the primitives here: https://docs.sentry.io/platforms/javascript/tracing/trace-propagation/custom-instrumentation/

from sentry-javascript.

adam187 avatar adam187 commented on August 27, 2024

That's fair. You don't have to. But then you need to set up trace propagation yourself. We have documented the primitives here: https://docs.sentry.io/platforms/javascript/tracing/trace-propagation/custom-instrumentation/

Still it doesn't look like my case, this look like propagating trace from server side to client side and I have issue with pure SSR requests and it's not the issue with propagating traces to other services with outgoing request but the fact that Sentry creates separate trace scope that is isolated from initial tracing 🤔

from sentry-javascript.

mydea avatar mydea commented on August 27, 2024

If you do not care about connecting errors to traces, you should be able to skip using the SentryPropagator.

We have new and improved docs on using Sentry with a custom otel setup here: https://docs.sentry.io/platforms/javascript/guides/nextjs/opentelemetry/custom-setup/

This explains what you need to set up and why. Your setup cannot work because you did not set up the SentryContextManager - without this, the Sentry SDK will not work as expected, because Sentry scope & OTEL context will not be linked correctly.

You need to use SentrySampler (or use wrapSamplingDecision in your own sampler) and SentryProagator if you want to be able to connect errors in your frontend to your backend.

from sentry-javascript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.