Expand description
OpenTelemetry context propagation for gRPC.
This module provides utilities for propagating OpenTelemetry context (trace context and baggage) across gRPC service boundaries using tonic metadata.
§Usage
§Client-side injection
ⓘ
use linera_rpc::propagation::inject_context;
use opentelemetry::Context;
let mut request = tonic::Request::new(payload);
inject_context(&Context::current(), request.metadata_mut());§Server-side extraction
ⓘ
use linera_rpc::propagation::extract_context;
let cx = extract_context(request.metadata());
// Use cx.with_baggage() to access baggage valuesStructs§
- Extracted
Otel Context - Extension type to store the extracted OpenTelemetry context.
- Otel
Context Layer - Tower layer that extracts OpenTelemetry context from incoming gRPC requests.
- Otel
Context Service - Service wrapper that extracts OpenTelemetry context from requests.
Constants§
- TRAFFIC_
TYPE_ ENV_ VAR - Environment variable to override the traffic type.
- TRAFFIC_
TYPE_ KEY - Baggage key for traffic type labeling.
- TRAFFIC_
TYPE_ ORGANIC - Traffic type for normal production traffic.
- TRAFFIC_
TYPE_ SYNTHETIC - Traffic type for synthetic benchmark traffic.
- TRAFFIC_
TYPE_ UNKNOWN - Traffic type when OpenTelemetry feature is disabled.
Traits§
- HasOtel
Context - Trait for request types that can provide access to extracted OpenTelemetry context.
Functions§
- create_
request_ with_ context - Creates a new tonic::Request with the OpenTelemetry context injected into metadata.
- create_
request_ with_ current_ span_ context - Creates a new tonic::Request with the current tracing span’s context injected.
- extract_
context - Extracts the OpenTelemetry context from tonic metadata.
- get_
context_ with_ traffic_ type - Returns the current OpenTelemetry context, enriched with traffic type baggage
if the
LINERA_TRAFFIC_TYPEenvironment variable is set. - get_
otel_ context_ from_ tonic_ request - Gets the OpenTelemetry context from a tonic::Request’s extensions.
- get_
traffic_ type - Extracts the traffic type from the current context.
- get_
traffic_ type_ from_ request - Gets the traffic type from a request’s extensions.
- inject_
context - Injects the OpenTelemetry context into tonic metadata.