Skip to content

refactor: change Protocol's Serialize and Deserialize to use standard values #2765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions opentelemetry-otlp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@

## vNext

- **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.30.0

Released 2025-May-23
25 changes: 25 additions & 0 deletions opentelemetry-otlp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -442,10 +442,13 @@ use serde::{Deserialize, Serialize};
#[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,
}

@@ -470,3 +473,25 @@ pub mod tonic_types {
pub use tonic::transport::{Certificate, ClientTlsConfig, Identity};
}
}

#[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);
}
}
}