.localServiceName(serviceName) .spanReporter(reporter) .build();
@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(); }
@Test(timeout = 20000) public void shouldSubmitSpanWhenSampled() throws Exception { final SpanCollectingReporter reporter = new SpanCollectingReporter(); final Tracing tracing = Tracing.newBuilder() .localServiceName(TEST_SERVICE) .spanReporter(reporter) .sampler(Sampler.create(1.0f)) .build(); testRemoteInvocation(tracing, null); // check span name final Span span = reporter.spans().take(); assertThat(span.name()).isEqualTo(TEST_SPAN); // check kind assertThat(span.kind()).isSameAs(Kind.CLIENT); // only one span should be submitted assertThat(reporter.spans().poll(1, TimeUnit.SECONDS)).isNull(); // check # of annotations (we add wire annotations) assertThat(span.annotations()).hasSize(2); // check tags assertThat(span.tags()).containsAllEntriesOf(ImmutableMap.of( "http.host", "foo.com", "http.method", "POST", "http.path", "/hello/armeria", "http.status_code", "200", "http.url", "none+h2c://foo.com/hello/armeria")); // check service name assertThat(span.localServiceName()).isEqualTo(TEST_SERVICE); // check remote service name assertThat(span.remoteServiceName()).isEqualTo("foo.com"); }
public BraveFeature(final String name) { this( HttpTracing .newBuilder(Tracing.newBuilder().localServiceName(name).build()) .serverParser(new HttpServerSpanParser()) .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(); }
/** 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(); }
public BraveFeature(final String name) { this( HttpTracing .newBuilder(Tracing.newBuilder().localServiceName(name).build()) .serverParser(new HttpServerSpanParser()) .build() ); }
protected void run() { final Tracing brave = Tracing.newBuilder() .localServiceName("book-store") .spanReporter(new TestSpanReporter()) .build(); final JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean(); sf.setServiceClass(BookStore.class); sf.setAddress("http://localhost:" + PORT); sf.getFeatures().add(new BraveFeature(brave)); sf.create(); } }
public BraveFeature(final String name) { this( HttpTracing .newBuilder(Tracing.newBuilder().localServiceName(name).build()) .serverParser(new HttpServerSpanParser()) .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(); }
protected Tracing tracing() { this.tracing= Tracing .newBuilder() .localServiceName(this.serviceName) .sampler(Sampler.ALWAYS_SAMPLE) .spanReporter(spanReporter()) .build(); return this.tracing; }
public BraveFeature(final String name) { this( HttpTracing .newBuilder(Tracing.newBuilder().localServiceName(name).build()) .serverParser(new HttpServerSpanParser()) .build() ); }
public BookStore() { brave = Tracing.newBuilder() .localServiceName("book-store") .spanReporter(new TestSpanReporter()) .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(); }
.localServiceName(TEST_SERVICE) .spanReporter(reporter) .sampler(Sampler.create(samplingRate))
@Test(timeout = 20000) public void shouldSubmitSpanWithCustomRemoteName() throws Exception { final SpanCollectingReporter reporter = new SpanCollectingReporter(); final Tracing tracing = Tracing.newBuilder() .localServiceName(TEST_SERVICE) .spanReporter(reporter) .sampler(Sampler.create(1.0f)) .build(); testRemoteInvocation(tracing, "fooService"); // check span name final Span span = reporter.spans().take(); // check tags assertThat(span.tags()).containsAllEntriesOf(ImmutableMap.of( "http.host", "foo.com", "http.method", "POST", "http.path", "/hello/armeria", "http.status_code", "200", "http.url", "none+h2c://foo.com/hello/armeria")); // check service name assertThat(span.localServiceName()).isEqualTo(TEST_SERVICE); // check remote service name, lower-cased assertThat(span.remoteServiceName()).isEqualTo("fooservice"); }
@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(); }
@Override public Tracer getTracer(StagemonitorPlugin.InitArguments initArguments) { final Tracing braveTracer = Tracing.newBuilder() .localServiceName(initArguments.getMeasurementSession().getApplicationName()) .reporter(getZipkinReporterBuilder(initArguments).build()) .sampler(getSampler()) .build(); return BraveTracer.newBuilder(braveTracer) .textMapPropagation(B3HeaderFormat.INSTANCE, Propagation.B3_STRING) .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(); }
@Test public void shouldNotSubmitSpanWhenNotSampled() throws Exception { final SpanCollectingReporter reporter = new SpanCollectingReporter(); final Tracing tracing = Tracing.newBuilder() .localServiceName(TEST_SERVICE) .spanReporter(reporter) .sampler(Sampler.create(0.0f)) .build(); testRemoteInvocation(tracing, null); assertThat(reporter.spans().poll(1, TimeUnit.SECONDS)).isNull(); }