SpanContextHandlerTracer implements Tracer { @Override public void endSpan(TraceContext traceContext) { endSpanOptions(traceContext.getHandle().getCurrentSpanContext(), null); traceContext.getHandle().detach(); } SpanContextHandlerTracer(Set<TraceSink> sinks, SpanContextHandler contextHandler, SpanContextFactory spanContextFactory, TimestampFactory timestampFactory);  SpanContextHandlerTracer(TraceSink sink, SpanContextHandler contextHandler, SpanContextFactory spanContextFactory, TimestampFactory timestampFactory); @Override TraceContext startSpan(String name); @Override TraceContext startSpan(String name, StartSpanOptions options); @Override void endSpan(TraceContext traceContext); @Override void endSpan(TraceContext traceContext, EndSpanOptions options); @Override void annotateSpan(TraceContext traceContext, Labels labels); @Override void setStackTrace(TraceContext traceContext, StackTrace stackTrace);  }
@Test public void testEndSpan() { SpanContext parent = new SpanContext(new TraceId(BigInteger.valueOf(1)), new SpanId(1), new TraceOptions()); SpanContext child = new SpanContext(new TraceId(BigInteger.valueOf(1)), new SpanId(2), new TraceOptions()); contextHandler.attach(parent); SpanContextHandle handle = contextHandler.attach(child); TraceContext inProgressContext = new TraceContext(handle); tracer.endSpan(inProgressContext); assertThat(contextHandler.current()).isEqualTo(parent); assertThat(sink.endSpanEvents).hasSize(1); TestTraceSink.EndSpanEvent endEvent = sink.endSpanEvents.get(0); assertThat(endEvent.context).isEqualTo(child); }
@Test public void testEndSpanWithOptions() { EndSpanOptions options = new EndSpanOptions(); Timestamp ts = new Timestamp() { @Override public long getSeconds() { return 1; } @Override public int getNanos() { return 2; } }; options.setTimestamp(ts); SpanContext parent = new SpanContext(new TraceId(BigInteger.valueOf(1)), new SpanId(1), new TraceOptions()); SpanContext child = new SpanContext(new TraceId(BigInteger.valueOf(1)), new SpanId(2), new TraceOptions()); contextHandler.attach(parent); SpanContextHandle handle = contextHandler.attach(child); TraceContext inProgressContext = new TraceContext(handle); tracer.endSpan(inProgressContext, options); assertThat(sink.endSpanEvents).hasSize(1); TestTraceSink.EndSpanEvent endEvent = sink.endSpanEvents.get(0); assertThat(contextHandler.current()).isEqualTo(parent); assertThat(endEvent.context).isEqualTo(child); assertThat(endEvent.timestamp).isEqualTo(ts); }