Skip to content

Commit e850eca

Browse files
committed
Remove Transaction deprecations
1 parent 9afd9d1 commit e850eca

File tree

3 files changed

+14
-219
lines changed

3 files changed

+14
-219
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
- Remove deprecated `config.enable_tracing`, use `config.traces_sample_rate = 1.0` instead ([#2731](https://github.com/getsentry/sentry-ruby/pull/2731))
99
- Remove deprecated `config.logger=`, use `config.sdk_logger=` instead ([#2732](https://github.com/getsentry/sentry-ruby/pull/2732))
1010
- Remove deprecated `Sentry::Rails::Tracing::ActionControllerSubscriber` ([#2733](https://github.com/getsentry/sentry-ruby/pull/2733))
11+
- Remove `Transaction` deprecations ([#2736](https://github.com/getsentry/sentry-ruby/pull/2736))
12+
- Remove deprecated constant `Sentry::Transaction::SENTRY_TRACE_REGEXP`, use `Sentry::PropagationContext::SENTRY_TRACE_REGEXP` instead
13+
- Remove deprecated method `Sentry::Transaction.from_sentry_trace`, use `Sentry.continue_trace` instead
14+
- Remove deprecated method `Sentry::Transaction.extract_sentry_trace`, use `Sentry::PropagationContext.extract_sentry_trace` instead
15+
- Remove deprecated attribute `Sentry::Transaction.configuration`
16+
- Remove deprecated attribute `Sentry::Transaction.hub`
17+
- Remove deprecated argument `hub` to `Sentry::Transaction.finish`
1118
- Remove `:monotonic_active_support_logger` from `config.breadcrumbs_logger` ([#2717](https://github.com/getsentry/sentry-ruby/pull/2717))
1219
- Migrate from to_hash to to_h ([#2351](https://github.com/getsentry/sentry-ruby/pull/2351))
1320
- Add `before_send_check_in` for applying to `CheckInEvent` ([#2703](https://github.com/getsentry/sentry-ruby/pull/2703))

sentry-ruby/lib/sentry/transaction.rb

Lines changed: 7 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
module Sentry
99
class Transaction < Span
10-
# @deprecated Use Sentry::PropagationContext::SENTRY_TRACE_REGEXP instead.
11-
SENTRY_TRACE_REGEXP = PropagationContext::SENTRY_TRACE_REGEXP
12-
1310
UNLABELD_NAME = "<unlabeled transaction>"
1411
MESSAGE_PREFIX = "[Tracing]"
1512

@@ -40,12 +37,6 @@ class Transaction < Span
4037
# @return [Hash]
4138
attr_reader :measurements
4239

43-
# @deprecated Use Sentry.get_current_hub instead.
44-
attr_reader :hub
45-
46-
# @deprecated Use Sentry.configuration instead.
47-
attr_reader :configuration
48-
4940
# The effective sample rate at which this transaction was sampled.
5041
# @return [Float, nil]
5142
attr_reader :effective_sample_rate
@@ -77,7 +68,6 @@ def initialize(
7768
@parent_sampled = parent_sampled
7869
@hub = hub
7970
@baggage = baggage
80-
@configuration = hub.configuration # to be removed
8171
@tracing_enabled = hub.configuration.tracing_enabled?
8272
@traces_sampler = hub.configuration.traces_sampler
8373
@traces_sample_rate = hub.configuration.traces_sample_rate
@@ -91,8 +81,8 @@ def initialize(
9181
@measurements = {}
9282
@sample_rand = sample_rand
9383

94-
unless @hub.profiler_running?
95-
@profiler = @configuration.profiler_class.new(@configuration)
84+
unless hub.profiler_running?
85+
@profiler = hub.configuration.profiler_class.new(hub.configuration)
9686
end
9787

9888
init_span_recorder
@@ -103,63 +93,6 @@ def initialize(
10393
end
10494
end
10595

106-
# @deprecated use Sentry.continue_trace instead.
107-
#
108-
# Initalizes a Transaction instance with a Sentry trace string from another transaction (usually from an external request).
109-
#
110-
# The original transaction will become the parent of the new Transaction instance. And they will share the same `trace_id`.
111-
#
112-
# The child transaction will also store the parent's sampling decision in its `parent_sampled` attribute.
113-
# @param sentry_trace [String] the trace string from the previous transaction.
114-
# @param baggage [String, nil] the incoming baggage header string.
115-
# @param hub [Hub] the hub that'll be responsible for sending this transaction when it's finished.
116-
# @param options [Hash] the options you want to use to initialize a Transaction instance.
117-
# @return [Transaction, nil]
118-
def self.from_sentry_trace(sentry_trace, baggage: nil, hub: Sentry.get_current_hub, **options)
119-
return unless hub.configuration.tracing_enabled?
120-
return unless sentry_trace
121-
122-
sentry_trace_data = extract_sentry_trace(sentry_trace)
123-
return unless sentry_trace_data
124-
125-
trace_id, parent_span_id, parent_sampled = sentry_trace_data
126-
127-
baggage =
128-
if baggage && !baggage.empty?
129-
Baggage.from_incoming_header(baggage)
130-
else
131-
# If there's an incoming sentry-trace but no incoming baggage header,
132-
# for instance in traces coming from older SDKs,
133-
# baggage will be empty and frozen and won't be populated as head SDK.
134-
Baggage.new({})
135-
end
136-
137-
baggage.freeze!
138-
139-
sample_rand = extract_sample_rand_from_baggage(baggage, trace_id, parent_sampled)
140-
141-
new(
142-
trace_id: trace_id,
143-
parent_span_id: parent_span_id,
144-
parent_sampled: parent_sampled,
145-
hub: hub,
146-
baggage: baggage,
147-
sample_rand: sample_rand,
148-
**options
149-
)
150-
end
151-
152-
# @deprecated Use Sentry::PropagationContext.extract_sentry_trace instead.
153-
# @return [Array, nil]
154-
def self.extract_sentry_trace(sentry_trace)
155-
PropagationContext.extract_sentry_trace(sentry_trace)
156-
end
157-
158-
def self.extract_sample_rand_from_baggage(baggage, trace_id, parent_sampled)
159-
PropagationContext.extract_sample_rand_from_baggage(baggage, trace_id) ||
160-
PropagationContext.generate_sample_rand(baggage, trace_id, parent_sampled)
161-
end
162-
16396
# @return [Hash]
16497
def to_h
16598
hash = super
@@ -266,20 +199,8 @@ def set_initial_sample_decision(sampling_context:)
266199
end
267200

268201
# Finishes the transaction's recording and send it to Sentry.
269-
# @param hub [Hub] the hub that'll send this transaction. (Deprecated)
270202
# @return [TransactionEvent]
271-
def finish(hub: nil, end_timestamp: nil)
272-
if hub
273-
log_warn(
274-
<<~MSG
275-
Specifying a different hub in `Transaction#finish` will be deprecated in version 5.0.
276-
Please use `Hub#start_transaction` with the designated hub.
277-
MSG
278-
)
279-
end
280-
281-
hub ||= @hub
282-
203+
def finish(end_timestamp: nil)
283204
super(end_timestamp: end_timestamp)
284205

285206
if @name.nil?
@@ -297,13 +218,13 @@ def finish(hub: nil, end_timestamp: nil)
297218
@hub.current_client.transport.record_lost_event(:event_processor, "transaction")
298219
@hub.current_client.transport.record_lost_event(:event_processor, "span")
299220
elsif @sampled
300-
event = hub.current_client.event_from_transaction(self)
301-
hub.capture_event(event)
221+
event = @hub.current_client.event_from_transaction(self)
222+
@hub.capture_event(event)
302223
else
303224
is_backpressure = Sentry.backpressure_monitor&.downsample_factor&.positive?
304225
reason = is_backpressure ? :backpressure : :sample_rate
305-
hub.current_client.transport.record_lost_event(reason, "transaction")
306-
hub.current_client.transport.record_lost_event(reason, "span")
226+
@hub.current_client.transport.record_lost_event(reason, "transaction")
227+
@hub.current_client.transport.record_lost_event(reason, "span")
307228
end
308229
end
309230

sentry-ruby/spec/sentry/transaction_spec.rb

Lines changed: 0 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -21,93 +21,6 @@
2121
let(:string_io) { StringIO.new }
2222
let(:sdk_logger) { Logger.new(string_io) }
2323

24-
describe ".from_sentry_trace" do
25-
let(:sentry_trace) { subject.to_sentry_trace }
26-
27-
let(:baggage) {
28-
"other-vendor-value-1=foo;bar;baz, "\
29-
"sentry-trace_id=771a43a4192642f0b136d5159a501700, "\
30-
"sentry-public_key=49d0f7386ad645858ae85020e393bef3, "\
31-
"sentry-sample_rate=0.01337, "\
32-
"sentry-user_id=Am%C3%A9lie, "\
33-
"other-vendor-value-2=foo;bar;"
34-
}
35-
36-
let(:configuration) do
37-
Sentry.configuration
38-
end
39-
40-
context "when tracing is enabled (> 0)" do
41-
before do
42-
configuration.traces_sample_rate = 1.0
43-
end
44-
45-
it "returns correctly-formatted value" do
46-
child_transaction = described_class.from_sentry_trace(sentry_trace, op: "child")
47-
48-
expect(child_transaction.trace_id).to eq(subject.trace_id)
49-
expect(child_transaction.parent_span_id).to eq(subject.span_id)
50-
expect(child_transaction.parent_sampled).to eq(true)
51-
# doesn't set the sampled value
52-
expect(child_transaction.sampled).to eq(nil)
53-
expect(child_transaction.op).to eq("child")
54-
end
55-
56-
it "handles invalid values without crashing" do
57-
child_transaction = described_class.from_sentry_trace("dummy", op: "child")
58-
59-
expect(child_transaction).to be_nil
60-
end
61-
62-
it "stores frozen empty baggage on incoming traces from older SDKs" do
63-
child_transaction = described_class.from_sentry_trace(sentry_trace, baggage: nil, op: "child")
64-
expect(child_transaction.baggage).not_to be_nil
65-
expect(child_transaction.baggage.mutable).to be(false)
66-
expect(child_transaction.baggage.items).to eq({})
67-
end
68-
69-
it "stores correct baggage on incoming baggage header" do
70-
child_transaction = described_class.from_sentry_trace(sentry_trace, baggage: baggage, op: "child")
71-
expect(child_transaction.baggage).not_to be_nil
72-
expect(child_transaction.baggage.mutable).to be(false)
73-
74-
expect(child_transaction.baggage.items).to eq({
75-
"sample_rate" => "0.01337",
76-
"public_key" => "49d0f7386ad645858ae85020e393bef3",
77-
"trace_id" => "771a43a4192642f0b136d5159a501700",
78-
"user_id" => "Amélie"
79-
})
80-
end
81-
end
82-
83-
context "when tracing is enabled (= 0)" do
84-
before do
85-
configuration.traces_sample_rate = 0.0
86-
end
87-
88-
it "returns correctly-formatted value" do
89-
child_transaction = described_class.from_sentry_trace(sentry_trace, op: "child")
90-
91-
expect(child_transaction.trace_id).to eq(subject.trace_id)
92-
expect(child_transaction.parent_span_id).to eq(subject.span_id)
93-
expect(child_transaction.parent_sampled).to eq(true)
94-
# doesn't set the sampled value
95-
expect(child_transaction.sampled).to eq(nil)
96-
expect(child_transaction.op).to eq("child")
97-
end
98-
end
99-
100-
context "when tracing is disabled" do
101-
before do
102-
configuration.traces_sample_rate = nil
103-
end
104-
105-
it "returns nil" do
106-
expect(described_class.from_sentry_trace(sentry_trace, op: "child")).to be_nil
107-
end
108-
end
109-
end
110-
11124
describe "#deep_dup" do
11225
before do
11326
subject.start_child(op: "first child")
@@ -467,12 +380,6 @@
467380
end
468381

469382
describe "hub selection" do
470-
it "prioritizes the optional hub argument and uses it to submit the transaction" do
471-
expect(another_hub).to receive(:capture_event)
472-
473-
subject.finish(hub: another_hub)
474-
end
475-
476383
it "submits the event with the transaction's hub by default" do
477384
# Create transaction with the specific hub from the beginning
478385
transaction = described_class.new(
@@ -703,46 +610,6 @@
703610
end
704611
end
705612

706-
describe ".extract_sample_rand_from_baggage" do
707-
let(:trace_id) { "771a43a4192642f0b136d5159a501700" }
708-
709-
it "returns trace_id generation when baggage is nil" do
710-
result = described_class.extract_sample_rand_from_baggage(nil, trace_id, true)
711-
712-
generator = Sentry::Utils::SampleRand.new(trace_id: trace_id)
713-
expected = generator.generate_from_trace_id
714-
715-
expect(result).to eq(expected)
716-
end
717-
718-
it "returns trace_id generation when baggage has no items" do
719-
baggage = double("baggage", items: nil)
720-
result = described_class.extract_sample_rand_from_baggage(baggage, trace_id, true)
721-
722-
generator = Sentry::Utils::SampleRand.new(trace_id: trace_id)
723-
expected = generator.generate_from_trace_id
724-
725-
expect(result).to eq(expected)
726-
end
727-
728-
it "returns trace_id generation when sample_rand is invalid" do
729-
baggage = double("baggage", items: { "sample_rand" => "1.5" })
730-
result = described_class.extract_sample_rand_from_baggage(baggage, trace_id, true)
731-
732-
generator = Sentry::Utils::SampleRand.new(trace_id: trace_id)
733-
expected = generator.generate_from_trace_id
734-
735-
expect(result).to eq(expected)
736-
end
737-
738-
it "returns valid sample_rand from baggage when present" do
739-
baggage = double("baggage", items: { "sample_rand" => "0.5" })
740-
result = described_class.extract_sample_rand_from_baggage(baggage, trace_id, true)
741-
742-
expect(result).to eq(0.5)
743-
end
744-
end
745-
746613
describe "#set_name" do
747614
it "sets name and source directly" do
748615
subject.set_name("bar", source: :url)

0 commit comments

Comments
 (0)