Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sentry-ruby/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Unreleased

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

## 4.2.2

Expand Down
1 change: 1 addition & 0 deletions sentry-ruby/lib/sentry/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def set_span_recorder
end

def self.from_sentry_trace(sentry_trace, **options)
return unless Sentry.configuration.tracing_enabled?
return unless sentry_trace

match = SENTRY_TRACE_REGEXP.match(sentry_trace)
Expand Down
32 changes: 27 additions & 5 deletions sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,38 @@
Sentry.configuration.traces_sample_rate = nil
end

let(:stack) do
described_class.new(
->(_) do
[200, {}, ["ok"]]
end
)
end

it "doesn't record transaction" do
app = ->(_) do
[200, {}, ["ok"]]
stack.call(env)

expect(transport.events.count).to eq(0)
end

context "when sentry-trace header is sent" do
let(:external_transaction) do
Sentry::Transaction.new(
op: "pageload",
status: "ok",
sampled: true,
name: "a/path"
)
end

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

stack.call(env)
response = stack.call(env)

expect(transport.events.count).to eq(0)
expect(response[0]).to eq(200)
expect(transport.events).to be_empty
end
end
end
end
Expand Down
41 changes: 30 additions & 11 deletions sentry-ruby/spec/sentry/transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,39 @@
describe ".from_sentry_trace" do
let(:sentry_trace) { subject.to_sentry_trace }

it "returns correctly-formatted value" do
child_transaction = described_class.from_sentry_trace(sentry_trace, op: "child")

expect(child_transaction.trace_id).to eq(subject.trace_id)
expect(child_transaction.parent_span_id).to eq(subject.span_id)
expect(child_transaction.parent_sampled).to eq(true)
expect(child_transaction.sampled).to eq(true)
expect(child_transaction.op).to eq("child")
before do
configuration = Sentry::Configuration.new
configuration.traces_sample_rate = 1.0
allow(Sentry).to receive(:configuration).and_return(configuration)
end

it "handles invalid values without crashing" do
child_transaction = described_class.from_sentry_trace("dummy", op: "child")
context "when tracing is enabled" do
it "returns correctly-formatted value" do
child_transaction = described_class.from_sentry_trace(sentry_trace, op: "child")

expect(child_transaction.trace_id).to eq(subject.trace_id)
expect(child_transaction.parent_span_id).to eq(subject.span_id)
expect(child_transaction.parent_sampled).to eq(true)
expect(child_transaction.sampled).to eq(true)
expect(child_transaction.op).to eq("child")
end

it "handles invalid values without crashing" do
child_transaction = described_class.from_sentry_trace("dummy", op: "child")

expect(child_transaction).to be_nil
expect(child_transaction).to be_nil
end
end

context "when tracing is disabled" do
before do
configuration = Sentry::Configuration.new
allow(Sentry).to receive(:configuration).and_return(configuration)
end

it "returns nil" do
expect(described_class.from_sentry_trace(sentry_trace, op: "child")).to be_nil
end
end
end

Expand Down