Skip to content

Commit

Permalink
Support sending measurements via TransactionEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Jul 2, 2022
1 parent 2ea78ce commit dbd53f2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sentry-ruby/lib/sentry/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions sentry-ruby/lib/sentry/transaction_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class TransactionEvent < Event
# @return [<Array[Span]>]
attr_accessor :spans

# @return [Hash]
attr_accessor :measurements

# @return [Float, nil]
attr_reader :start_timestamp

Expand All @@ -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
Expand Down
26 changes: 26 additions & 0 deletions sentry-ruby/spec/sentry/transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -453,5 +453,31 @@
expect(subject.name).to eq("<unlabeled transaction>")
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

0 comments on commit dbd53f2

Please sign in to comment.