Interface Span.Builder

Enclosing interface:
Span

public static interface Span.Builder
In some cases (e.g. when dealing with Propagator.extract(Object, Propagator.Getter)'s we want to create a span that has not yet been started, yet it's heavily configurable (some options are not possible to be set when a span has already been started). We can achieve that by using a builder.

Inspired by OpenZipkin Brave and OpenTelemetry API.

  • Field Details

    • NOOP

      static final Span.Builder NOOP
      A noop implementation.
  • Method Details

    • setParent

      Span.Builder setParent(TraceContext context)
      Sets the parent of the built span.
      Parameters:
      context - parent's context
      Returns:
      this
    • setNoParent

      Span.Builder setNoParent()
      Sets no parent of the built span.
      Returns:
      this
    • name

      Span.Builder name(String name)
      Sets the name of the span.
      Parameters:
      name - span name
      Returns:
      this
    • event

      Span.Builder event(String value)
      Sets an event on the span.
      Parameters:
      value - event value
      Returns:
      this
    • tag

      Span.Builder tag(String key, String value)
      Sets a tag on the span.
      Parameters:
      key - tag key
      value - tag value
      Returns:
      this
    • error

      Span.Builder error(Throwable throwable)
      Sets an error on the span.
      Parameters:
      throwable - error to set
      Returns:
      this
    • kind

      Span.Builder kind(Span.Kind spanKind)
      Sets the kind on the span.
      Parameters:
      spanKind - kind of the span
      Returns:
      this
    • remoteServiceName

      Span.Builder remoteServiceName(String remoteServiceName)
      Sets the remote service name for the span.
      Parameters:
      remoteServiceName - remote service name
      Returns:
      this
    • remoteIpAndPort

      Span.Builder remoteIpAndPort(String ip, int port)
      Sets the remote URL for the span.
      Parameters:
      ip - remote service ip
      port - remote service port
      Returns:
      this
    • startTimestamp

      Span.Builder startTimestamp(long startTimestamp, TimeUnit unit)
      Sets start timestamp.
      Parameters:
      startTimestamp - start timestamp
      unit - start time unit
      Returns:
      this
    • start

      Span start()
      Builds and starts the span.
      Returns:
      started span