Skip to main content

TraceContext

Struct TraceContext 

Source
pub struct TraceContext { /* private fields */ }
Expand description

The trace a request belongs to.

Two ways in. TraceContext::parse continues a trace that already exists, which is the usual one: a service that received a traceparent of its own passes it on, and the cluster’s work appears under the same trace as the request that caused it.

use ytsaurus_client::{Client, TraceContext};

let incoming = "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01";
let client = Client::new("http://localhost:8000")
    .with_trace_context(&TraceContext::parse(incoming)?);

TraceContext::new starts one, for a program that is nobody’s callee. Print the id it made and the cluster’s copy of the trace can be found by it:

use ytsaurus_client::{Client, TraceContext};

let trace = TraceContext::new();
eprintln!("trace {}", trace.yt_trace_id());

let client = Client::new("http://localhost:8000").with_trace_context(&trace);

Implementations§

Source§

impl TraceContext

Source

pub fn new() -> Self

Starts a trace, sampled.

Sampled because a caller who asked for a trace wants it kept: the C++ wrapper’s EnableClientTracing and the Python wrapper’s generate_traceparent both do the same. An unsampled context is one that arrived that way — see TraceContext::parse.

Source

pub fn parse(header: &str) -> Result<Self>

Continues the trace a traceparent header names.

Both spellings the proxy accepts are accepted here: the standard 00-<trace>-<span>-<flags> and the version-less three-part form the Go SDK sends. Hex digits may be upper or lower case on the way in; what this client sends is always lowercase, as the standard requires.

The span id is carried through as it arrived, so the cluster’s spans hang under the span the caller named rather than under one belonging to this process. That is what a client with nothing of its own to point at can honestly do: the W3C wording asks a forwarder to substitute the id of its own current span, and this crate emits no spans the collector would know about — an invented id would name a parent that does not exist. The work still lands in the right trace, one level up from where a fully instrumented service would put it.

A tracestate that arrived beside the header is not in it, and is passed on separately — see TraceContext::with_tracestate.

§Errors

Returns ClientError::Config if the header is not a traceparent. Refusing is the point: a malformed header is dropped by the proxy without complaint, and the trace would then be silently missing the half that mattered.

Source

pub fn with_tracestate(self, state: impl Into<String>) -> Self

Carries a tracestate header alongside the traceparent.

The standard pairs the two, and asks a participant that forwards one to forward the other unmodified: tracestate is where a vendor puts the sampling decision or the correlation key that its own backend reads, and dropping it on this hop loses that for everything downstream. The proxy itself has no opinion about it — this is for the caller’s backend, not the cluster’s.

Not modified on the way through, deliberately: rewriting the list means claiming a vendor entry of one’s own, and this client has none.

use ytsaurus_client::{Client, TraceContext};

let incoming = "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01";
let context = TraceContext::parse(incoming)?.with_tracestate("vendora=t61,vendorb=x9");

let client = Client::new("http://localhost:8000").with_trace_context(&context);
Source

pub fn tracestate(&self) -> Option<&str>

The tracestate this context carries, if it was given one.

Source

pub fn trace_id(&self) -> &str

The trace, as the header spells it: 32 lowercase hex digits.

Source

pub fn yt_trace_id(&self) -> String

The trace, as the cluster spells it: four hyphenated hex groups, leading zeros dropped.

This is the form that appears in the proxy log, in the X-YT-Trace-Id header of a response, and in the cluster’s UI — the same 128 bits as TraceContext::trace_id, punctuated the way every other YTsaurus id is.

use ytsaurus_client::TraceContext;

let trace = TraceContext::parse("00-08e9bcc435c2be9b456f18c4e117ea31-00f067aa0ba902b7-01")?;

assert_eq!(trace.trace_id(), "08e9bcc435c2be9b456f18c4e117ea31");
assert_eq!(trace.yt_trace_id(), "8e9bcc4-35c2be9b-456f18c4-e117ea31");
Source

pub fn span_id(&self) -> &str

The span this client’s requests hang under: 16 lowercase hex digits.

Source

pub fn is_sampled(&self) -> bool

Whether the trace is being recorded.

A context that arrived unsampled is passed on unsampled: the decision belongs to whoever started the trace, and overriding it here would record half a trace.

Source

pub fn header(&self) -> String

The traceparent header value, as it goes on the wire.

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 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 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 PartialEq for TraceContext

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more