/** * Creates a potentially noop span representing this request. This is used when you need to * provision a span in a different scope than where the request is executed. * * @since 4.4 */ public Span nextSpan(Req request) { Sampler override = httpSampler.toSampler(adapter, request, sampler); return tracer.withSampler(override).nextSpan(); }
@Test public void propagatesExtra_unsampledTrace() throws Exception { Tracer tracer = httpTracing.tracing().tracer().withSampler(Sampler.NEVER_SAMPLE); server.enqueue(new MockResponse()); ScopedSpan parent = tracer.startScopedSpan("test"); try { ExtraFieldPropagation.set(parent.context(), EXTRA_KEY, "joey"); get(client, "/foo"); } finally { parent.finish(); } assertThat(server.takeRequest().getHeader(EXTRA_KEY)) .isEqualTo("joey"); }
/** * Returns a span representing the sampled status of the current server span or null if there's no * span attached to the current thread. */ @Nullable public static brave.Span getServerSpan(Tracer tracer, ServerSpanThreadBinder threadBinder) { if (tracer == null) throw new NullPointerException("tracer == null"); if (threadBinder == null) throw new NullPointerException("threadBinder == null"); ServerSpan result = threadBinder.getCurrentServerSpan(); if (result == null || result.equals(ServerSpan.EMPTY)) return null; if (result.getSpan() != null) return toSpan(tracer, result.getSpan()); assert result.getSample() != null && !result.getSample() : "unexpected sample state: " + result; return tracer.withSampler(Sampler.NEVER_SAMPLE).newTrace(); }
@Test public void propagatesExtra_unsampledTrace() throws Exception { Tracer tracer = httpTracing.tracing().tracer().withSampler(Sampler.NEVER_SAMPLE); server.enqueue(new MockResponse()); ScopedSpan parent = tracer.startScopedSpan("test"); try { ExtraFieldPropagation.set(parent.context(), EXTRA_KEY, "joey"); get(client, "/foo"); } finally { parent.finish(); } assertThat(server.takeRequest().getHeader(EXTRA_KEY)) .isEqualTo("joey"); }
Integer samplingPriority = Integer.valueOf(sampling); if (samplingPriority == 0) { scopedBraveTracer = braveTracer.withSampler(Sampler.NEVER_SAMPLE); } else if (samplingPriority > 0) { scopedBraveTracer = braveTracer.withSampler(Sampler.ALWAYS_SAMPLE);