Refine search
@Override public Set<Object> getSingletons() { return new LinkedHashSet<>(asList(new Resource(), TracingApplicationEventListener.create( HttpTracing.create(Tracing.newBuilder().spanReporter(Reporter.NOOP).build()) ))); } }
protected Tracing.Builder tracingBuilder(Sampler sampler) { return Tracing.newBuilder() .spanReporter(s -> { // make sure the context was cleared prior to finish.. no leaks! TraceContext current = httpTracing.tracing().currentTraceContext().get(); boolean contextLeak = false; if (current != null) { // add annotation in addition to throwing, in case we are off the main thread if (current.spanIdString().equals(s.id())) { s = s.toBuilder().addAnnotation(s.timestampAsLong(), CONTEXT_LEAK).build(); contextLeak = true; } } spans.add(s); // throw so that we can see the path to the code that leaked the context if (contextLeak) { throw new AssertionError(CONTEXT_LEAK + " on " + Thread.currentThread().getName()); } }) .propagationFactory(ExtraFieldPropagation.newFactory(B3Propagation.FACTORY, EXTRA_KEY)) .currentTraceContext(currentTraceContext) .sampler(sampler); } }
@Setup(Level.Trial) public void init() { tracer = Tracing.newBuilder() .addFinishedSpanHandler(new FinishedSpanHandler() { @Override public boolean handle(TraceContext context, MutableSpan span) { return true; // anonymous subtype prevents all recording from being no-op } }) .spanReporter(Reporter.NOOP).build().tracer(); tracerExtra = Tracing.newBuilder() .propagationFactory(ExtraFieldPropagation.newFactory( B3Propagation.FACTORY, "x-vcap-request-id")) .addFinishedSpanHandler(new FinishedSpanHandler() { @Override public boolean handle(TraceContext context, MutableSpan span) { return true; // anonymous subtype prevents all recording from being no-op } }) .spanReporter(Reporter.NOOP).build().tracer(); }
@Test public void samplingDisabled() throws Exception { httpTracing = HttpTracing.create(tracingBuilder(Sampler.NEVER_SAMPLE).build()); init(); get("/foo"); // @After will check that nothing is reported }
@Before public void setup() throws Exception { httpTracing = HttpTracing.create(tracingBuilder(Sampler.ALWAYS_SAMPLE).build()); init(); }
@Before public void setup() { httpTracing = HttpTracing.create(tracingBuilder(Sampler.ALWAYS_SAMPLE).build()); client = newClient(server.getPort()); }
/** Unlike Brave 3, Brave 4 propagates trace ids even when unsampled */ @Test public void propagates_sampledFalse() throws Exception { close(); httpTracing = HttpTracing.create(tracingBuilder(Sampler.NEVER_SAMPLE).build()); client = newClient(server.getPort()); server.enqueue(new MockResponse()); get(client, "/foo"); RecordedRequest request = server.takeRequest(); assertThat(request.getHeaders().toMultimap()) .containsKeys("x-b3-traceId", "x-b3-spanId") .doesNotContainKey("x-b3-parentSpanId") .containsEntry("x-b3-sampled", asList("0")); }
@Test public void samplingDisabled() throws Exception { httpTracing = HttpTracing.create(tracingBuilder(Sampler.NEVER_SAMPLE).build()); init(); get("/foo"); // @After will check that nothing is reported }
@Before public void setup() { httpTracing = HttpTracing.create(tracingBuilder(Sampler.ALWAYS_SAMPLE).build()); client = newClient(server.getPort()); }
@Before public void setup() throws Exception { httpTracing = HttpTracing.create(tracingBuilder(Sampler.ALWAYS_SAMPLE).build()); BraveTracer braveTracer = BraveTracer.create(httpTracing.tracing()); httpTracingState = new HttpServerTracingDispatch("test", braveTracer); }
/** Unlike Brave 3, Brave 4 propagates trace ids even when unsampled */ @Test public void propagates_sampledFalse() throws Exception { close(); httpTracing = HttpTracing.create(tracingBuilder(Sampler.NEVER_SAMPLE).build()); client = newClient(server.getPort()); server.enqueue(new MockResponse()); get(client, "/foo"); RecordedRequest request = server.takeRequest(); assertThat(request.getHeaders().toMultimap()) .containsKeys("x-b3-traceId", "x-b3-spanId") .doesNotContainKey("x-b3-parentSpanId") .containsEntry("x-b3-sampled", asList("0")); }
@Before public void setup() throws Exception { httpTracing = HttpTracing.create(tracingBuilder(Sampler.ALWAYS_SAMPLE).build()); init(); }
@Test public void testThatProvidedSpanIsNotClosedWhenActive() throws MalformedURLException { final Tracing brave = Tracing.newBuilder() .localServiceName("book-store") .spanReporter(new TestSpanReporter()) .build(); final Span span = brave.tracer().nextSpan().name("test span").start(); try { try (SpanInScope scope = brave.tracer().withSpanInScope(span)) { assertThat(service.getBooks().size(), equalTo(2)); assertThat(brave.tracer().currentSpan(), not(nullValue()));
@Override public Set<Object> getSingletons() { return new LinkedHashSet<>(asList(new Resource(), TracingApplicationEventListener.create( HttpTracing.create(Tracing.newBuilder() .sampler(Sampler.NEVER_SAMPLE) .spanReporter(Reporter.NOOP) .build()) ))); } }
protected Tracing.Builder tracingBuilder(Sampler sampler) { return Tracing.newBuilder() .spanReporter(s -> { // make sure the context was cleared prior to finish.. no leaks! TraceContext current = httpTracing.tracing().currentTraceContext().get(); boolean contextLeak = false; if (current != null) { // add annotation in addition to throwing, in case we are off the main thread if (current.spanIdString().equals(s.id())) { s = s.toBuilder().addAnnotation(s.timestampAsLong(), CONTEXT_LEAK).build(); contextLeak = true; } } spans.add(s); // throw so that we can see the path to the code that leaked the context if (contextLeak) { throw new AssertionError(CONTEXT_LEAK + " on " + Thread.currentThread().getName()); } }) .propagationFactory(ExtraFieldPropagation.newFactory(B3Propagation.FACTORY, EXTRA_KEY)) .currentTraceContext(currentTraceContext) .sampler(sampler); } }
@Override public Set<Object> getSingletons() { return new LinkedHashSet<>(asList(new Resource(), TracingApplicationEventListener.create( HttpTracing.create(Tracing.newBuilder() .traceId128Bit(true) .spanReporter(Reporter.NOOP) .build()) ))); } }
Tracing.Builder tracingBuilder(Sampler sampler) { return Tracing.newBuilder() .spanReporter( s -> { // make sure the context was cleared prior to finish.. no leaks! TraceContext current = httpTracing.tracing().currentTraceContext().get(); if (current != null) { Assert.assertNotEquals(current.spanId(), s.id()); } spans.add(s); }) .currentTraceContext(currentTraceContext) .sampler(sampler); }
@Test public void newDecorator_shouldFailFastWhenRequestContextCurrentTraceContextNotConfigured() { assertThatThrownBy(() -> HttpTracingService.newDecorator(Tracing.newBuilder().build())) .isInstanceOf(IllegalStateException.class).hasMessage( "Tracing.currentTraceContext is not a RequestContextCurrentTraceContext scope. " + "Please call Tracing.Builder.currentTraceContext(RequestContextCurrentTraceContext.INSTANCE)." ); }
@Test public void newDecorator_shouldFailFastWhenRequestContextCurrentTraceContextNotConfigured() { assertThatThrownBy(() -> HttpTracingClient.newDecorator(Tracing.newBuilder().build())) .isInstanceOf(IllegalStateException.class).hasMessage( "Tracing.currentTraceContext is not a RequestContextCurrentTraceContext scope. " + "Please call Tracing.Builder.currentTraceContext(RequestContextCurrentTraceContext.INSTANCE)." ); }
@Bean @ConditionalOnMissingBean // NOTE: stable bean name as might be used outside sleuth Tracing tracing( @Value("${spring.zipkin.service.name:${spring.application.name:default}}") String serviceName, Propagation.Factory factory, CurrentTraceContext currentTraceContext, Sampler sampler, ErrorParser errorParser, SleuthProperties sleuthProperties, @Nullable List<Reporter<zipkin2.Span>> spanReporters) { Tracing.Builder builder = Tracing.newBuilder().sampler(sampler) .errorParser(errorParser) .localServiceName(StringUtils.isEmpty(serviceName) ? DEFAULT_SERVICE_NAME : serviceName) .propagationFactory(factory).currentTraceContext(currentTraceContext) .spanReporter(new CompositeReporter(this.spanAdjusters, spanReporters != null ? spanReporters : Collections.emptyList())) .traceId128Bit(sleuthProperties.isTraceId128()) .supportsJoin(sleuthProperties.isSupportsJoin()); for (FinishedSpanHandler finishedSpanHandlerFactory : this.finishedSpanHandlers) { builder.addFinishedSpanHandler(finishedSpanHandlerFactory); } return builder.build(); }