Module brave
Package brave

Class Tracing.Builder

  • Enclosing class:
    Tracing

    public static final class Tracing.Builder
    extends java.lang.Object
    • Method Detail

      • localServiceName

        public Tracing.Builder localServiceName​(java.lang.String localServiceName)
        Lower-case label of the remote node in the service graph, such as "favstar". Avoid names with variables or unique identifiers embedded. Defaults to "unknown".

        This is a primary label for trace lookup and aggregation, so it should be intuitive and consistent. Many use a name from service discovery.

        See Also:
        localIp(String)
      • localIp

        public Tracing.Builder localIp​(java.lang.String localIp)
        The text representation of the primary IP address associated with this service. Ex. 192.168.99.100 or 2001:db8::c001. Defaults to a link local IP.
        Since:
        5.2
        See Also:
        localServiceName(String), localPort(int)
      • localPort

        public Tracing.Builder localPort​(int localPort)
        The primary listen port associated with this service. No default.
        Since:
        5.2
        See Also:
        localIp(String)
      • spanReporter

        public Tracing.Builder spanReporter​(zipkin2.reporter.Reporter<zipkin2.Span> spanReporter)
        Controls how spans are reported. Defaults to logging, but often an AsyncReporter which batches spans before sending to Zipkin. The AsyncReporter includes a Sender, which is a driver for transports like http, kafka and scribe.

        For example, here's how to batch send spans via http:

        
         spanReporter = AsyncReporter.create(URLConnectionSender.create("http://localhost:9411/api/v2/spans"));
        
         tracingBuilder.spanReporter(spanReporter);
         

        See https://github.com/apache/incubator-zipkin-reporter-java

      • clock

        public Tracing.Builder clock​(Clock clock)
        Assigns microsecond-resolution timestamp source for operations like Span.start(). Defaults to JRE-specific platform time.

        Note: timestamps are read once per trace, then ticks thereafter. This ensures there's no clock skew problems inside a single trace. See Tracing.clock(TraceContext)

      • sampler

        public Tracing.Builder sampler​(Sampler sampler)
        Sampler is responsible for deciding if a particular trace should be "sampled", i.e. whether the overhead of tracing will occur and/or if a trace will be reported to Zipkin.
        See Also:
        for temporary overrides
      • traceId128Bit

        public Tracing.Builder traceId128Bit​(boolean traceId128Bit)
        When true, new root spans will have 128-bit trace IDs. Defaults to false (64-bit)
      • addFinishedSpanHandler

        public Tracing.Builder addFinishedSpanHandler​(FinishedSpanHandler handler)
        Similar to spanReporter(Reporter) except it can read the trace context and create more efficient or completely different data structures. Importantly, the input is mutable for customization purposes.

        These handlers execute before the span reporter, which means any mutations occur prior to Zipkin.

        Advanced notes

        This is named firehose as it can receive data even when spans are not sampled remotely. For example, FinishedSpanHandler.alwaysSampleLocal() will generate data for all traced requests while not affecting headers. This setting is often used for metrics aggregation.

        Your handler can also be a custom span transport. When this is the case, set the span reporter to Reporter.NOOP to avoid redundant conversion overhead.

        Parameters:
        handler - skipped if FinishedSpanHandler.NOOP or already added
        See Also:
        alwaysReportSpans(), SamplingFlags.sampledLocal()