Skip to content

Commit 2945569

Browse files
committed
Support sending measurements via TransactionEvent
1 parent c19e09f commit 2945569

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

sentry-ruby/lib/sentry/client.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ def event_from_transaction(transaction)
112112
event.start_timestamp = transaction.start_timestamp
113113
event.tags = transaction.tags
114114

115+
if configuration.experiments.custom_measurements
116+
event.measurements = transaction.measurements
117+
end
118+
115119
finished_spans = transaction.span_recorder.spans.select { |span| span.timestamp && span != transaction }
116120
event.spans = finished_spans.map(&:to_hash)
117121
end

sentry-ruby/lib/sentry/transaction_event.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ class TransactionEvent < Event
88
# @return [<Array[Span]>]
99
attr_accessor :spans
1010

11+
# @return [Hash]
12+
attr_accessor :measurements
13+
1114
# @return [Float, nil]
1215
attr_reader :start_timestamp
1316

@@ -23,6 +26,7 @@ def to_hash
2326
data = super
2427
data[:spans] = @spans.map(&:to_hash) if @spans
2528
data[:start_timestamp] = @start_timestamp
29+
data[:measurements] = @measurements
2630
data
2731
end
2832
end

sentry-ruby/spec/sentry/transaction_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,5 +453,31 @@
453453
expect(subject.name).to eq("<unlabeled transaction>")
454454
end
455455
end
456+
457+
context "config.experiments.custom_measurements = true" do
458+
before do
459+
Sentry.configuration.experiments.custom_measurements = true
460+
end
461+
462+
it "adds measurements the event" do
463+
subject.set_measurement("metric.foo", 0.5, "second")
464+
subject.finish
465+
466+
transaction = events.last.to_hash
467+
expect(transaction[:measurements]).to eq(
468+
{ "metric.foo" => { value: 0.5, unit: "second" } }
469+
)
470+
end
471+
end
472+
473+
context "config.experiments.custom_measurements = false" do
474+
it "adds measurements the event" do
475+
subject.set_measurement("metric.foo", 0.5, "second")
476+
subject.finish
477+
478+
transaction = events.last.to_hash
479+
expect(transaction[:measurements]).to eq(nil)
480+
end
481+
end
456482
end
457483
end

0 commit comments

Comments
 (0)