Struct SpanBuilder
pub struct SpanBuilder {
pub trace_id: Option<TraceId>,
pub span_id: Option<SpanId>,
pub span_kind: Option<SpanKind>,
pub name: Cow<'static, str>,
pub start_time: Option<SystemTime>,
pub end_time: Option<SystemTime>,
pub attributes: Option<Vec<KeyValue>>,
pub events: Option<Vec<Event>>,
pub links: Option<Vec<Link>>,
pub status: Status,
pub sampling_result: Option<SamplingResult>,
}
opentelemetry
only.Expand description
SpanBuilder
allows span attributes to be configured before the span
has started.
use opentelemetry::{
global,
trace::{TracerProvider, SpanBuilder, SpanKind, Tracer},
};
let tracer = global::tracer("example-tracer");
// The builder can be used to create a span directly with the tracer
let _span = tracer.build(SpanBuilder {
name: "example-span-name".into(),
span_kind: Some(SpanKind::Server),
..Default::default()
});
// Or used with builder pattern
let _span = tracer
.span_builder("example-span-name")
.with_kind(SpanKind::Server)
.start(&tracer);
Fields§
§trace_id: Option<TraceId>
Trace id, useful for integrations with external tracing systems.
span_id: Option<SpanId>
Span id, useful for integrations with external tracing systems.
span_kind: Option<SpanKind>
Span kind
name: Cow<'static, str>
Span name
start_time: Option<SystemTime>
Span start time
end_time: Option<SystemTime>
Span end time
attributes: Option<Vec<KeyValue>>
Span attributes that are provided at the span creation time. More attributes can be added afterwards. Providing duplicate keys will result in multiple attributes with the same key, as there is no de-duplication performed.
events: Option<Vec<Event>>
Span events
links: Option<Vec<Link>>
Span Links
status: Status
Span status
sampling_result: Option<SamplingResult>
Sampling result
Implementations§
§impl SpanBuilder
SpanBuilder methods
impl SpanBuilder
SpanBuilder methods
pub fn from_name<T>(name: T) -> SpanBuilder
pub fn from_name<T>(name: T) -> SpanBuilder
Create a new span builder from a span name
pub fn with_trace_id(self, trace_id: TraceId) -> SpanBuilder
pub fn with_trace_id(self, trace_id: TraceId) -> SpanBuilder
Specify trace id to use if no parent context exists
pub fn with_span_id(self, span_id: SpanId) -> SpanBuilder
pub fn with_span_id(self, span_id: SpanId) -> SpanBuilder
Assign span id
pub fn with_kind(self, span_kind: SpanKind) -> SpanBuilder
pub fn with_kind(self, span_kind: SpanKind) -> SpanBuilder
Assign span kind
pub fn with_start_time<T>(self, start_time: T) -> SpanBuilderwhere
T: Into<SystemTime>,
pub fn with_start_time<T>(self, start_time: T) -> SpanBuilderwhere
T: Into<SystemTime>,
Assign span start time
pub fn with_end_time<T>(self, end_time: T) -> SpanBuilderwhere
T: Into<SystemTime>,
pub fn with_end_time<T>(self, end_time: T) -> SpanBuilderwhere
T: Into<SystemTime>,
Assign span end time
pub fn with_attributes<I>(self, attributes: I) -> SpanBuilderwhere
I: IntoIterator<Item = KeyValue>,
pub fn with_attributes<I>(self, attributes: I) -> SpanBuilderwhere
I: IntoIterator<Item = KeyValue>,
Assign span attributes from an iterable. Providing duplicate keys will result in multiple attributes with the same key, as there is no de-duplication performed.
pub fn with_events(self, events: Vec<Event>) -> SpanBuilder
pub fn with_events(self, events: Vec<Event>) -> SpanBuilder
Assign events
pub fn with_links(self, links: Vec<Link>) -> SpanBuilder
pub fn with_links(self, links: Vec<Link>) -> SpanBuilder
Assign links
pub fn with_status(self, status: Status) -> SpanBuilder
pub fn with_status(self, status: Status) -> SpanBuilder
Assign status code
pub fn with_sampling_result(
self,
sampling_result: SamplingResult,
) -> SpanBuilder
pub fn with_sampling_result( self, sampling_result: SamplingResult, ) -> SpanBuilder
Assign sampling result
Trait Implementations§
§impl Clone for SpanBuilder
impl Clone for SpanBuilder
§fn clone(&self) -> SpanBuilder
fn clone(&self) -> SpanBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more