SpanContext { public void endSpan(Span span) { if (spans.isEmpty()) { SpanHelper.LOG.warning("Ending span " + span.getName() + ":" + span.getSpanId() + " when no spans exist in SpanContext"); } Span poppedSpan = spans.pop(); int extraPops = 0; while (!Objects.equals(poppedSpan, span)) { extraPops++; poppedSpan = spans.pop(); } if (extraPops > 0) { SpanHelper.LOG.warning("Popped " + extraPops + " unclosed Spans"); } } SpanContext(); Optional<Span> currentSpan(); Optional<BigInteger> currentTraceId(); Optional<BigInteger> currentSpanId(); void startSpan(Span span); void endSpan(Span span); TraceLevel currentTraceLevel();  }
@Test(expected = EmptyStackException.class) public void testEndingSpanWhenNonePresentRaisesEmptyStackException() { context.endSpan(new EnabledSpan(BigInteger.ONE, BigInteger.TEN, Optional.<BigInteger>absent(), "unknown", TraceLevel.INHERIT)); }