pub struct TracingContext(Context);
Expand description
Context for tracing used for propagating tracing information in a distributed system.
Generally, the caller of a service should create a tracing context from the current tracing span and pass it to the callee through the network. The callee will then attach its local tracing span as a child of the tracing context, so that the external tracing service can associate them in a single trace.
The tracing context must be serialized and deserialized when passing through the network. There’re two ways to do this:
- For RPC calls with clear caller/callee relationship, the tracing context can be serialized into the W3C trace context format and passed in HTTP headers seamlessly with a service middleware. For example, the DDL requests from the frontend to the meta service.
- For RPC calls with no clear caller/callee relationship or with asynchronous semantics, the
tracing context should be passed manually as a protobuf field in the request and response for
better lifetime management. For example, the exchange services between streaming actors or
batch stages, and the
create_task
requests from the frontend to the batch service.
See Trace Context for more information.
Tuple Fields§
§0: Context
Implementations§
source§impl TracingContext
impl TracingContext
sourcepub fn from_current_span() -> Self
pub fn from_current_span() -> Self
Create a new tracing context from the current tracing span considered by the subscriber.
sourcepub fn attach(&self, span: Span) -> Span
pub fn attach(&self, span: Span) -> Span
Attach the given span as a child of the context. Returns the attached span.
sourcefn to_w3c(&self) -> HashMap<String, String>
fn to_w3c(&self) -> HashMap<String, String>
Convert the tracing context to the W3C trace context format.
sourcefn from_w3c(fields: &HashMap<String, String>) -> Self
fn from_w3c(fields: &HashMap<String, String>) -> Self
Create a new tracing context from the W3C trace context format.
sourcepub fn to_protobuf(&self) -> HashMap<String, String>
pub fn to_protobuf(&self) -> HashMap<String, String>
Convert the tracing context to the protobuf format.
sourcepub fn from_protobuf(fields: &HashMap<String, String>) -> Self
pub fn from_protobuf(fields: &HashMap<String, String>) -> Self
Create a new tracing context from the protobuf format.
sourcepub fn to_http_headers(&self) -> HeaderMap
pub fn to_http_headers(&self) -> HeaderMap
Convert the tracing context to the W3C trace context format in HTTP headers.
sourcepub fn from_http_headers(headers: &HeaderMap) -> Option<Self>
pub fn from_http_headers(headers: &HeaderMap) -> Option<Self>
Create a new tracing context from the W3C trace context format in HTTP headers.
Returns None
if the headers are invalid.
Trait Implementations§
source§impl Clone for TracingContext
impl Clone for TracingContext
source§fn clone(&self) -> TracingContext
fn clone(&self) -> TracingContext
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for TracingContext
impl !RefUnwindSafe for TracingContext
impl Send for TracingContext
impl Sync for TracingContext
impl Unpin for TracingContext
impl !UnwindSafe for TracingContext
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Err = Infallible
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>
source§impl<M> MetricVecRelabelExt for M
impl<M> MetricVecRelabelExt for M
source§fn relabel(
self,
metric_level: MetricLevel,
relabel_threshold: MetricLevel,
) -> RelabeledMetricVec<M>
fn relabel( self, metric_level: MetricLevel, relabel_threshold: MetricLevel, ) -> RelabeledMetricVec<M>
RelabeledMetricVec::with_metric_level
.source§fn relabel_n(
self,
metric_level: MetricLevel,
relabel_threshold: MetricLevel,
relabel_num: usize,
) -> RelabeledMetricVec<M>
fn relabel_n( self, metric_level: MetricLevel, relabel_threshold: MetricLevel, relabel_num: usize, ) -> RelabeledMetricVec<M>
RelabeledMetricVec::with_metric_level_relabel_n
.source§fn relabel_debug_1(
self,
relabel_threshold: MetricLevel,
) -> RelabeledMetricVec<M>
fn relabel_debug_1( self, relabel_threshold: MetricLevel, ) -> RelabeledMetricVec<M>
RelabeledMetricVec::with_metric_level_relabel_n
with metric_level
set to
MetricLevel::Debug
and relabel_num
set to 1.