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
impl TraceContext
Sourcepub fn new() -> Self
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.
Sourcepub fn parse(header: &str) -> Result<Self>
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.
Sourcepub fn with_tracestate(self, state: impl Into<String>) -> Self
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);Sourcepub fn tracestate(&self) -> Option<&str>
pub fn tracestate(&self) -> Option<&str>
The tracestate this context carries, if it was given one.
Sourcepub fn yt_trace_id(&self) -> String
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");Sourcepub fn span_id(&self) -> &str
pub fn span_id(&self) -> &str
The span this client’s requests hang under: 16 lowercase hex digits.
Sourcepub fn is_sampled(&self) -> bool
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.
Trait Implementations§
Source§impl Clone for TraceContext
impl Clone for TraceContext
Source§fn clone(&self) -> TraceContext
fn clone(&self) -> TraceContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more