Skip to content

How to set tag on a transaction? #11029

Answered by lforst
jeengbe asked this question in Q&A
Mar 11, 2024 · 4 comments · 7 replies
Discussion options

You must be logged in to vote

If you really want to exclusively set a tag on a transaction you can do the following:

const activeSpan = Sentry.getActiveSpan();
if (activeSpan) {
  Sentry.getRootSpan(activeSpan).setAttribute('foo', 'bar');
}

More easily though, if you're ok with the tag also being set on other events on the same request, you can just do Sentry.setTag('foo', 'bar'). Note that this will require an active isolation scope, which is normally something we create automatically for you with an integration, but in the case of Koa you likely need to do this yourself, but it is pretty straight forward. Just wrap any execution context in Sentry.withIsolationScope(() => { ... }). The right place for this is usually…

Replies: 4 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@jeengbe
Comment options

@jeengbe
Comment options

@jeengbe
Comment options

@lforst
Comment options

Answer selected by jeengbe
Comment options

You must be logged in to vote
1 reply
@lforst
Comment options

Comment options

You must be logged in to vote
2 replies
@lforst
Comment options

@jeengbe
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
Type: Bug Package: node Issues related to the Sentry Node SDK Waiting for: Product Owner
2 participants
Converted from issue

This discussion was converted from issue #11028 on March 11, 2024 16:41.