Skip to content

Commit be812b2

Browse files
committed
refactor: change Protocol's Serialize and Deserialize to use standard values
BREAKING CHANGE: users depending on the previous values (or having saved them) may observe the change
1 parent d4eb35a commit be812b2

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

opentelemetry-otlp/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## vNext
44

5+
- **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)
6+
57
## 0.30.0
68

79
Released 2025-May-23

opentelemetry-otlp/src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,13 @@ use serde::{Deserialize, Serialize};
442442
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
443443
pub enum Protocol {
444444
/// GRPC protocol
445+
#[cfg_attr(feature = "serialize", serde(rename = "grpc"))]
445446
Grpc,
446447
/// HTTP protocol with binary protobuf
448+
#[cfg_attr(feature = "serialize", serde(rename = "http/protobuf"))]
447449
HttpBinary,
448450
/// HTTP protocol with JSON payload
451+
#[cfg_attr(feature = "serialize", serde(rename = "http/json"))]
449452
HttpJson,
450453
}
451454

@@ -470,3 +473,25 @@ pub mod tonic_types {
470473
pub use tonic::transport::{Certificate, ClientTlsConfig, Identity};
471474
}
472475
}
476+
477+
#[cfg(test)]
478+
mod tests {
479+
480+
#[cfg(feature = "serialize")]
481+
#[test]
482+
fn test_protocol_serialization() {
483+
use super::Protocol;
484+
485+
for (protocol, expected) in [
486+
(Protocol::Grpc, r#""grpc""#),
487+
(Protocol::HttpBinary, r#""http/protobuf""#),
488+
(Protocol::HttpJson, r#""http/json""#),
489+
] {
490+
let serialized = serde_json::to_string(&protocol).unwrap();
491+
assert_eq!(serialized, expected);
492+
493+
let deserialized: Protocol = serde_json::from_str(&serialized).unwrap();
494+
assert_eq!(deserialized, protocol);
495+
}
496+
}
497+
}

0 commit comments

Comments
 (0)