Span _toSpan(TraceContext decorated) { if (isNoop(decorated)) return new NoopSpan(decorated); // allocate a mutable span in case multiple threads call this method.. they'll use the same data PendingSpan pendingSpan = pendingSpans.getOrCreate(decorated, false); return new RealSpan(decorated, pendingSpans, pendingSpan.state(), pendingSpan.clock(), finishedSpanHandler); }
/** * Returns a customizer for current span in scope or noop if there isn't one. * * <p>Unlike {@link CurrentSpanCustomizer}, this represents a single span. Accordingly, this * reference should not be saved as a field. That said, it is more efficient to save this result * as a method-local variable vs repeated calls. */ public SpanCustomizer currentSpanCustomizer() { // note: we don't need to decorate the context for propagation as it is only used for toString TraceContext context = currentTraceContext.get(); if (context == null || isNoop(context)) return NoopSpanCustomizer.INSTANCE; PendingSpan pendingSpan = pendingSpans.getOrCreate(context, false); return new RealSpanCustomizer(context, pendingSpan.state(), pendingSpan.clock()); }
/** * Same as {@link #startScopedSpan(String)}, except ignores the current trace context. * * <p>Use this when you are creating a scoped span in a method block where the parent was * created. You can also use this to force a new trace by passing null parent. */ // this api is needed to make tools such as executors which need to carry the invocation context public ScopedSpan startScopedSpanWithParent(String name, @Nullable TraceContext parent) { if (name == null) throw new NullPointerException("name == null"); if (parent == null) parent = currentTraceContext.get(); TraceContext context = parent != null ? nextContext(parent) : newRootContext(); Scope scope = currentTraceContext.newScope(context); if (isNoop(context)) return new NoopScopedSpan(context, scope); PendingSpan pendingSpan = pendingSpans.getOrCreate(context, true); Clock clock = pendingSpan.clock(); MutableSpan state = pendingSpan.state(); state.name(name); return new RealScopedSpan(context, scope, state, clock, pendingSpans, finishedSpanHandler); }
Span _toSpan(TraceContext decorated) { if (isNoop(decorated)) return new NoopSpan(decorated); // allocate a mutable span in case multiple threads call this method.. they'll use the same data PendingSpan pendingSpan = pendingSpans.getOrCreate(decorated, false); return new RealSpan(decorated, pendingSpans, pendingSpan.state(), pendingSpan.clock(), finishedSpanHandler); }
/** * Returns a customizer for current span in scope or noop if there isn't one. * * <p>Unlike {@link CurrentSpanCustomizer}, this represents a single span. Accordingly, this * reference should not be saved as a field. That said, it is more efficient to save this result * as a method-local variable vs repeated calls. */ public SpanCustomizer currentSpanCustomizer() { // note: we don't need to decorate the context for propagation as it is only used for toString TraceContext context = currentTraceContext.get(); if (context == null || isNoop(context)) return NoopSpanCustomizer.INSTANCE; PendingSpan pendingSpan = pendingSpans.getOrCreate(context, false); return new RealSpanCustomizer(context, pendingSpan.state(), pendingSpan.clock()); }
/** * Same as {@link #startScopedSpan(String)}, except ignores the current trace context. * * <p>Use this when you are creating a scoped span in a method block where the parent was * created. You can also use this to force a new trace by passing null parent. */ // this api is needed to make tools such as executors which need to carry the invocation context public ScopedSpan startScopedSpanWithParent(String name, @Nullable TraceContext parent) { if (name == null) throw new NullPointerException("name == null"); if (parent == null) parent = currentTraceContext.get(); TraceContext context = parent != null ? nextContext(parent) : newRootContext(); Scope scope = currentTraceContext.newScope(context); if (isNoop(context)) return new NoopScopedSpan(context, scope); PendingSpan pendingSpan = pendingSpans.getOrCreate(context, true); Clock clock = pendingSpan.clock(); MutableSpan state = pendingSpan.state(); state.name(name); return new RealScopedSpan(context, scope, state, clock, pendingSpans, finishedSpanHandler); }