Skip to content

Commit

Permalink
Return original context if parsing TraceContext fails
Browse files Browse the repository at this point in the history
  • Loading branch information
mwear committed Jan 17, 2020
1 parent 7000c57 commit 562ed24
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def initialize(traceparent_header_key: 'traceparent',
# which expects the carrier to respond to [] and []=.
# @yield [Carrier, String] if an optional getter is provided, extract will yield the carrier
# and the header key to the getter.
# @return [Context] Updated context with span context from the header, or a new one if
# parsing fails.
# @return [Context] Updated context with span context from the header, or the original
# context if parsing fails.
def extract(context, carrier, &getter)
getter ||= default_getter
header = getter.call(carrier, @traceparent_header_key)
Expand All @@ -48,7 +48,7 @@ def extract(context, carrier, &getter)
remote: true)
context.set_value(ContextKeys.extracted_span_context_key, span_context)
rescue OpenTelemetry::Error
context.set_value(ContextKeys.extracted_span_context_key, Trace::SpanContext.new)
context
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@
_(span_context.tracestate).must_equal('vendorname=opaquevalue')
end

it 'returns a valid non-remote SpanContext on error' do
it 'returns original context on error' do
ctx = extractor.extract(context, {}) { invalid_traceparent_header }
_(ctx).must_equal(context)
span_context = ctx[span_context_key]
_(span_context).wont_be :remote?
_(span_context).must_be :valid?
_(span_context).must_be_nil
end
end
end

0 comments on commit 562ed24

Please sign in to comment.