Skip to content

Commit ea28aea

Browse files
Lms24JoshuaMoelans
authored andcommitted
doc(js): Document how to set attribute on all spans (#12449)
1 parent 6dd54aa commit ea28aea

File tree

1 file changed

+28
-0
lines changed
  • docs/platforms/javascript/common/tracing/instrumentation/custom-instrumentation

1 file changed

+28
-0
lines changed

docs/platforms/javascript/common/tracing/instrumentation/custom-instrumentation/index.mdx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,34 @@ if (span) {
225225
}
226226
```
227227

228+
### Adding attributes to all spans
229+
230+
To add an attribute to all spans, use the `beforeSendTransaction` callback:
231+
232+
```javascript
233+
Sentry.init({
234+
// dsn, ...
235+
beforeSendTransaction(event) {
236+
237+
// set the attribute on the root span
238+
event.contexts.trace.data = {
239+
...event.contexts.trace.data,
240+
myAttribute: "myValue",
241+
}
242+
243+
// and on all child spans
244+
event.spans.forEach(span => {
245+
span.data = {
246+
...span.data,
247+
myAttribute: "myValue",
248+
}
249+
});
250+
}
251+
});
252+
```
253+
254+
255+
228256
### Adding Span Operations ("op")
229257

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

0 commit comments

Comments
 (0)