Skip to content

Commit

Permalink
fix: Support Case Insensitive Trace and Span IDs (#781)
Browse files Browse the repository at this point in the history
This change allows systems that generate uppercase hex values to properly propagate OTTrace context.
  • Loading branch information
arielvalentin authored May 31, 2021
1 parent 0b58055 commit 8f3c150
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ module OTTrace
# Propagates context using OTTrace header format
class TextMapPropagator
PADDING = '0' * 16
VALID_TRACE_ID_REGEX = /^[0-9a-f]{32}$/.freeze
VALID_SPAN_ID_REGEX = /^[0-9a-f]{16}$/.freeze
VALID_TRACE_ID_REGEX = /^[0-9a-f]{32}$/i.freeze
VALID_SPAN_ID_REGEX = /^[0-9a-f]{16}$/i.freeze
TRACE_ID_64_BIT_WIDTH = 64 / 4
TRACE_ID_HEADER = 'ot-tracer-traceid'
SPAN_ID_HEADER = 'ot-tracer-spanid'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,26 @@ def set(carrier, key, value)
end
end

describe 'given a minimal context with uppercase fields' do
let(:carrier) do
{
'ot-tracer-traceid' => trace_id_header.upcase,
'ot-tracer-spanid' => span_id_header.upcase,
'ot-tracer-sampled' => sampled_header
}
end

it 'extracts parent context' do
context = propagator.extract(carrier, context: parent_context)
extracted_context = OpenTelemetry::Trace.current_span(context).context

_(extracted_context.hex_trace_id).must_equal('80f198ee56343ba864fe8b2a57d3eff7')
_(extracted_context.hex_span_id).must_equal('e457b5a2e4d86bd1')
_(extracted_context.trace_flags).must_equal(OpenTelemetry::Trace::TraceFlags::SAMPLED)
_(extracted_context).must_be(:remote?)
end
end

describe 'given a context with sampling disabled' do
let(:sampled_header) do
'false'
Expand Down

0 comments on commit 8f3c150

Please sign in to comment.