Skip to content

Commit 8f3c150

Browse files
fix: Support Case Insensitive Trace and Span IDs (#781)
This change allows systems that generate uppercase hex values to properly propagate OTTrace context.
1 parent 0b58055 commit 8f3c150

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

propagator/ottrace/lib/opentelemetry/propagator/ottrace/text_map_propagator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ module OTTrace
1818
# Propagates context using OTTrace header format
1919
class TextMapPropagator
2020
PADDING = '0' * 16
21-
VALID_TRACE_ID_REGEX = /^[0-9a-f]{32}$/.freeze
22-
VALID_SPAN_ID_REGEX = /^[0-9a-f]{16}$/.freeze
21+
VALID_TRACE_ID_REGEX = /^[0-9a-f]{32}$/i.freeze
22+
VALID_SPAN_ID_REGEX = /^[0-9a-f]{16}$/i.freeze
2323
TRACE_ID_64_BIT_WIDTH = 64 / 4
2424
TRACE_ID_HEADER = 'ot-tracer-traceid'
2525
SPAN_ID_HEADER = 'ot-tracer-spanid'

propagator/ottrace/test/opentelemetry/propagator/ottrace/text_map_propagator_test.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,26 @@ def set(carrier, key, value)
117117
end
118118
end
119119

120+
describe 'given a minimal context with uppercase fields' do
121+
let(:carrier) do
122+
{
123+
'ot-tracer-traceid' => trace_id_header.upcase,
124+
'ot-tracer-spanid' => span_id_header.upcase,
125+
'ot-tracer-sampled' => sampled_header
126+
}
127+
end
128+
129+
it 'extracts parent context' do
130+
context = propagator.extract(carrier, context: parent_context)
131+
extracted_context = OpenTelemetry::Trace.current_span(context).context
132+
133+
_(extracted_context.hex_trace_id).must_equal('80f198ee56343ba864fe8b2a57d3eff7')
134+
_(extracted_context.hex_span_id).must_equal('e457b5a2e4d86bd1')
135+
_(extracted_context.trace_flags).must_equal(OpenTelemetry::Trace::TraceFlags::SAMPLED)
136+
_(extracted_context).must_be(:remote?)
137+
end
138+
end
139+
120140
describe 'given a context with sampling disabled' do
121141
let(:sampled_header) do
122142
'false'

0 commit comments

Comments
 (0)