TracingHandler implements Handler<RoutingContext> { public static SpanContext serverSpanContext(RoutingContext routingContext) { SpanContext serverContext = null; Object object = routingContext.get(CURRENT_SPAN); if (object instanceof Span) { Span span = (Span) object; serverContext = span.context(); } else { log.error("Sever SpanContext is null or not an instance of SpanContext"); } return serverContext; } TracingHandler(Tracer tracer);  TracingHandler(Tracer tracer, List<WebSpanDecorator> decorators); @Override void handle(RoutingContext routingContext); static SpanContext serverSpanContext(RoutingContext routingContext); static final String CURRENT_SPAN; }
@Test public void testLocalSpan() throws Exception { { router.route("/localSpan").handler(routingContext -> { SpanContext serverSpanContext = TracingHandler.serverSpanContext(routingContext); io.opentracing.Tracer.SpanBuilder spanBuilder = mockTracer.buildSpan("localSpan"); spanBuilder.asChildOf(serverSpanContext) .start() .finish(); routingContext.response() .setStatusCode(202) .end(); }); request("/localSpan", HttpMethod.GET, 202); Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(2)); } List<MockSpan> mockSpans = mockTracer.finishedSpans(); Assert.assertEquals(2, mockSpans.size()); Assert.assertEquals(mockSpans.get(0).parentId(), mockSpans.get(1).context().spanId()); Assert.assertEquals(mockSpans.get(0).context().traceId(), mockSpans.get(1).context().traceId()); }