diff --git a/sentry-ruby/lib/sentry/client.rb b/sentry-ruby/lib/sentry/client.rb index 933e857cb..7c3236855 100644 --- a/sentry-ruby/lib/sentry/client.rb +++ b/sentry-ruby/lib/sentry/client.rb @@ -112,6 +112,10 @@ def event_from_transaction(transaction) event.start_timestamp = transaction.start_timestamp event.tags = transaction.tags + if configuration.experiments.custom_measurements + event.measurements = transaction.measurements + end + finished_spans = transaction.span_recorder.spans.select { |span| span.timestamp && span != transaction } event.spans = finished_spans.map(&:to_hash) end diff --git a/sentry-ruby/lib/sentry/transaction_event.rb b/sentry-ruby/lib/sentry/transaction_event.rb index 9d017217a..8bba1b04f 100644 --- a/sentry-ruby/lib/sentry/transaction_event.rb +++ b/sentry-ruby/lib/sentry/transaction_event.rb @@ -8,6 +8,9 @@ class TransactionEvent < Event # @return [] attr_accessor :spans + # @return [Hash] + attr_accessor :measurements + # @return [Float, nil] attr_reader :start_timestamp @@ -23,6 +26,7 @@ def to_hash data = super data[:spans] = @spans.map(&:to_hash) if @spans data[:start_timestamp] = @start_timestamp + data[:measurements] = @measurements data end end diff --git a/sentry-ruby/spec/sentry/transaction_spec.rb b/sentry-ruby/spec/sentry/transaction_spec.rb index 95186f74f..252c22f13 100644 --- a/sentry-ruby/spec/sentry/transaction_spec.rb +++ b/sentry-ruby/spec/sentry/transaction_spec.rb @@ -453,5 +453,31 @@ expect(subject.name).to eq("") end end + + context "config.experiments.custom_measurements = true" do + before do + Sentry.configuration.experiments.custom_measurements = true + end + + it "adds measurements the event" do + subject.set_measurement("metric.foo", 0.5, "second") + subject.finish + + transaction = events.last.to_hash + expect(transaction[:measurements]).to eq( + { "metric.foo" => { value: 0.5, unit: "second" } } + ) + end + end + + context "config.experiments.custom_measurements = false" do + it "adds measurements the event" do + subject.set_measurement("metric.foo", 0.5, "second") + subject.finish + + transaction = events.last.to_hash + expect(transaction[:measurements]).to eq(nil) + end + end end end