@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(); }
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); } }
@Bean Tracing tracing(Reporter<Span> reporter, DynamicProperties dynamicProperties, CurrentTraceContext currentTraceContext) { return Tracing.newBuilder() .localServiceName(dynamicProperties.getStringProperty(CONFIG_QUALIFIED_MICROSERVICE_NAME_KEY, DEFAULT_MICROSERVICE_NAME)) .currentTraceContext(currentTraceContext) // puts trace IDs into logs .spanReporter(reporter) .build(); }
.currentTraceContext( ThreadLocalCurrentTraceContext.newBuilder() .addScopeDecorator(MDCScopeDecorator.create())
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); } }
@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) { 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, this.spanReporters)) .traceId128Bit(sleuthProperties.isTraceId128()) .supportsJoin(sleuthProperties.isSupportsJoin()); for (FinishedSpanHandler finishedSpanHandlerFactory : this.finishedSpanHandlers) { builder.addFinishedSpanHandler(finishedSpanHandlerFactory); } return builder.build(); }
@Override protected Tracing createInstance() { Tracing.Builder builder = Tracing.newBuilder(); if (localServiceName != null) builder.localServiceName(localServiceName); if (localEndpoint != null) builder.endpoint(localEndpoint); if (endpoint != null) builder.endpoint(endpoint); if (spanReporter != null) builder.spanReporter(spanReporter); if (finishedSpanHandlers != null) { for (FinishedSpanHandler finishedSpanHandler : finishedSpanHandlers) { builder.addFinishedSpanHandler(finishedSpanHandler); } } if (errorParser != null) builder.errorParser(errorParser); if (clock != null) builder.clock(clock); if (sampler != null) builder.sampler(sampler); if (currentTraceContext != null) builder.currentTraceContext(currentTraceContext); if (propagationFactory != null) builder.propagationFactory(propagationFactory); if (traceId128Bit != null) builder.traceId128Bit(traceId128Bit); if (supportsJoin != null) builder.supportsJoin(supportsJoin); return builder.build(); }
private Tracing newTracing(String serviceName) { Tracing brave = null; if (camelContext.isUseMDCLogging()) { brave = Tracing.newBuilder() .currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder() .addScopeDecorator(MDCScopeDecorator.create()).build()) .localServiceName(serviceName) .sampler(Sampler.create(rate)) .spanReporter(spanReporter).build(); } else { brave = Tracing.newBuilder() .localServiceName(serviceName) .sampler(Sampler.create(rate)) .spanReporter(spanReporter).build(); } return brave; }
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); }
Tracing buildZipkinTracing(@NonNull String name, @NonNull String zipkinUrl, float samplingRate) { if (zipkinUrl.isEmpty() || !(samplingRate > 0f)) { return null; } return Tracing.newBuilder() .localServiceName(name) // puts trace IDs into logs .currentTraceContext(MDCCurrentTraceContext.create()) .spanReporter(buildReporter(zipkinUrl)) .sampler(Sampler.create(samplingRate)) .build(); } }
@Override protected Tracing buildZipkinTracing(String name, String zipkinUrl, float samplingRate) { if (currentTraceContext == null) { currentTraceContext = new StrictCurrentTraceContext(); } return Tracing.newBuilder() .spanReporter(ignored -> latch.countDown()) .currentTraceContext(currentTraceContext) .sampler(Sampler.ALWAYS_SAMPLE) .build(); } }
/** Controls aspects of tracing such as the service name that shows up in the UI */ @Bean Tracing tracing(@Value("${spring.application.name}") String serviceName) { return Tracing.newBuilder() .localServiceName(serviceName) .propagationFactory(ExtraFieldPropagation.newFactory(B3Propagation.FACTORY, "user-name")) .currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder() .addScopeDecorator(MDCScopeDecorator.create()) // puts trace IDs into logs .build() ) .spanReporter(spanReporter()).build(); }
@Bean Tracing tracing(Reporter<Span> reporter, DynamicProperties dynamicProperties, CurrentTraceContext currentTraceContext) { return Tracing.newBuilder() .localServiceName(dynamicProperties.getStringProperty(CONFIG_QUALIFIED_MICROSERVICE_NAME_KEY, DEFAULT_MICROSERVICE_NAME)) .currentTraceContext(currentTraceContext) // puts trace IDs into logs .reporter(reporter) .build(); }
@Bean Tracing tracing(Reporter<Span> reporter, DynamicProperties dynamicProperties, CurrentTraceContext currentTraceContext) { return Tracing.newBuilder() .localServiceName(dynamicProperties.getStringProperty(CONFIG_QUALIFIED_MICROSERVICE_NAME_KEY, DEFAULT_MICROSERVICE_NAME)) .currentTraceContext(currentTraceContext) // puts trace IDs into logs .spanReporter(reporter) .build(); }
/** Controls aspects of tracing such as the name that shows up in the UI */ @Bean Tracing tracing( @Lazy Reporter<Span> reporter, @Value("${zipkin.self-tracing.sample-rate:1.0}") float rate) { return Tracing.newBuilder() .localServiceName("zipkin-server") .sampler(rate < 0.01 ? BoundarySampler.create(rate) : Sampler.create(rate)) .currentTraceContext(currentTraceContext()) .spanReporter(reporter) .build(); }
@Override protected Tracing createInstance() { Tracing.Builder builder = Tracing.newBuilder(); if (localServiceName != null) builder.localServiceName(localServiceName); if (localEndpoint != null) builder.endpoint(localEndpoint); if (endpoint != null) builder.endpoint(endpoint); if (spanReporter != null) builder.spanReporter(spanReporter); if (finishedSpanHandlers != null) { for (FinishedSpanHandler finishedSpanHandler : finishedSpanHandlers) { builder.addFinishedSpanHandler(finishedSpanHandler); } } if (errorParser != null) builder.errorParser(errorParser); if (clock != null) builder.clock(clock); if (sampler != null) builder.sampler(sampler); if (currentTraceContext != null) builder.currentTraceContext(currentTraceContext); if (propagationFactory != null) builder.propagationFactory(propagationFactory); if (traceId128Bit != null) builder.traceId128Bit(traceId128Bit); if (supportsJoin != null) builder.supportsJoin(supportsJoin); return builder.build(); }
public TracedCorrelated() { super(Tracing.newBuilder() .currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder() // intentionally added twice to test overhead of multiple correlations .addScopeDecorator(ThreadContextScopeDecorator.create()) .addScopeDecorator(ThreadContextScopeDecorator.create()) .build()) .spanReporter(AsyncReporter.create(new NoopSender())) .build()); } }
@Test public void newDecorator_shouldWorkWhenRequestContextCurrentTraceContextConfigured() { HttpTracingService.newDecorator( Tracing.newBuilder().currentTraceContext(RequestContextCurrentTraceContext.DEFAULT).build()); }
@Test public void newDecorator_shouldWorkWhenRequestContextCurrentTraceContextConfigured() { HttpTracingClient.newDecorator( Tracing.newBuilder().currentTraceContext(RequestContextCurrentTraceContext.DEFAULT).build()); }
private static Tracing newTracing(String name) { final CurrentTraceContext currentTraceContext = RequestContextCurrentTraceContext.newBuilder() .addScopeDecorator(StrictScopeDecorator.create()) .build(); return Tracing.newBuilder() .currentTraceContext(currentTraceContext) .localServiceName(name) .spanReporter(spanReporter) .sampler(Sampler.ALWAYS_SAMPLE) .build(); }