opentelemetry-java icon indicating copy to clipboard operation
opentelemetry-java copied to clipboard

TracerShim#extract() returning current context instead of null in case of empty carrier

Open calohmn opened this issue 3 years ago • 1 comments

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

calohmn avatar Apr 07 '22 07:04 calohmn

Calling @carlosalberto for input on this.

jkwatson avatar Apr 07 '22 23:04 jkwatson