Skip to content

Commit

Permalink
expose trace id property name constant (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
qinfchen authored and dansanduleac committed Aug 1, 2018
1 parent a258a1a commit 74aa06f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
public final class TraceEnrichingFilter implements ContainerRequestFilter, ContainerResponseFilter {
public static final TraceEnrichingFilter INSTANCE = new TraceEnrichingFilter();

/**
* This is the name of the trace id property we set on {@link ContainerRequestContext}.
*/
public static final String TRACE_ID_PROPERTY_NAME = "com.palantir.tracing.traceId";

@Context
private ExtendedUriInfo uriInfo;

Expand Down Expand Up @@ -70,7 +75,7 @@ public void filter(ContainerRequestContext requestContext) throws IOException {
}

// Give asynchronous downstream handlers access to the trace id
requestContext.setProperty("com.palantir.conjure.java.traceId", Tracer.getTraceId());
requestContext.setProperty(TRACE_ID_PROPERTY_NAME, Tracer.getTraceId());
}

// Handles outgoing response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void testFilter_setsMdcIfTraceIdHeaderIsPresent() throws Exception {
when(request.getHeaderString(TraceHttpHeaders.TRACE_ID)).thenReturn("traceId");
TraceEnrichingFilter.INSTANCE.filter(request);
assertThat(MDC.get(Tracers.TRACE_ID_KEY), is("traceId"));
verify(request).setProperty("com.palantir.conjure.java.traceId", "traceId");
verify(request).setProperty(TraceEnrichingFilter.TRACE_ID_PROPERTY_NAME, "traceId");
}

@Test
Expand All @@ -203,7 +203,7 @@ public void testFilter_createsReceiveAndSendEvents() throws Exception {
public void testFilter_setsMdcIfTraceIdHeaderIsNotePresent() throws Exception {
TraceEnrichingFilter.INSTANCE.filter(request);
assertThat(MDC.get(Tracers.TRACE_ID_KEY).length(), is(16));
verify(request).setProperty(eq("com.palantir.conjure.java.traceId"), anyString());
verify(request).setProperty(eq(TraceEnrichingFilter.TRACE_ID_PROPERTY_NAME), anyString());
}

public static class TracingTestServer extends Application<Configuration> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
* [...]
* }
*
* Note that network calls using remoting will be automatically wrapped with appropriate traces. Only use this
* to add traces to internal code.
*/
public final class CloseableTracer implements AutoCloseable {
private static final CloseableTracer INSTANCE = new CloseableTracer();
Expand Down
6 changes: 4 additions & 2 deletions tracing/src/main/java/com/palantir/tracing/TraceSampler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

package com.palantir.tracing;

import com.palantir.tracing.api.SpanObserver;

/**
* Nullary predicate that returns true iff the trace under consideration should be presented to the configured {@link
* com.palantir.conjure.java.api.tracing.SpanObserver observers}. Implementations must be thread-safe. The sampler is
* Nullary predicate that returns true iff the trace under consideration should be presented to the configured
* {@link SpanObserver observers}. Implementations must be thread-safe. The sampler is
* invoked synchronously on the thread calling into {@link Tracer} and must only do non-trivial work (e.g., at most
* drawing a random number).
*/
Expand Down

0 comments on commit 74aa06f

Please sign in to comment.