TracerShim#extract() returning current context instead of null in case of empty carrier
Describe the bug
The io.opentelemetry.opentracingshim.TracerShim#extract(format, carrier) method is not independent of the current opentelemetry Context.
If a current opentelemetry Context is set, the TracerShim#extract(format, carrier) method will return a SpanContext based on that context if the given carrier contains no context information.
However, the javadoc of the io.opentracing.Tracer#extract(format, carrier) method states:
If the span serialized state is missing the method returns null.
So, IMHO, for a carrier parameter containing no span serialized state, the TracerShim#extract() method should always return null.
Steps to reproduce
Adapt the io.opentelemetry.opentracingshim.TracerShimTest#extract_nullContext() unit test, activating a span first.
@Test
void extract_nullContext() {
tracerShim.activateSpan(tracerShim.buildSpan("one").start());
SpanContext result =
tracerShim.extract(Format.Builtin.TEXT_MAP, new TextMapAdapter(Collections.emptyMap()));
assertThat(result).isNull();
}
What did you expect to see?
I expected a null return value for the given empty carrier content.
What did you see instead?
TracerShimTest > extract_nullContext() FAILED
org.opentest4j.AssertionFailedError:
expected: null
but was: io.opentelemetry.opentracingshim.SpanContextShim@69c93ca4
What version and what artifacts are you using?
Using opentelemetry-opentracing-shim-1.9.0-alpha or current code from opentelemetry-java main branch as of today (2022-04-07).
Environment Compiler: OpenJDK 11.0.14.1 OS: Ubuntu 20.04
Calling @carlosalberto for input on this.