yangxikun/opentelemetry-lua

TraceContext propagator should return unmodified context if header is not present

kamalmarhubi opened this issue · 2 comments

Pretty sure this is the culprit line:

return context:with_span_context(empty_span_context)

That should be

return context

This is in the spec:

If a value can not be parsed from the carrier, for a cross-cutting concern, the implementation MUST NOT throw an exception and MUST NOT store a new value in the Context, in order to preserve any previously existing valid value.

See also, eg, the Python implementation, which returns the unmodified context if the header is not present or contains invalid content: https://github.com/open-telemetry/opentelemetry-python/blob/75313b6c6d58945c1401622b6683ccdd28657984/opentelemetry-api/src/opentelemetry/trace/propagation/tracecontext.py#L51-L70

I came across this because I wrote a custom propagator for Google's x-cloud-trace-context header. Using that together with the tracecontext propagator via the composite propagator resulted in an empty context if only one of the headers was specified.

Nice catch! I think you are correct.

LGTM