Module propagation

Source
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 values

Structs§

ExtractedOtelContext
Extension type to store the extracted OpenTelemetry context.
OtelContextLayer
Tower layer that extracts OpenTelemetry context from incoming gRPC requests.
OtelContextService
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§

HasOtelContext
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_TYPE environment 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.