Skip to content

Commit

Permalink
change Protocol's Serialize and Deserialize to use standard values
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Mar 6, 2025
1 parent b33f0cc commit ea44667
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions opentelemetry-otlp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 25 additions & 0 deletions opentelemetry-otlp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,39 @@ 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,
}

#[derive(Debug, Default)]
#[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);
}
}
}

0 comments on commit ea44667

Please sign in to comment.