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/lib/sentry/propagation_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def self.extract_sentry_trace(sentry_trace)
return if match.nil?

trace_id, parent_span_id, sampled_flag = match[1..3]
return if trace_id.nil?

parent_sampled = sampled_flag.nil? ? nil : sampled_flag != "0"

[trace_id, parent_span_id, parent_sampled]
Expand Down
16 changes: 16 additions & 0 deletions sentry-ruby/spec/sentry/propagation_context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@
expect(subject.baggage.mutable).to eq(false)
expect(subject.baggage.items).to eq({})
end

it "ignores incoming sentry-trace without a trace_id" do
subject = described_class.new(scope, { "sentry-trace" => "-1" })

expect(subject.trace_id.length).to eq(32)
expect(subject.parent_span_id).to be_nil
expect(subject.parent_sampled).to be_nil
expect(subject.baggage).to be_nil
expect(subject.incoming_trace).to eq(false)
end
end

describe "#get_trace_context" do
Expand Down Expand Up @@ -338,6 +348,12 @@ def make_env(sentry_trace:, baggage_org_id: nil)
expect(described_class.extract_sentry_trace("")).to be_nil
end

it "returns nil for sentry-trace without a trace_id" do
["-1", "1", "--1", "-0", "7c51afd529da4a2a-1"].each do |sentry_trace|
expect(described_class.extract_sentry_trace(sentry_trace)).to be_nil
end
end

it "allows whitespace" do
whitespace = " \t \t \t \t "
sentry_trace = "#{whitespace}771a43a4192642f0b136d5159a501700-7c51afd529da4a2a-1#{whitespace}"
Expand Down
Loading