From 42fa7921632c4f1ef9112f255d2d66efbee1478d Mon Sep 17 00:00:00 2001 From: scar-lovevery <68864650+scar-lovevery@users.noreply.github.com> Date: Thu, 24 Jun 2021 09:04:50 -0600 Subject: [PATCH] Fix: XRay propagator null exception (#833) * Fixing XRay propagator null exception * Add test for missing header Co-authored-by: Robert --- .../opentelemetry/propagator/xray/text_map_propagator.rb | 2 ++ propagator/xray/test/text_map_propagator_test.rb | 8 ++++++++ 2 files changed, 10 insertions(+) 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