class Span implements AutoCloseable, SpanData {

    public final void end() {
        duration = System.nanoTime() - duration;

        // we need to ensure this span context is ended even if it's not being logged,
        // otherwise we risk pollution of the context for subsequent operations.
        Optional<SpanContext> context = SpanHelper.currentContext();
        if (context.isPresent()) {
            context.get().endSpan(this);
            afterClose();
        } else {
            throw new IllegalStateException("Span.end() from a detached span.");
        }
    }

    protected  Span(Optional<BigInteger> parentSpanId, BigInteger spanId, String name, BigInteger traceId, long startTime, long startNanos, TraceLevel traceLevel);

}