diff --git a/.gitignore b/.gitignore index fb515e06c..3d0b1379f 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,6 @@ instrumentation/**/*.gemfile.lock # Vendored gems **/vendor/**/* + +# IDE Settings +/.idea/ diff --git a/propagator/xray/lib/opentelemetry/propagator/xray/text_map_propagator.rb b/propagator/xray/lib/opentelemetry/propagator/xray/text_map_propagator.rb index c6339691a..624f795d4 100644 --- a/propagator/xray/lib/opentelemetry/propagator/xray/text_map_propagator.rb +++ b/propagator/xray/lib/opentelemetry/propagator/xray/text_map_propagator.rb @@ -76,7 +76,7 @@ def inject(carrier, context: Context.current, setter: Context::Propagation.text_ end ot_trace_id = span_context.hex_trace_id - xray_trace_id = "1-#{ot_trace_id[0..6]}-#{ot_trace_id[7..ot_trace_id.length]}" + xray_trace_id = "1-#{ot_trace_id[0..7]}-#{ot_trace_id[8..ot_trace_id.length]}" parent_id = span_context.hex_span_id xray_value = "Root=#{xray_trace_id};Parent=#{parent_id};Sampled=#{sampling_state}" @@ -98,7 +98,7 @@ def parse_header(header) # Convert an id from a hex encoded string to byte array. Assumes the input id has already been # validated to be 35 characters in length. def to_trace_id(hex_id) - Array(hex_id[2..8] + hex_id[10..hex_id.length]).pack('H*') + Array(hex_id[2..9] + hex_id[11..hex_id.length]).pack('H*') end # Convert an id from a hex encoded string to byte array. diff --git a/propagator/xray/test/text_map_propagator_test.rb b/propagator/xray/test/text_map_propagator_test.rb index c99c2e784..5ab2d1fd4 100644 --- a/propagator/xray/test/text_map_propagator_test.rb +++ b/propagator/xray/test/text_map_propagator_test.rb @@ -16,12 +16,12 @@ describe('#extract') do it 'extracts context with trace id, span id, sampling flag, trace state' do parent_context = OpenTelemetry::Context.empty - carrier = { 'X-Amzn-Trace-Id' => 'Root=1-80f198e-e56343ba864fe8b2a57d3eff7;Parent=e457b5a2e4d86bd1;Sampled=1;Foo=Bar;Fizz=Buzz' } + carrier = { 'X-Amzn-Trace-Id' => 'Root=1-80f198ea-e56343ba864fe8b2a57d3eff;Parent=e457b5a2e4d86bd1;Sampled=1;Foo=Bar;Fizz=Buzz' } 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_trace_id).must_equal('80f198eae56343ba864fe8b2a57d3eff') _(extracted_context.hex_span_id).must_equal('e457b5a2e4d86bd1') _(extracted_context.trace_flags).must_equal(OpenTelemetry::Trace::TraceFlags::SAMPLED) _(extracted_context.tracestate.to_s).must_equal(OpenTelemetry::Trace::Tracestate.from_string('Foo=Bar,Fizz=Buzz').to_s) @@ -30,12 +30,12 @@ it 'extracts context with trace id, span id, sampling flag' do parent_context = OpenTelemetry::Context.empty - carrier = { 'X-Amzn-Trace-Id' => 'Root=1-80f198e-e56343ba864fe8b2a57d3eff7;Parent=e457b5a2e4d86bd1;Sampled=1' } + carrier = { 'X-Amzn-Trace-Id' => 'Root=1-80f198ea-e56343ba864fe8b2a57d3eff;Parent=e457b5a2e4d86bd1;Sampled=1' } 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_trace_id).must_equal('80f198eae56343ba864fe8b2a57d3eff') _(extracted_context.hex_span_id).must_equal('e457b5a2e4d86bd1') _(extracted_context.trace_flags).must_equal(OpenTelemetry::Trace::TraceFlags::SAMPLED) _(extracted_context).must_be(:remote?) @@ -43,12 +43,12 @@ it 'extracts context with trace id, span id' do parent_context = OpenTelemetry::Context.empty - carrier = { 'X-Amzn-Trace-Id' => 'Root=1-80f198e-e56343ba864fe8b2a57d3eff7;Parent=e457b5a2e4d86bd1' } + carrier = { 'X-Amzn-Trace-Id' => 'Root=1-80f198ea-e56343ba864fe8b2a57d3eff;Parent=e457b5a2e4d86bd1' } 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_trace_id).must_equal('80f198eae56343ba864fe8b2a57d3eff') _(extracted_context.hex_span_id).must_equal('e457b5a2e4d86bd1') _(extracted_context.trace_flags).must_equal(OpenTelemetry::Trace::TraceFlags::DEFAULT) _(extracted_context).must_be(:remote?) @@ -56,7 +56,7 @@ it 'converts debug flag to sampled' do parent_context = OpenTelemetry::Context.empty - carrier = { 'X-Amzn-Trace-Id' => 'Root=1-80f198e-e56343ba864fe8b2a57d3eff7;Parent=e457b5a2e4d86bd1;Sampled=d' } + carrier = { 'X-Amzn-Trace-Id' => 'Root=1-80f198ea-e56343ba864fe8b2a57d3eff;Parent=e457b5a2e4d86bd1;Sampled=d' } context = propagator.extract(carrier, context: parent_context) extracted_context = OpenTelemetry::Trace.current_span(context).context @@ -66,7 +66,7 @@ it 'handles malformed trace id' do parent_context = OpenTelemetry::Context.empty - carrier = { 'X-Amzn-Trace-Id' => 'Root=180f198e-e56343ba864fe8b2a57d3eff7;Parent=e457b5a2e4d86bd1;Sampled=1' } + carrier = { 'X-Amzn-Trace-Id' => 'Root=180f198ea-e56343ba864fe8b2a57d3eff;Parent=e457b5a2e4d86bd1;Sampled=1' } context = propagator.extract(carrier, context: parent_context) @@ -75,7 +75,7 @@ it 'handles malformed span id' do parent_context = OpenTelemetry::Context.empty - carrier = { 'X-Amzn-Trace-Id' => 'Root=1-80f198e-e56343ba864fe8b2a57d3eff7;Parent=457b5a2e4d86bd1;Sampled=1' } + carrier = { 'X-Amzn-Trace-Id' => 'Root=1-80f198ea-e56343ba864fe8b2a57d3eff;Parent=457b5a2e4d86bd1;Sampled=1' } context = propagator.extract(carrier, context: parent_context) @@ -86,7 +86,7 @@ describe '#inject' do it 'injects context with sampled trace flags' do context = create_context( - trace_id: '80f198ee56343ba864fe8b2a57d3eff7', + trace_id: '80f198eae56343ba864fe8b2a57d3eff', span_id: 'e457b5a2e4d86bd1', trace_flags: TraceFlags::SAMPLED ) @@ -94,13 +94,13 @@ carrier = {} propagator.inject(carrier, context: context) - expected_xray = 'Root=1-80f198e-e56343ba864fe8b2a57d3eff7;Parent=e457b5a2e4d86bd1;Sampled=1' + expected_xray = 'Root=1-80f198ea-e56343ba864fe8b2a57d3eff;Parent=e457b5a2e4d86bd1;Sampled=1' _(carrier['X-Amzn-Trace-Id']).must_equal(expected_xray) end it 'injects context with default trace flags' do context = create_context( - trace_id: '80f198ee56343ba864fe8b2a57d3eff7', + trace_id: '80f198eae56343ba864fe8b2a57d3eff', span_id: 'e457b5a2e4d86bd1', trace_flags: TraceFlags::DEFAULT ) @@ -108,13 +108,13 @@ carrier = {} propagator.inject(carrier, context: context) - expected_xray = 'Root=1-80f198e-e56343ba864fe8b2a57d3eff7;Parent=e457b5a2e4d86bd1;Sampled=0' + expected_xray = 'Root=1-80f198ea-e56343ba864fe8b2a57d3eff;Parent=e457b5a2e4d86bd1;Sampled=0' _(carrier['X-Amzn-Trace-Id']).must_equal(expected_xray) end it 'injects debug flag when present' do context = create_context( - trace_id: '80f198ee56343ba864fe8b2a57d3eff7', + trace_id: '80f198eae56343ba864fe8b2a57d3eff', span_id: 'e457b5a2e4d86bd1', xray_debug: true ) @@ -122,7 +122,7 @@ carrier = {} propagator.inject(carrier, context: context) - expected_xray = 'Root=1-80f198e-e56343ba864fe8b2a57d3eff7;Parent=e457b5a2e4d86bd1;Sampled=d' + expected_xray = 'Root=1-80f198ea-e56343ba864fe8b2a57d3eff;Parent=e457b5a2e4d86bd1;Sampled=d' _(carrier['X-Amzn-Trace-Id']).must_equal(expected_xray) end @@ -140,7 +140,7 @@ it 'no-ops if span id invalid' do context = create_context( - trace_id: '80f198ee56343ba864fe8b2a57d3eff7', + trace_id: '80f198eae56343ba864fe8b2a57d3eff', span_id: '0' * 16 )