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

Sentry span not keep traceId #14803

Open
3 tasks done
xiaoxiangmoe opened this issue Dec 19, 2024 · 6 comments
Open
3 tasks done

Sentry span not keep traceId #14803

xiaoxiangmoe opened this issue Dec 19, 2024 · 6 comments
Labels
Package: node Issues related to the Sentry Node SDK

Comments

@xiaoxiangmoe
Copy link

xiaoxiangmoe commented Dec 19, 2024

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.43.0

Framework Version

nodejs

Link to Sentry event

No response

Reproduction Example/SDK Setup

No response

Steps to Reproduce

import * as _crypto from 'node:crypto';
import * as Sentry from '@sentry/node';

// Simulates the traceId obtained from the outside world
function getRandomSentryTraceData() {
    const sentryTrace = _crypto.randomBytes(16).toString('hex') + '-' + _crypto.randomBytes(8).toString('hex');
    console.log('traceId', sentryTrace);
    return { sentryTrace, baggage: 'environment=dev' };
}

const main = () =>
    Sentry.continueTrace(getRandomSentryTraceData(), async () => {
      await Sentry.startSpan({ name: 'hello span' }, (span) => {
          console.log('span traceId', span.spanContext().traceId);
      })
  })

main()

Expected Result

Log same traceId

same as v8.42.0

Actual Result

different traceId

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 19, 2024
@github-actions github-actions bot added the Package: node Issues related to the Sentry Node SDK label Dec 19, 2024
@xiaoxiangmoe xiaoxiangmoe changed the title Sentry span not Sentry span not keep traceId Dec 19, 2024
@Lms24
Copy link
Member

Lms24 commented Dec 20, 2024

Hi @xiaoxiangmoe thanks for writing in! This is probably related to what we initially discovered in #14787. We're working on a fix

EDIT: It is probably not related after all

@Lms24
Copy link
Member

Lms24 commented Dec 20, 2024

@xiaoxiangmoe just to confirm: Are you calling Sentry.init()? Please post your init code and how you initialize the SDK (e.g. via --import instrument.mjs).

@andreiborza
Copy link
Member

@xiaoxiangmoe I set this up as a repo here: https://github.com/andreiborza/14803-continue-trace

Are there any differences to what you have? Could you try running this and see if it runs as expected?

I'm getting

$ node --import ./instrument.mjs index.js
trace data traceId = 2dbc91a35572b1dea31563396f615511
span       traceId = 2dbc91a35572b1dea31563396f615511

@xiaoxiangmoe
Copy link
Author

xiaoxiangmoe commented Dec 20, 2024

@andreiborza change

https://github.com/andreiborza/14803-continue-trace/blob/c9b0bbf05be0feb0dbdbbbe0647dfe77dd7afb74/index.js#L2

from

import * as Sentry from '@sentry/node';

to

import * as Sentry from '@sentry/core';

will make this error happen


Okay, I found why it it not work.

In my real world app, it exists both

import * as Sentry from '@sentry/node';

Sentry.startSpan()

and

// for sharing code to both node and browser, we import @sentry/core here
import * as Sentry from '@sentry/core';

Sentry.startSpan()

And @sentry/node and @sentry/core have different Sentry.startSpan implementation since 8.43.0

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 20, 2024
@xiaoxiangmoe
Copy link
Author

#14819 may fix this

@andreiborza
Copy link
Member

@xiaoxiangmoe yep, that's likely it. Thanks for raising this tho.

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
Projects
Status: No status
Development

No branches or pull requests

3 participants