Skip to main content

TraceContext

Struct TraceContext 

Source
pub struct TraceContext {
    pub trace_id: TraceId,
    pub span_id: SpanId,
    pub flags: SamplingFlags,
}
Expand description

A parsed W3C traceparent header value.

Holds a TraceId, a SpanId, and SamplingFlags. Only spec version 00 is accepted; future versions with extra fields will be rejected.

§Parsing

use api_bones::traceparent::{TraceContext, SamplingFlags};

let tc: TraceContext =
    "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
        .parse()
        .unwrap();

assert!(tc.flags.is_sampled());

§Serialization

Display produces the canonical traceparent string which can be used directly as an HTTP header value.

Fields§

§trace_id: TraceId

128-bit trace identifier.

§span_id: SpanId

64-bit parent span identifier.

§flags: SamplingFlags

Sampling and other flags.

Implementations§

Source§

impl TraceContext

Source

pub fn new() -> Self

Create a new TraceContext with fresh random IDs and the sampled flag set.

use api_bones::traceparent::TraceContext;

let tc = TraceContext::new();
assert!(tc.flags.is_sampled());
Source

pub fn child_span(&self) -> Self

Create a new child span — same trace_id, new span_id.

use api_bones::traceparent::TraceContext;

let parent = TraceContext::new();
let child = parent.child_span();
assert_eq!(child.trace_id, parent.trace_id);
assert_ne!(child.span_id, parent.span_id);
Source

pub fn header_value(&self) -> String

Produce the canonical traceparent header value string.

Equivalent to self.to_string().

Source

pub fn header_name(&self) -> &'static str

The canonical HTTP header name: traceparent.

use api_bones::traceparent::TraceContext;

let tc = TraceContext::new();
assert_eq!(tc.header_name(), "traceparent");

Trait Implementations§

Source§

impl Clone for TraceContext

Source§

fn clone(&self) -> TraceContext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for TraceContext

Source§

impl Debug for TraceContext

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for TraceContext

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for TraceContext

Available on crate feature serde only.
Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for TraceContext

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for TraceContext

Source§

impl FromStr for TraceContext

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parse a traceparent header value.

Only version 00 is accepted. Extra fields beyond the four standard ones are rejected per spec (future-version compatibility is the caller’s responsibility).

Source§

type Err = TraceContextError

The associated error which can be returned from parsing.
Source§

impl Hash for TraceContext

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl HeaderId for TraceContext

Available on crate feature std only.
Source§

const HEADER_NAME: &'static str = "traceparent"

The canonical HTTP header name for this type. Read more
Source§

fn as_str(&self) -> Cow<'_, str>

Return the string representation of this header value. Read more
Source§

impl PartialEq for TraceContext

Source§

fn eq(&self, other: &TraceContext) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for TraceContext

Available on crate feature serde only.
Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for TraceContext

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T> ValidateIp for T
where T: ToString,

Source§

fn validate_ipv4(&self) -> bool

Validates whether the given string is an IP V4
Source§

fn validate_ipv6(&self) -> bool

Validates whether the given string is an IP V6
Source§

fn validate_ip(&self) -> bool

Validates whether the given string is an IP