[][src]Struct opentelemetry::api::trace::tracer::SpanBuilder

pub struct SpanBuilder {
    pub parent_context: Option<SpanContext>,
    pub trace_id: Option<TraceId>,
    pub span_id: Option<SpanId>,
    pub span_kind: Option<SpanKind>,
    pub name: String,
    pub start_time: Option<SystemTime>,
    pub end_time: Option<SystemTime>,
    pub attributes: Option<Vec<KeyValue>>,
    pub message_events: Option<Vec<Event>>,
    pub links: Option<Vec<Link>>,
    pub status_code: Option<StatusCode>,
    pub status_message: Option<String>,
    pub sampling_result: Option<SamplingResult>,
}

SpanBuilder allows span attributes to be configured before the span has started.

use opentelemetry::{
    api::{Provider, SpanBuilder, SpanKind, Tracer},
    global,
};

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".to_string(),
    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

parent_context: Option<SpanContext>

Parent SpanContext

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: String

Span name

start_time: Option<SystemTime>

Span start time

end_time: Option<SystemTime>

Span end time

attributes: Option<Vec<KeyValue>>

Span attributes

message_events: Option<Vec<Event>>

Span Message events

links: Option<Vec<Link>>

Span Links

status_code: Option<StatusCode>

Span status code

status_message: Option<String>

Span status message

sampling_result: Option<SamplingResult>

Sampling result

Implementations

impl SpanBuilder[src]

SpanBuilder methods

pub fn from_name(name: String) -> Self[src]

Create a new span builder from a span name

pub fn with_parent(self, parent_context: SpanContext) -> Self[src]

Assign parent context

pub fn with_trace_id(self, trace_id: TraceId) -> Self[src]

Specify trace id to use if no parent context exists

pub fn with_span_id(self, span_id: SpanId) -> Self[src]

Assign span id

pub fn with_kind(self, span_kind: SpanKind) -> Self[src]

Assign span kind

pub fn with_start_time<T: Into<SystemTime>>(self, start_time: T) -> Self[src]

Assign span start time

pub fn with_end_time<T: Into<SystemTime>>(self, end_time: T) -> Self[src]

Assign span end time

pub fn with_attributes(self, attributes: Vec<KeyValue>) -> Self[src]

Assign span attributes

pub fn with_message_events(self, message_events: Vec<Event>) -> Self[src]

Assign message events

Assign links

pub fn with_status_code(self, code: StatusCode) -> Self[src]

Assign status code

pub fn with_status_message(self, message: String) -> Self[src]

Assign status message

pub fn with_sampling_result(self, sampling_result: SamplingResult) -> Self[src]

Assign sampling result

pub fn start<T: Tracer>(self, tracer: &T) -> T::Span[src]

Builds a span with the given tracer from this configuration.

Trait Implementations

impl Clone for SpanBuilder[src]

impl Debug for SpanBuilder[src]

impl Default for SpanBuilder[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> FutureExt for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,