Skip to content

Commit cb3c7b0

Browse files
authored
Ignore sentry-trace when tracing is not enabled (#1308)
* Ignore sentry-trace when tracing is not enabled * Update changelog
1 parent 7630b72 commit cb3c7b0

File tree

4 files changed

+60
-16
lines changed

4 files changed

+60
-16
lines changed

sentry-ruby/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## Unreleased
44

55
- Refactor interface construction [#1296](https://github.com/getsentry/sentry-ruby/pull/1296)
6+
- Ignore sentry-trace when tracing is not enabled [#1308](https://github.com/getsentry/sentry-ruby/pull/1308)
7+
- Fixes [#1307](https://github.com/getsentry/sentry-ruby/issues/1307)
68

79
## 4.2.2
810

sentry-ruby/lib/sentry/transaction.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def set_span_recorder
2626
end
2727

2828
def self.from_sentry_trace(sentry_trace, **options)
29+
return unless Sentry.configuration.tracing_enabled?
2930
return unless sentry_trace
3031

3132
match = SENTRY_TRACE_REGEXP.match(sentry_trace)

sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,38 @@
287287
Sentry.configuration.traces_sample_rate = nil
288288
end
289289

290+
let(:stack) do
291+
described_class.new(
292+
->(_) do
293+
[200, {}, ["ok"]]
294+
end
295+
)
296+
end
297+
290298
it "doesn't record transaction" do
291-
app = ->(_) do
292-
[200, {}, ["ok"]]
299+
stack.call(env)
300+
301+
expect(transport.events.count).to eq(0)
302+
end
303+
304+
context "when sentry-trace header is sent" do
305+
let(:external_transaction) do
306+
Sentry::Transaction.new(
307+
op: "pageload",
308+
status: "ok",
309+
sampled: true,
310+
name: "a/path"
311+
)
293312
end
294313

295-
stack = described_class.new(app)
314+
it "doesn't cause the transaction to be recorded" do
315+
env["HTTP_SENTRY_TRACE"] = external_transaction.to_sentry_trace
296316

297-
stack.call(env)
317+
response = stack.call(env)
298318

299-
expect(transport.events.count).to eq(0)
319+
expect(response[0]).to eq(200)
320+
expect(transport.events).to be_empty
321+
end
300322
end
301323
end
302324
end

sentry-ruby/spec/sentry/transaction_spec.rb

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,39 @@
1515
describe ".from_sentry_trace" do
1616
let(:sentry_trace) { subject.to_sentry_trace }
1717

18-
it "returns correctly-formatted value" do
19-
child_transaction = described_class.from_sentry_trace(sentry_trace, op: "child")
20-
21-
expect(child_transaction.trace_id).to eq(subject.trace_id)
22-
expect(child_transaction.parent_span_id).to eq(subject.span_id)
23-
expect(child_transaction.parent_sampled).to eq(true)
24-
expect(child_transaction.sampled).to eq(true)
25-
expect(child_transaction.op).to eq("child")
18+
before do
19+
configuration = Sentry::Configuration.new
20+
configuration.traces_sample_rate = 1.0
21+
allow(Sentry).to receive(:configuration).and_return(configuration)
2622
end
2723

28-
it "handles invalid values without crashing" do
29-
child_transaction = described_class.from_sentry_trace("dummy", op: "child")
24+
context "when tracing is enabled" do
25+
it "returns correctly-formatted value" do
26+
child_transaction = described_class.from_sentry_trace(sentry_trace, op: "child")
27+
28+
expect(child_transaction.trace_id).to eq(subject.trace_id)
29+
expect(child_transaction.parent_span_id).to eq(subject.span_id)
30+
expect(child_transaction.parent_sampled).to eq(true)
31+
expect(child_transaction.sampled).to eq(true)
32+
expect(child_transaction.op).to eq("child")
33+
end
34+
35+
it "handles invalid values without crashing" do
36+
child_transaction = described_class.from_sentry_trace("dummy", op: "child")
3037

31-
expect(child_transaction).to be_nil
38+
expect(child_transaction).to be_nil
39+
end
40+
end
41+
42+
context "when tracing is disabled" do
43+
before do
44+
configuration = Sentry::Configuration.new
45+
allow(Sentry).to receive(:configuration).and_return(configuration)
46+
end
47+
48+
it "returns nil" do
49+
expect(described_class.from_sentry_trace(sentry_trace, op: "child")).to be_nil
50+
end
3251
end
3352
end
3453

0 commit comments

Comments
 (0)