Java Code Examples for brave.propagation.TraceContext#shared()
The following examples show how to use
brave.propagation.TraceContext#shared() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MutableSpan.java From brave with Apache License 2.0 | 5 votes |
/** * Creates a new instance from the given context, and defaults in the span. * * <p><em>Note:</em> It is unexpected to have context properties also in the span defaults. The * context will win in this case, as opposed to throwing an exception. * * @since 5.12 */ public MutableSpan(TraceContext context, @Nullable MutableSpan defaults) { this(defaults != null ? defaults : EMPTY); if (context == null) throw new NullPointerException("context == null"); // We don't call the setters as context.*IdString are well formed this.traceId = context.traceIdString(); this.localRootId = context.localRootIdString(); this.parentId = context.parentIdString(); this.id = context.spanIdString(); flags = 0; // don't inherit flags from the span if (context.debug()) setDebug(); if (context.shared()) setShared(); }
Example 2
Source File: Tracer.java From brave with Apache License 2.0 | 3 votes |
/** * Joining is re-using the same trace and span ids extracted from an incoming RPC request. This * should not be used for messaging operations, as {@link #nextSpan(TraceContextOrSamplingFlags)} * is a better choice. * * <p>When this incoming context is sampled, we assume this is a shared span, one where the * caller and the current tracer report to the same span IDs. If no sampling decision occurred * yet, we have exclusive access to this span ID. * * <p>Here's an example of conditionally joining a span, depending on if a trace context was * extracted from an incoming request. * * <pre>{@code * extracted = extractor.extract(request); * span = contextOrFlags.context() != null * ? tracer.joinSpan(contextOrFlags.context()) * : tracer.nextSpan(extracted); * }</pre> * * <p><em>Note:</em> When {@link Propagation.Factory#supportsJoin()} is false, this will always * fork a new child via {@link #newChild(TraceContext)}. * * @see Propagation * @see Extractor#extract(Object) * @see TraceContextOrSamplingFlags#context() * @see #nextSpan(TraceContextOrSamplingFlags) */ public final Span joinSpan(TraceContext context) { if (context == null) throw new NullPointerException("context == null"); if (!supportsJoin) return newChild(context); // set shared flag if not already done int flags = InternalPropagation.instance.flags(context); if (!context.shared()) { flags |= FLAG_SHARED; return toSpan(context, InternalPropagation.instance.withFlags(context, flags)); } else { flags &= ~FLAG_SHARED; return toSpan(InternalPropagation.instance.withFlags(context, flags), context); } }