Skip to content

doc(js): Document how to set attributes on transaction and all child spans #12449

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

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,34 @@ if (span) {
}
```

### Adding attributes to all spans

To add an attribute to all spans, use the `beforeSendTransaction` callback:

```javascript
Sentry.init({
// dsn, ...
beforeSendTransaction(event) {

// set the attribute on the root span
event.contexts.trace.data = {
...event.contexts.trace.data,
myAttribute: "myValue",
}

// and on all child spans
event.spans.forEach(span => {
span.data = {
...span.data,
myAttribute: "myValue",
}
});
}
});
```



### Adding Span Operations ("op")

Spans can have an operation associated with them, which help activate Sentry identify additional context about the span. For example database related spans have the `db` span operation associated with them. The Sentry product offers additional controls, visualizations and filters for spans with known operations.
Expand Down
Loading