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.getCurrentScope().setTransactionName(name) not having any effect #14663

Closed
drmrbrewer opened this issue Nov 25, 2024 · 15 comments
Closed

Comments

@drmrbrewer
Copy link

Self-Hosted Version

24.9.0

CPU Architecture

arm64

Docker Version

27.3.1, build ce12230

Docker Compose Version

2.29.7

Steps to Reproduce

I have an node.js express route that has two main branches within it, and the chosen branch to go down is based on what is passed into the incoming request. The two branches are quite different and would benefit from being regarded within Sentry as two different transactions.

I have tried calling the following soon after the code branches, to override the transaction name:

Sentry.getCurrentScope().setTransactionName('branchA');

and

Sentry.getCurrentScope().setTransactionName('branchB');

But... I'm not seeing these two transaction names anywhere in my data... in Performance for example I'm just seeing the GET /myRoute transaction but not separate branchA and branchB transactions.

What am I doing wrong? So far as I can tell I'm just doing what the docs are telling me to do.

Expected Result

See above.

Actual Result

See above.

Event ID

No response

@aldy505
Copy link

aldy505 commented Nov 27, 2024

Are you able to reproduce this using the SDK targeted to Sentry SaaS? If on SaaS they don't output the correct result, this issue should be transferred to the JS SDK repository.

@drmrbrewer
Copy link
Author

@aldy505 if by Sentry SaaS you just mean the hosted version of Sentry rather than self-hosted, then yes... it appears to be the same regardless of whether my transaction data is sent to my hosted dsn or my self-hosted dsn... I don't see my custom transaction names in either place.

@aldy505
Copy link

aldy505 commented Dec 9, 2024

@bc-sentry @hubertdeng123 Can you guys help transfer this issue over to sentry-javascript? Thanks.

@Lms24 Lms24 transferred this issue from getsentry/self-hosted Dec 11, 2024
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 11, 2024
@Lms24
Copy link
Member

Lms24 commented Dec 11, 2024

Hey @drmrbrewer I transferred this issue to the JS SDK repo.

Unfortunately, this docs page is very misleading and outdated since v8 of the SDK. To keep it short, scope.setTransactionName() has no influence on spans (i.e. what the Sentry performance product is showing). I opened a docs PR today to finally update this page: getsentry/sentry-docs#12091

You can visit this preview link of the updated page for more information. Feel free to leave feedback on the PR as well if you encounter things that are unclear.

EDIT: I (somewhat accidentally) closed this issue. However, I'll keep it closed for now because the docs PR is already up and should get merged soon. Furthermore, the question should be answered.

@drmrbrewer
Copy link
Author

Hi @Lms24 thanks, that new page makes it all much clearer. It looks like the most relevant method to me, for my most common usecase which is to set the name dynamically while the request is being processed, will be Sentry.updateSpanName():

Image

This is only available from v8.44.0 and latest is v8.43.0 so I guess I need to wait... or is there any way of trying v8.44.0 now?

@Lms24
Copy link
Member

Lms24 commented Dec 12, 2024

Hey @drmrbrewer this is not yet merged unfortunately, so the version in the Available Since paragraph is only a placeholder.

You can follow the progress of the PR here: #14291

@drmrbrewer
Copy link
Author

@Lms24 looks like this PR is making good progress. When do you think it might end up in a new release? I'm keen to try it out!
Thanks!

@Lms24
Copy link
Member

Lms24 commented Dec 18, 2024

We're probably gonna release today. Your comment gave me some extra motivation to do that :)

You can follow the SDK release here: #14777. After the PR is merged it'll be a matter of hours before the SDK packages are released.

Once 8.47.0 is released, we can merge the docs PRs that depend on it.

@drmrbrewer
Copy link
Author

@Lms24 great, thanks! Appreciate it.

@drmrbrewer
Copy link
Author

@Lms24 thanks for pushing this through... seems to work a treat!

@Lms24
Copy link
Member

Lms24 commented Dec 19, 2024

Glad to hear it! Docs should all be up to date as well now :)

@drmrbrewer
Copy link
Author

drmrbrewer commented Dec 20, 2024

@Lms24 I am using the suggested way of setting the root span name while the span is active:

const activeSpan = Sentry.getActiveSpan();
const rootSpan = activeSpan && Sentry.getRootSpan(activeSpan);
Sentry.updateSpanName(rootSpan, "UserListView");

But I'm also sometimes seeing:

TypeError: Cannot read properties of undefined (reading 'updateName')
  at Module.updateSpanName (file:///usr/src/app/node_modules/@sentry/core/build/esm/utils/spanUtils.js:305:8)
  at MonitorHelper.setTransactionName (file:///usr/src/app/nodeserver.js:10517:20)
  ...

I haven't yet figured out when/why this happens (*), but I had assumed that the suggested method was 'safe' in the sense that it wouldn't throw an exception if maybe rootSpan was somehow undefined?

(*) maybe it's when the rootSpan has completed by the time that the Sentry helper function gets around to calling updateName() on it?

@Lms24
Copy link
Member

Lms24 commented Dec 20, 2024

@drmrbrewer which SDK are you using? This generally shouldn't happen. Any chance you could find out which span you passed into updateSpanName? This might help us find out what's going on.

@drmrbrewer
Copy link
Author

@Lms24 I'm using the node.js SDK. By which span, do you mean the span name I'm trying to set?

@Lms24
Copy link
Member

Lms24 commented Dec 23, 2024

Hmm this is a bit weird because according to our type definitions getRootSpan must always return a Span and must not return undefined. The span ending itself in the meantime shouldn't cause the reference you're holding to it to suddenly become undefined. Even less because your code is sync, so there shouldn't be an interruption.

I'm afraid to debug this properly, we'd need a reproducible example. If you can (and since you said you're still trying to get to the bottom of this, whenever you're ready), it'd be great if you could provide a small sample project (GH repo, Zip, stackblitz whatever). Otherwise, please provide your Sentry setup code, specific SDK version and a small code snippet example how to reproduce the bug. Since I'm ooo for the next days and closed issues don't get tracked, please open a new issue with the information.

Sorry for the trouble and thanks for sticking with me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Archived in project
Development

No branches or pull requests

3 participants