diff --git a/opentelemetry-otlp/CHANGELOG.md b/opentelemetry-otlp/CHANGELOG.md index 311a8a4bfc..af20aa658d 100644 --- a/opentelemetry-otlp/CHANGELOG.md +++ b/opentelemetry-otlp/CHANGELOG.md @@ -4,6 +4,7 @@ - The `OTEL_EXPORTER_OTLP_TIMEOUT`, `OTEL_EXPORTER_OTLP_TRACES_TIMEOUT`, `OTEL_EXPORTER_OTLP_METRICS_TIMEOUT` and `OTEL_EXPORTER_OTLP_LOGS_TIMEOUT` are changed from seconds to miliseconds. - Fixed `.with_headers()` in `HttpExporterBuilder` to correctly support multiple key/value pairs. [#2699](https://github.com/open-telemetry/opentelemetry-rust/pull/2699) +- **BREAKING** `opentelemetry_otlp::Protocol` implementations of `Serialize` and `Deserialize` have been changed to [match standard otel values for protocol](https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#otel_exporter_otlp_protocol). [#2765](https://github.com/open-telemetry/opentelemetry-rust/pull/2765) ## 0.28.0 diff --git a/opentelemetry-otlp/src/lib.rs b/opentelemetry-otlp/src/lib.rs index 4d80a017f1..a35a31cfcf 100644 --- a/opentelemetry-otlp/src/lib.rs +++ b/opentelemetry-otlp/src/lib.rs @@ -389,10 +389,13 @@ impl ExportError for Error { #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum Protocol { /// GRPC protocol + #[cfg_attr(feature = "serialize", serde(rename = "grpc"))] Grpc, /// HTTP protocol with binary protobuf + #[cfg_attr(feature = "serialize", serde(rename = "http/protobuf"))] HttpBinary, /// HTTP protocol with JSON payload + #[cfg_attr(feature = "serialize", serde(rename = "http/json"))] HttpJson, } @@ -400,3 +403,25 @@ pub enum Protocol { #[doc(hidden)] /// Placeholder type when no exporter pipeline has been configured in telemetry pipeline. pub struct NoExporterConfig(()); + +#[cfg(test)] +mod tests { + + #[cfg(feature = "serialize")] + #[test] + fn test_protocol_serialization() { + use super::Protocol; + + for (protocol, expected) in [ + (Protocol::Grpc, r#""grpc""#), + (Protocol::HttpBinary, r#""http/protobuf""#), + (Protocol::HttpJson, r#""http/json""#), + ] { + let serialized = serde_json::to_string(&protocol).unwrap(); + assert_eq!(serialized, expected); + + let deserialized: Protocol = serde_json::from_str(&serialized).unwrap(); + assert_eq!(deserialized, protocol); + } + } +}