opentracing / opentracing-java

OpenTracing API for Java. 🛑 This library is DEPRECATED! https://github.com/opentracing/specification/issues/163
http://opentracing.io
Apache License 2.0
1.68k stars 344 forks source link

Add unwrap to interfaces #282

Open jpkrohling opened 6 years ago

jpkrohling commented 6 years ago

It would be useful to have a <T extends Span> unwrap() method on the Span interface (and similar methods on similar interfaces), similar to JPA's. It would make it easier to call implementation-specific methods.

Before:

    Span span = tracer.buildSpan("test-operation").start();
    long traceId = ((JaegerSpanContext) span.context()).getTraceId();

After:

    Span span = tracer.buildSpan("test-operation").start();
    long traceId = span.context().<JaegerSpanContext>unwrap().getTraceId();

Before:

    JaegerSpanContext expectedContext = (JaegerSpanContext) jaegerSpan.context();

After:

    JaegerSpanContext expectedContext = jaegerSpan.context().unwrap();
sjoerdtalsma commented 6 years ago

Please note there is a bit of discussion in PR 211 about the desirability of adding this to the API

tedsuo commented 6 years ago

We may want to move this to a cross-language discussion as part of Trace Identifiers: https://github.com/opentracing/specification/issues/123