/** * If the input includes only this extra, set {@link #isPong() pong = true}. */ static boolean maybeSetPong(TraceContext context) { if (context.extra().size() == 1) { Object extra = context.extra().get(0); if (extra instanceof PingPongExtra) { ((PingPongExtra) extra).pong = true; return true; } } return false; }
/** Returns an immutable result from the values currently in the builder */ public final TraceContextOrSamplingFlags build() { final TraceContextOrSamplingFlags result; if (!extra.isEmpty() && type == 1) { // move extra to the trace context TraceContext context = (TraceContext) value; if (context.extra().isEmpty()) { context = InternalPropagation.instance.withExtra(context, ensureImmutable(extra)); } else { context = InternalPropagation.instance.withExtra(context, concatImmutableLists(context.extra(), extra)); } result = new TraceContextOrSamplingFlags(type, context, emptyList()); } else { // make sure the extra data is immutable and unmodifiable result = new TraceContextOrSamplingFlags(type, value, ensureImmutable(extra)); } if (!sampledLocal) return result; // save effort if no change return result.withFlags(value.flags | FLAG_SAMPLED_LOCAL); }
/** * 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() ); }
context.extra() ); return _toSpan(propagationFactory.decorate(context));
localRootId = implicitParent.localRootId(); spanId = implicitParent.spanId(); extra = concatImmutableLists(extra, implicitParent.extra()); } else { flags = InternalPropagation.instance.flags(samplingFlags);
/** * Used for log correlation or {@link brave.Span#tag(String, String) tag values} * * @return a formatted Root field like "1-58406520-a006649127e371903a2de979" or null if the * context was not created from an instance of {@link AWSPropagation}. */ @Nullable public static String traceId(TraceContext context) { for (int i = 0, length = context.extra().size(); i < length; i++) { Object next = context.extra().get(i); if (next instanceof Extra) { char[] result = new char[ROOT_LENGTH]; writeRoot(context, result, 0); return new String(result); } } // See if we have the field as a pass-through String maybeHeader = ExtraFieldPropagation.get(context, TRACE_ID_NAME); if (maybeHeader == null) return null; int i = maybeHeader.indexOf("Root="); if (i == -1) return null; i += 5; // Root= if (maybeHeader.length() < i + ROOT_LENGTH) return null; return maybeHeader.substring(i, i + ROOT_LENGTH); }
/** Returns an immutable result from the values currently in the builder */ public final TraceContextOrSamplingFlags build() { final TraceContextOrSamplingFlags result; if (!extra.isEmpty() && type == 1) { // move extra to the trace context TraceContext context = (TraceContext) value; if (context.extra().isEmpty()) { context = InternalPropagation.instance.withExtra(context, ensureImmutable(extra)); } else { context = InternalPropagation.instance.withExtra(context, concatImmutableLists(context.extra(), extra)); } result = new TraceContextOrSamplingFlags(type, context, emptyList()); } else { // make sure the extra data is immutable and unmodifiable result = new TraceContextOrSamplingFlags(type, value, ensureImmutable(extra)); } if (!sampledLocal) return result; // save effort if no change return result.withFlags(value.flags | FLAG_SAMPLED_LOCAL); }
/** * 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() ); }
context.extra() ); return _toSpan(propagationFactory.decorate(context));
localRootId = implicitParent.localRootId(); spanId = implicitParent.spanId(); extra = concatImmutableLists(extra, implicitParent.extra()); } else { flags = InternalPropagation.instance.flags(samplingFlags);