SpanBuilder[F[_]] is a builder interface for creating and configuring Span instances. It provides a fluent API for setting span attributes, links, parent relationships, and other span properties.
Overview
TheSpanBuilder allows you to configure all aspects of a span before creating it. The builder uses an internal state that can be modified through various methods.
Properties
meta
Type:InstrumentMeta[F]
The instrument’s metadata. Indicates whether instrumentation is enabled.
Methods
modifyState
The modification function to apply to the current state
SpanBuilder[F]
Modifies the internal state using the provided function and returns the modified builder.
root
Returns:SpanBuilder[F]
Indicates that the span should be the root span and the scope parent should be ignored. This is equivalent to calling modifyState(_.withParent(SpanBuilder.Parent.Root)).
build
Returns:SpanOps[F]
Creates SpanOps using the current state of the builder. This is the final step that produces the actual span operations.
liftTo
The target effect type with a
MonadCancelThrow instanceSpanBuilder[G]
Modifies the context F using an implicit KindTransformer from F to G.
Requirements:
- Implicit
MonadCancelThrow[F] - Implicit
MonadCancelThrow[G] - Implicit
KindTransformer[F, G]
Parent Selection
TheSpanBuilder.Parent sealed trait defines the parent selection strategy:
Parent.propagate
Returns:Parent
Use the span context that is currently available in the scope as a parent (if any).
Parent.root
Returns:Parent
Indicates the span must be the root span.
Parent.explicit
The parent span context to use
Parent
Use the given parent span context as an explicit parent.
State
TheSpanBuilder.State sealed trait represents the internal state of the builder.
State Properties
attributes: Attributes- The attributes added to the statelinks: Vector[(SpanContext, Attributes)]- The links added to the stateparent: Parent- The parent selection strategyfinalizationStrategy: SpanFinalizer.Strategy- The selected finalization strategyspanKind: Option[SpanKind]- The selected span kindstartTimestamp: Option[FiniteDuration]- The explicit start timestamp
State Methods
addAttribute
The attribute to add to the state
State
Adds the given attribute to the state. If the state previously contained a mapping for the key, the old value is replaced.
addAttributes
The set of attributes to add
State
Adds multiple attributes to the state. If the state previously contained a mapping for any of the keys, the old values are replaced.
addLink
The context of the linked span
The set of attributes to associate with the link
State
Adds a link to another span context with associated attributes.
withFinalizationStrategy
The finalization strategy to use
State
Sets the finalization strategy for the span.
withSpanKind
The kind of span to create
State
Sets the SpanKind for the span.
withStartTimestamp
The explicit start timestamp from the epoch
State
Sets an explicit start timestamp. The timestamp should be based on Clock[F].realTime. Using Clock[F].monotonic may lead to a missing span.
withParent
The parent selection strategy to use
State
Sets the parent to use for the span.
Companion Object
State.init
Returns:State
Creates an initial state with default values:
- Empty attributes
- No links
SpanFinalizer.Strategy.reportAbnormalfinalization strategy- No span kind
- No start timestamp
Parent.Propagateparent strategy
noop
The backend to use for the no-op span
The effect type with an
Applicative instanceSpanBuilder[F]
Creates a no-op implementation of the SpanBuilder that produces no-op spans.