Skip to content

continueTrace with startInactiveSpan does not work correctly with Sentry v8 #13126

Closed
@mikan3rd

Description

@mikan3rd

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

8.20.0

Framework Version

No response

Link to Sentry event

https://bizforward.sentry.io/issues/5659614696/events/e33fe93c614b41779919285369087372/

Reproduction Example/SDK Setup

No response

Steps to Reproduce

In Sentry v7, continueTrace is used as follows, and checking the Sentry Issue confirms that the traceId used in the frontend is successfully passed on to the backend.

  const server = new ApolloServer({
    context: async ({ req }): Promise<Context> => {
      const sentryTraceHeaders = req.headers['sentry-trace'];
      const sentryTrace = Array.isArray(sentryTraceHeaders) ? sentryTraceHeaders.join(',') : sentryTraceHeaders;
      const baggage = req.headers['baggage'];
      const sentrySpan = Sentry.continueTrace({ sentryTrace, baggage }, (transactionContext) => {
        return Sentry.startInactiveSpan({
          ...transactionContext,
          op: 'gql',
          name: req.body.operationName,
        });
      });
      return { sentrySpan };
    },
  );

In Sentry v8, the transactionContext argument of the continueTrace callback has been removed, so I changed the code as follows.
However, when I did so, the traceId displayed in Sentry's Issue was different for frontend and backend.

  const server = new ApolloServer({
    context: async ({ req }): Promise<Context> => {
      const sentryTraceHeaders = req.headers['sentry-trace'];
      const sentryTrace = Array.isArray(sentryTraceHeaders) ? sentryTraceHeaders.join(',') : sentryTraceHeaders;
      const baggage = req.headers['baggage'];
      const sentrySpan = Sentry.continueTrace({ sentryTrace, baggage }, () => {
        return Sentry.startInactiveSpan({
          op: 'gql',
          name: req.body.operationName,
        });
      });
      return { sentrySpan };
    },
  );

I would like to know the cause and countermeasures.

Do I have to use startSpan, and if I use ApolloServer, how do I use startSpan?

Expected Result

The trace ID in the Issue must match the sentryTrace in the request header.

Actual Result

The trace ID listed in the Issue does not match the sentryTrace in the request header.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nodeIssues related to the Sentry Node SDK

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions