Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ public Response intercept(Chain chain) throws IOException {
OpenSpan span = Tracer.startSpan(spanName, SpanType.CLIENT_OUTGOING);
Request.Builder tracedRequest = request.newBuilder()
.addHeader(TraceHttpHeaders.TRACE_ID, Tracer.getTraceId())
.addHeader(TraceHttpHeaders.SPAN_ID, span.getSpanId())
.addHeader(TraceHttpHeaders.IS_SAMPLED, Tracer.isTraceObservable() ? "1" : "0");
.addHeader(TraceHttpHeaders.SPAN_ID, span.getSpanId());

if (Tracer.isTraceObservable()) {
tracedRequest.addHeader(TraceHttpHeaders.IS_SAMPLED, "1");
}

if (span.getParentSpanId().isPresent()) {
tracedRequest.header(TraceHttpHeaders.PARENT_SPAN_ID, span.getParentSpanId().get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ public void testHeaders_whenTraceIsNotObservable() throws IOException {
Request intercepted = requestCaptor.getValue();
assertThat(intercepted.header(TraceHttpHeaders.SPAN_ID)).isNotNull();
assertThat(intercepted.header(TraceHttpHeaders.TRACE_ID)).isEqualTo(traceId);
assertThat(intercepted.header(TraceHttpHeaders.IS_SAMPLED)).isEqualTo("0");

// intentionally don't send "0" for spans that weren't sampled in this service, so that downstream services
// can make the sampling decision for themselves
assertThat(intercepted.header(TraceHttpHeaders.IS_SAMPLED)).isNull();
}

@Test
Expand Down
13 changes: 6 additions & 7 deletions tracing/src/main/java/com/palantir/tracing/Observability.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@

package com.palantir.tracing;

import com.palantir.tracing.api.SpanObserver;

/**
* Represents the desired observability of a new trace.
*/
public enum Observability {
/**
* Force the trace to be sampled.
* Force the trace to be sampled, i.e.s spans will be sent to each {@link SpanObserver}, and any outgoing
* network requests will have the X-B3-SAMPLED header set to "1", so that all downstream services do the same.
*/
SAMPLE,

/**
* Force the trace to not be sampled.
*/
/** Do not send the trace's spans to any {@link SpanObserver} (on this service). */
DO_NOT_SAMPLE,

/**
* Do not force, and let the tracer decide the observability.
*/
/** Allow the {@link TraceSampler} to decide whether this trace will be observed or not. */
UNDECIDED
}