opentracing-contrib/java-jaxrs

Not nesting spans

ribrewguy opened this issue · 5 comments

I'm running a Dropwizard app which uses Jersey for JAXRS. I have setup the following in the configuration of the service:

        Tracer tracer = TracerResolver.resolveTracer();
        DynamicFeature tracing = new ServerTracingDynamicFeature.Builder(tracer)
                    .build();

However, whenever a call is made I see two traces: 1) is for the JAXRS request, and 2) is from the nested code's tracing. I expected to see the nested code's span within the JAXRS req span. Is there some other configuration that needs to be applied?

@redijedi hi,

what tracer are you using? Do you have a reproducer or code snipped where you create that nested span?

I'm using Jaegar as the impl. I generally use Byteman rules to perform the nested tracing. One example would be:

RULE Enter Query for Foos
CLASS foo.bar.FooService
METHOD query
HELPER io.opentracing.contrib.agent.OpenTracingHelper
AT ENTRY
IF TRUE
DO
  getTracer().buildSpan("foo.query").startActive();
ENDRULE

RULE Exit Query for Foos
CLASS foo.bar.FooService
METHOD query
HELPER io.opentracing.contrib.agent.OpenTracingHelper
BIND
  span : io.opentracing.ActiveSpan = getTracer().activeSpan();
AT EXIT
IF span != null
DO
  span.setTag("status.code","OK");
  span.deactivate();
ENDRULE

The FooService.query invocation takes place within a JAXRS call, but both appear as separate spans, not nested as I would expect.

interesting maybe @objectiser can help here. I am not very familiar with byteman. However if foo.bar.FooService.query runs in a separate thread then the trace is broken (not sure whether it is your case).

The byteman rules are simply creating a span around the method call - so might be best if you could create a reproducer where this nested span is directly created inside the application, so minimise the number of dependencies. It seems like a thread related issue, so should be reproducable just with dropwizard and the jaxrs instrumentation.

I was able to resolve this by ensuring that I registered a tracer globally. By default it uses a noop tracer, so the internally instrumented code wasn't using the same tracer as the jaxrs feature.