Refine search
/** * Get parent span id. * * @return Parent span id. Can be <code>null</code>. * @deprecated use {@link #nullableParentId()} */ @Deprecated @Nullable public Long getParentSpanId() { return nullableParentId(); }
public void addSpanIdToRequest(@Nullable SpanId spanId) { Map<String,String> at = this.invocation.getAttachments(); if (spanId == null) { at.put("Sampled", "0"); } else { at.put("Sampled", "1"); at.put("TraceId", spanId.traceIdString()); at.put("SpanId", IdConversion.convertToString(spanId.spanId)); if (spanId.nullableParentId() != null) { at.put("ParentSpanId", IdConversion.convertToString(spanId.parentId)); } } }
public SpanId build() { return new SpanId(this); }
Span(SpanId context) { this.context = context; trace_id_high = context.traceIdHigh; trace_id = context.traceId; parent_id = context.nullableParentId(); id = context.spanId; name = ""; // avoid NPE on equals if (context.debug()) debug = true; }
/** * Creates a new span id. * * @param traceId Trace Id. * @param spanId Span Id. * @param parentSpanId Nullable parent span id. * @deprecated Please use {@link SpanId.Builder} */ @Deprecated public static SpanId create(long traceId, long spanId, @Nullable Long parentSpanId) { return SpanId.builder().traceId(traceId).parentId(parentSpanId).spanId(spanId).build(); }
static SpanId getSpanId(String traceId, String spanId, String parentSpanId) { return SpanId.builder() .traceId(convertToLong(traceId)) .spanId(convertToLong(spanId)) .parentId(parentSpanId == null ? null : convertToLong(parentSpanId)).build(); }
@Override Span nextSpan(@Nullable SpanId maybeParent) { // Generates a new 64-bit ID, taking care to dodge zero which can be confused with absent long newSpanId = randomGenerator().nextLong(); while (newSpanId == 0L) { newSpanId = randomGenerator().nextLong(); } if (maybeParent == null) { // new trace return Brave.toSpan(SpanId.builder() .traceIdHigh(traceId128Bit() ? nextTraceIdHigh(randomGenerator()) : 0L) .traceId(newSpanId) .spanId(newSpanId) .sampled(sampler().isSampled(newSpanId)) .build()); } return Brave.toSpan(maybeParent.toBuilder() .parentId(maybeParent.spanId) .spanId(newSpanId) .build()); }
headers.put(BraveHttpHeaders.TraceId.getName(), Long.toString(spanId.getTraceId(), 16)); headers.put(BraveHttpHeaders.SpanId.getName(), Long.toString(spanId.getSpanId(), 16)); if (spanId.getParentSpanId() != null) { headers.put(BraveHttpHeaders.ParentSpanId.getName(),Long.toString(spanId.getParentSpanId(), 16));
/** * Should we sample this request or not? True means sample, false means don't, null means we defer * decision to someone further down in the stack. */ @Nullable public final Boolean sampled() { if (debug()) return true; return (flags & FLAG_SAMPLING_SET) == FLAG_SAMPLING_SET ? (flags & FLAG_SAMPLED) == FLAG_SAMPLED : null; }
public static TraceContext toTraceContext(SpanId spanId) { // visible for testing if (spanId == null) throw new NullPointerException("spanId == null"); return TraceContext.newBuilder() .traceIdHigh(spanId.traceIdHigh) .traceId(spanId.traceId) .parentId(spanId.nullableParentId()) .spanId(spanId.spanId) .debug(spanId.debug()) .sampled(spanId.sampled()).build(); }
Builder(SpanId source) { this.traceIdHigh = source.traceIdHigh; this.traceId = source.traceId; this.nullableParentId = source.nullableParentId(); this.spanId = source.spanId; this.flags = source.flags; this.shared = false; }
@Test public void usesExistingTraceId_local() throws Exception { server.enqueue(new MockResponse()); SpanId parent = brave.localTracer().startNewSpan(getClass().getSimpleName(), "test"); try { get(client, "/foo"); } finally { brave.localTracer().finishSpan(); } RecordedRequest request = server.takeRequest(); assertThat(request.getHeader("x-b3-traceId")) .isEqualTo(parent.traceIdString()); assertThat(request.getHeader("x-b3-parentspanid")) .endsWith(IdConversion.convertToString(parent.spanId)); }
/** * Creates a new span id. * * @param traceId Trace Id. * @param spanId Span Id. * @param parentSpanId Nullable parent span id. * @deprecated Please use {@link SpanId.Builder} */ @Deprecated public static SpanId create(long traceId, long spanId, @Nullable Long parentSpanId) { return SpanId.builder().traceId(traceId).parentId(parentSpanId).spanId(spanId).build(); }
static SpanId getSpanId(String traceId, String spanId, String parentSpanId, Boolean sampled) { return SpanId.builder() .traceIdHigh(traceId.length() == 32 ? convertToLong(traceId, 0) : 0) .traceId(convertToLong(traceId)) .spanId(convertToLong(spanId)) .sampled(sampled) .parentId(parentSpanId == null ? null : convertToLong(parentSpanId)).build(); } }
public static void addTracingHeaders(final ClientRequestAdapter clientRequestAdapter, final SpanId spanId, final String spanName) { if (spanId != null) { LOGGER.debug("Will trace request. Span Id returned from ClientTracer: {}", spanId); clientRequestAdapter.addHeader(BraveHttpHeaders.Sampled.getName(), TRUE); clientRequestAdapter.addHeader(BraveHttpHeaders.TraceId.getName(), IdConversion.convertToString(spanId.getTraceId())); clientRequestAdapter.addHeader(BraveHttpHeaders.SpanId.getName(), IdConversion.convertToString(spanId.getSpanId())); if (spanId.getParentSpanId() != null) { clientRequestAdapter.addHeader(BraveHttpHeaders.ParentSpanId.getName(), IdConversion.convertToString(spanId.getParentSpanId())); } if (spanName != null) { clientRequestAdapter.addHeader(BraveHttpHeaders.SpanName.getName(), spanName); } } else { LOGGER.debug("Will not trace request."); clientRequestAdapter.addHeader(BraveHttpHeaders.Sampled.getName(), FALSE); } } }
/** * Should we sample this request or not? True means sample, false means don't, null means we defer * decision to someone further down in the stack. */ @Nullable public final Boolean sampled() { if (debug()) return true; return (flags & FLAG_SAMPLING_SET) == FLAG_SAMPLING_SET ? (flags & FLAG_SAMPLED) == FLAG_SAMPLED : null; }
/** Preferred way to create spans, as it properly deals with the parent id */ public Span toSpan() { Span result = new Span(); result.setId(spanId); result.setTrace_id(traceId); result.setParent_id(nullableParentId()); if (debug()) result.setDebug(debug()); return result; }
Builder(SpanId source) { this.traceId = source.traceId; this.parentId = source.nullableParentId(); this.spanId = source.spanId; this.flags = source.flags; }
/** * This tests that the parent is determined at the time the request was made, not when the request * was executed. */ @Test public void usesParentFromInvocationTime_local() throws Exception { server.enqueue(new MockResponse().setBodyDelay(1, TimeUnit.SECONDS)); server.enqueue(new MockResponse()); SpanId parent = brave.localTracer().startNewSpan(getClass().getSimpleName(), "test"); try { getAsync(client, "/foo"); getAsync(client, "/foo"); } finally { brave.localTracer().finishSpan(); } // changing the local span after the fact! brave.localTracer().startNewSpan(getClass().getSimpleName(), "test"); try { for (int i = 0; i < 2; i++) { RecordedRequest request = server.takeRequest(); assertThat(request.getHeader("x-b3-traceId")) .isEqualTo(parent.traceIdString()); assertThat(request.getHeader("x-b3-parentspanid")) .endsWith(IdConversion.convertToString(parent.spanId)); } } finally { brave.localTracer().finishSpan(); } }
/** * Get parent span id. * * @return Parent span id. Can be <code>null</code>. * @deprecated use {@link #nullableParentId()} */ @Deprecated @Nullable public Long getParentSpanId() { return nullableParentId(); }