Tracer { Tracer( Clock clock, Propagation.Factory propagationFactory, SpanHandler spanHandler, PendingSpans pendingSpans, Sampler sampler, CurrentTraceContext currentTraceContext, boolean traceId128Bit, boolean supportsJoin, boolean alwaysSampleLocal, AtomicBoolean noop ) { this.clock = clock; this.propagationFactory = propagationFactory; this.spanHandler = spanHandler; this.pendingSpans = pendingSpans; this.sampler = sampler; this.currentTraceContext = currentTraceContext; this.traceId128Bit = traceId128Bit; this.supportsJoin = supportsJoin; this.alwaysSampleLocal = alwaysSampleLocal; this.noop = noop; } Tracer(
    Clock clock,
    Propagation.Factory propagationFactory,
    SpanHandler spanHandler,
    PendingSpans pendingSpans,
    Sampler sampler,
    CurrentTraceContext currentTraceContext,
    boolean traceId128Bit,
    boolean supportsJoin,
    boolean alwaysSampleLocal,
    AtomicBoolean noop
  ); @Deprecated Tracer withSampler(Sampler sampler); Span newTrace(); final Span joinSpan(TraceContext context); Span newChild(TraceContext parent); Span nextSpan(TraceContextOrSamplingFlags extracted); Span toSpan(TraceContext context); SpanInScope withSpanInScope(@Nullable Span span); SpanCustomizer currentSpanCustomizer(); @Nullable Span currentSpan(); Span nextSpan(); ScopedSpan startScopedSpan(String name); ScopedSpan startScopedSpan(String name, SamplerFunction<T> samplerFunction, T arg); Span nextSpan(SamplerFunction<T> samplerFunction, T arg); Span nextSpanWithParent(SamplerFunction<T> samplerFunction, T arg,
    @Nullable TraceContext parent); ScopedSpan startScopedSpanWithParent(String name, @Nullable TraceContext parent); @Override String toString();  }
@Test public void handler_hasNiceToString() { tracer = Tracing.newBuilder().build().tracer(); assertThat(tracer.pendingSpans).extracting("spanHandler") .hasToString("LogSpanHandler{name=brave.Tracer}"); }
@Test public void sampler() { Sampler sampler = new Sampler() { @Override public boolean isSampled(long traceId) { return false; } }; tracer = Tracing.newBuilder().sampler(sampler).build().tracer(); assertThat(tracer.sampler) .isSameAs(sampler); }
@Test public void localServiceName() { tracer = Tracing.newBuilder().localServiceName("my-foo").build().tracer(); assertThat(tracer).extracting("pendingSpans.defaultSpan.localServiceName") .isEqualTo("my-foo"); }
@Test public void localServiceName_defaultIsUnknown() { tracer = Tracing.newBuilder().build().tracer(); assertThat(tracer).extracting("pendingSpans.defaultSpan.localServiceName") .isEqualTo("unknown"); }
@Test public void localServiceName_ignoredWhenGivenLocalEndpoint() { Endpoint endpoint = Endpoint.newBuilder().ip("1.2.3.4").serviceName("my-bar").build(); tracer = Tracing.newBuilder().localServiceName("my-foo").endpoint(endpoint).build().tracer(); MutableSpan defaultSpan = new MutableSpan(); defaultSpan.localServiceName("my-bar"); defaultSpan.localIp("1.2.3.4"); assertThat(tracer).extracting("pendingSpans.defaultSpan").isEqualTo(defaultSpan); }
@Test public void toString_withSpanReporter() { tracer = Tracing.newBuilder().addSpanHandler(new SpanHandler() { @Override public boolean end(TraceContext context, MutableSpan span, Cause cause) { return true; } @Override public String toString() { return "MyHandler"; } }).spanReporter(new Reporter<zipkin2.Span>() { @Override public void report(zipkin2.Span span) { } @Override public String toString() { return "MyReporter"; } }).build().tracer(); assertThat(tracer).hasToString( "Tracer{spanHandler=[MyHandler, MyReporter]}" ); }