Skip to content
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
23 changes: 22 additions & 1 deletion platform-includes/performance/improving-data/ruby.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ end

### Adding Data Attributes to Spans

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:
You can add data attributes to your spans the same way, with the same type restrictions as described above.

```ruby
Sentry.with_child_span(op: "my-span") do |span|
Expand All @@ -31,3 +31,24 @@ Sentry.with_child_span(op: "my-span") do |span|
span.set_data("my-data-attribute-6", [true, false, true])
end
```

### Adding Data Attributes to All Spans

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>:

```ruby
Sentry.init do |config|
# ...
config.traces_sample_rate = 1.0

config.before_send_transaction = lambda do |event, _hint|
# Set the data attribute "foo" to "bar" on every span belonging to this transaction event
event.spans.each { |span| span.set_data(:foo, "bar")

# Set the data on the transaction itself, too
event.contexts[:trace][:data][:foo] = "bar"

event
end
end
```
Loading