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

pub struct SpanBuilder {
Show fields pub parent_context: Context, 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_code: Option<StatusCode>, pub status_message: Option<Cow<'static, str>>, pub sampling_result: Option<SamplingResult>,
}
This is supported on crate feature trace only.

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

parent_context: Context

Parent Context

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

events: Option<Vec<Event>>

Span events

links: Option<Vec<Link>>

Span Links

status_code: Option<StatusCode>

Span status code

status_message: Option<Cow<'static, str>>

Span status message

sampling_result: Option<SamplingResult>

Sampling result

Implementations

impl SpanBuilder[src]

SpanBuilder methods

pub fn from_name<T: Into<Cow<'static, str>>>(name: T) -> Self[src]

Create a new span builder from a span name

pub fn with_parent_context(self, parent_context: Context) -> 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_events(self, events: Vec<Event>) -> Self[src]

Assign events

Assign links

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

Assign status code

pub fn with_status_message<T: Into<Cow<'static, str>>>(self, message: T) -> 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]

fn clone(&self) -> SpanBuilder[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for SpanBuilder[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl Default for SpanBuilder[src]

fn default() -> SpanBuilder[src]

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

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

pub fn vzip(self) -> V