TraceContext newRootContext() { return nextContext(FLAG_LOCAL_ROOT, 0L, 0L, 0L, 0L, Collections.emptyList()); }
/** * Explicitly creates a child within an existing trace. The result will be have its parent ID set * to the input's span ID. If a sampling decision has not yet been made, one will happen here. * * <p>To implicitly create a new trace, or a span within an existing one, use {@link * #nextSpan()}. */ public Span newChild(TraceContext parent) { if (parent == null) throw new NullPointerException("parent == null"); return _toSpan(nextContext(parent)); }
/** * Called by methods which can accept externally supplied parent trace contexts: Ex. {@link * #newChild(TraceContext)} and {@link #startScopedSpanWithParent(String, TraceContext)}. This * implies the {@link TraceContext#localRootId()} could be zero, if the context was manually * created. */ TraceContext nextContext(TraceContext parent) { return nextContext( InternalPropagation.instance.flags(parent), parent.traceIdHigh(), parent.traceId(), parent.localRootId(), parent.spanId(), parent.extra() ); }
/** * 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); }
return _toSpan(nextContext( InternalPropagation.instance.flags(extracted.traceIdContext()), traceIdContext.traceIdHigh(), flags = InternalPropagation.instance.flags(samplingFlags); return _toSpan(nextContext(flags, traceIdHigh, traceId, localRootId, spanId, extra));
TraceContext newRootContext() { return nextContext(FLAG_LOCAL_ROOT, 0L, 0L, 0L, 0L, Collections.emptyList()); }
/** * Explicitly creates a child within an existing trace. The result will be have its parent ID set * to the input's span ID. If a sampling decision has not yet been made, one will happen here. * * <p>To implicitly create a new trace, or a span within an existing one, use {@link * #nextSpan()}. */ public Span newChild(TraceContext parent) { if (parent == null) throw new NullPointerException("parent == null"); return _toSpan(nextContext(parent)); }
/** * Called by methods which can accept externally supplied parent trace contexts: Ex. {@link * #newChild(TraceContext)} and {@link #startScopedSpanWithParent(String, TraceContext)}. This * implies the {@link TraceContext#localRootId()} could be zero, if the context was manually * created. */ TraceContext nextContext(TraceContext parent) { return nextContext( InternalPropagation.instance.flags(parent), parent.traceIdHigh(), parent.traceId(), parent.localRootId(), parent.spanId(), parent.extra() ); }
/** * 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); }
return _toSpan(nextContext( InternalPropagation.instance.flags(extracted.traceIdContext()), traceIdContext.traceIdHigh(), flags = InternalPropagation.instance.flags(samplingFlags); return _toSpan(nextContext(flags, traceIdHigh, traceId, localRootId, spanId, extra));