JaegerTracerFactory extends TracerFactory { @Override public boolean isRoot(Span span) { if (span instanceof SpanWrapper) { span = ((SpanWrapper) span).getDelegate(); } if (span instanceof io.jaegertracing.internal.JaegerSpan) { final io.jaegertracing.internal.JaegerSpan jaegerSpan = (io.jaegertracing.internal.JaegerSpan) span; return jaegerSpan.context().getParentId() == 0; } return false; }  @Override Tracer getTracer(StagemonitorPlugin.InitArguments initArguments); @Override boolean isRoot(Span span); @Override boolean isSampled(Span span);  }
@Test public void testIsRoot() throws Exception { final StagemonitorPlugin.InitArguments initArguments = mock(StagemonitorPlugin.InitArguments.class); when(initArguments.getMeasurementSession()).thenReturn( new MeasurementSession("JaegerTracerFactoryTest", "test", "test")); final JaegerTracerFactory jaegerTracerFactory = new JaegerTracerFactory(); final Tracer tracer = jaegerTracerFactory.getTracer(initArguments); Span rootSpan = tracer.buildSpan("foo").start(); try (final Scope rootScope = tracer.scopeManager().activate(rootSpan)) { final Span childSpan = tracer.buildSpan("bar").start(); try (final Scope childScope = tracer.scopeManager().activate(childSpan)) { assertThat(jaegerTracerFactory.isRoot(rootSpan)).isTrue(); assertThat(jaegerTracerFactory.isRoot(childSpan)).isFalse(); } } }