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 46b04aa534..bc7714b998 100644 --- a/propagator/xray/lib/opentelemetry/propagator/xray/text_map_propagator.rb +++ b/propagator/xray/lib/opentelemetry/propagator/xray/text_map_propagator.rb @@ -38,6 +38,8 @@ class TextMapPropagator # if extraction fails def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) header = getter.get(carrier, XRAY_CONTEXT_KEY) + return context unless header + match = parse_header(header) return context unless match diff --git a/propagator/xray/test/text_map_propagator_test.rb b/propagator/xray/test/text_map_propagator_test.rb index 0c7e045dc9..656d294fb0 100644 --- a/propagator/xray/test/text_map_propagator_test.rb +++ b/propagator/xray/test/text_map_propagator_test.rb @@ -79,6 +79,14 @@ context = propagator.extract(carrier, context: parent_context) + _(context).must_equal(parent_context) + end + it 'handles missing header gracefully' do + parent_context = OpenTelemetry::Context.empty + carrier = {} + + context = propagator.extract(carrier, context: parent_context) + _(context).must_equal(parent_context) end end