sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

Improve distributed tracing custom instrumentation

Open AbhiPrasad opened this issue 1 year ago • 1 comments

Right now to implement distributed tracing with the JS SDK, it is a bit confusing. The docs jump back and forth between different concepts: https://docs.sentry.io/platforms/javascript/distributed-tracing/custom-instrumentation/

and attaching headers requires both @sentry/core and @sentry/utils to be installed.

import * as Sentry from '@sentry/node';
import { spanToTraceHeader, getDynamicSamplingContextFromSpan } from '@sentry/core';
import { dynamicSamplingContextToSentryBaggageHeader } from '@sentry/utils';
app.get('/v1/metrics', (req, res, next) => helpers.authenticated(req, res, next), async (req, res) => {
  await Sentry.startSpan(
    {
      name: 'enqueue metrics job',
      op: 'queue.submit',
      attributes: {
      },
    },
    async (span) => {
      const traceHeader = spanToTraceHeader(span);
      const dynamicSamplingContext = getDynamicSamplingContextFromSpan(span);
      const baggageHeader = dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext);
      console.info(traceHeader, baggageHeader);
    },
  );
  res.send('ok');
});

We need to restructure the docs, and make sure all relevant methods are accessible via @sentry/browser and @sentry/node.

AbhiPrasad avatar Apr 24 '24 15:04 AbhiPrasad

Related https://github.com/getsentry/sentry-javascript/issues/11199

AbhiPrasad avatar Apr 24 '24 18:04 AbhiPrasad