-
Notifications
You must be signed in to change notification settings - Fork 559
Description
OpenTelemetry Protocol Requirements:
The OTLP specification supports multiple transport protocols: gRPC, HTTP/protobuf, and HTTP/JSON.
We model this using a fluent builder style API - first to select the transport protocol (note the feature gates):
opentelemetry-rust/opentelemetry-otlp/src/span.rs
Lines 60 to 61 in c5fde17
#[cfg(any(feature = "http-proto", feature = "http-json"))] | |
pub fn with_http(self) -> SpanExporterBuilder<HttpExporterBuilderSet> { |
opentelemetry-rust/opentelemetry-otlp/src/span.rs
Lines 68 to 70 in c5fde17
#[cfg(feature = "grpc-tonic")] | |
impl SpanExporterBuilder<TonicExporterBuilderSet> { | |
/// Build the [SpanExporter] with the gRPC Tonic transport. |
Then, to select the encoding (rather confusingly called "protocol"):
fn with_protocol(mut self, protocol: Protocol) -> Self { |
opentelemetry-rust/opentelemetry-otlp/src/lib.rs
Lines 440 to 450 in c5fde17
/// The communication protocol to use when exporting data. | |
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))] | |
#[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
pub enum Protocol { | |
/// GRPC protocol | |
Grpc, | |
/// HTTP protocol with binary protobuf | |
HttpBinary, | |
/// HTTP protocol with JSON payload | |
HttpJson, | |
} |
This means we can select impossible combinations which are silently remapped at runtime:
HTTP Transport + gRPC Protocol: with_http().with_protocol(Protocol::Grpc)
uses HTTP transport with protobuf instead of actual gRPC wire format, silently accepting semantically incorrect configuration.
exporter/http/mod.rs:303 - Protocol::Grpc
falls through to _
wildcard and gets HTTP+protobuf instead of failing
gRPC Transport + HTTP Protocol: with_tonic().with_protocol(Protocol::HttpJson)
ignores protocol setting entirely, always uses gRPC regardless of specified protocol
exporter/tonic/mod.rs:140 - TonicExporterBuilder hard-codes protocol: Protocol::Grpc
regardless of user configuration
Feature-Gated Runtime Behavior: Protocol::HttpJson
compiles successfully but silently falls back to protobuf when http-json
feature is disabled
exporter/http/mod.rs:298-299 - #[cfg(feature = "http-json")]
arm disappears at compile time without the feature