Closed arjun-1 closed 4 years ago
In OpenTracing the Tracer is responsible for creating spans. Jaeger tracer will never create a NoopSpan, so the class cast exception should not be happening, unless you're somehow trying to use two different tracers simultaneously.
OpenTelemetry does not have a notion of 'default span' in the spec.
Hi @yurishkuro, thanks for your response. I tried making the following minimal example https://github.com/arjun-1/opentracing-example, explaining the issue (or perhaps my improper use) with opentracing-java.
In this example I create a childspan of a NoopSpan
:
val mockTracer = new MockTracer()
val span: Span = NoopSpan.INSTANCE
mockTracer.buildSpan("operationName").asChildOf(span).start()
Which yields a ClassCastException
.
There is also another example showcased, which shows a similar issue happening in combination with JaegerTracer:
val span: Span = NoopSpan.INSTANCE
val jaegerTracer = new Configuration("seviceName").getTracerBuilder.build()
val textMapAdapter = new TextMapAdapter(Map.empty.asJava)
jaegerTracer.inject(span.context(), Format.Builtin.TEXT_MAP, textMapAdapter)
In these examples, I only use one tracer at a time. Is it possible though that I am using NoopSpan
in a way that is not intended?
NoopSpan
is an implementation detail of NoopTracer
, so the following statement is technically false:
In these examples, I only use one tracer at a time.
Ah thanks, I think I get it now. I understand correctly that even though NoopSpan extends Span
, NoopSpan
cannot be used interchangeably with any other Span
, if NoopSpan
itself belongs to a different Tracer
?
My initial thought was that NoopSpan
could be interchangeable be used for any Span
, driven by the observation that the equivalent of above examples work fine in java-opentelemetry (using io.opentelemetry.trace.DefaultSpan.INVALID
for NoopSpan
). But of course that is not any guarantee for a different library :slightly_smiling_face: .
If I want to initialize a 'dummy' value of type Span
(not being null
) in java-opentracing (and which would work with all kinds of Tracer
), would there be a recommended way?
If I want to initialize a 'dummy' value of type
Span
(not beingnull
) in java-opentracing (and which would work with all kinds ofTracer
), would there be a recommended way?
I don't think that's possible. Most implementations of Tracer
that I know of will cast spans and contexts to their implementation classes to access details that are not part of the standard OpenTracing API. See also https://github.com/opentracing-contrib/java-api-extensions/issues/16 for a similar issue.
Thanks, I understand :slightly_smiling_face:
I don't use opentracing-java directly, but wrap it through Scala (https://github.com/zio/zio-telemetry). I am in need of a 'default' span for opentracing-java (analogous to
DefaultSpan
in opentelemetry, to be used for initialization of the library), and thought thatNoopSpan
would be a suitable candidate.I can not use
NoopSpan
as a parent span however without gettingClassCastException
. For example in tests (when using.asChildOf
):Or when using jaegertracing:
Is this intended behavior? I understand a
NoopSpan
is not intended to be used as a valid root span, but a user of the wrapping library would preferably not be confronted with an exception if a child span is created without creating a valid root span first. Note that the strategy of usingDefaultSpan
as a default span works in opentelemetry-java without any exception.