Skip to content

Commit b8e429a

Browse files
authored
feat(ruby): Add snippet for adding data to transaction and all its spans (#12559)
1 parent c6fcf5f commit b8e429a

File tree

1 file changed

+22
-1
lines changed
  • platform-includes/performance/improving-data

1 file changed

+22
-1
lines changed

platform-includes/performance/improving-data/ruby.mdx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ end
1818

1919
### Adding Data Attributes to Spans
2020

21-
You can add data attributes to your spans. This data is visible in the trace explorer in Sentry. Data attributes can be strings, numbers or booleans, as well as (non-mixed) arrays of these types:
21+
You can add data attributes to your spans the same way, with the same type restrictions as described above.
2222

2323
```ruby
2424
Sentry.with_child_span(op: "my-span") do |span|
@@ -31,3 +31,24 @@ Sentry.with_child_span(op: "my-span") do |span|
3131
span.set_data("my-data-attribute-6", [true, false, true])
3232
end
3333
```
34+
35+
### Adding Data Attributes to All Spans
36+
37+
To attach data attributes to the transaction and all its spans, you can use <PlatformLink to="/configuration/filtering/#using-before-send-transaction">`before_send_transaction`</PlatformLink>:
38+
39+
```ruby
40+
Sentry.init do |config|
41+
# ...
42+
config.traces_sample_rate = 1.0
43+
44+
config.before_send_transaction = lambda do |event, _hint|
45+
# Set the data attribute "foo" to "bar" on every span belonging to this transaction event
46+
event.spans.each { |span| span.set_data(:foo, "bar")
47+
48+
# Set the data on the transaction itself, too
49+
event.contexts[:trace][:data][:foo] = "bar"
50+
51+
event
52+
end
53+
end
54+
```

0 commit comments

Comments
 (0)