Skip to content

Commit 5aaf22c

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 b33f0cc commit 5aaf22c

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

opentelemetry-otlp/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- 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.
66
- Fixed `.with_headers()` in `HttpExporterBuilder` to correctly support multiple key/value pairs. [#2699](https://github.com/open-telemetry/opentelemetry-rust/pull/2699)
7+
- **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)
78

89
## 0.28.0
910

opentelemetry-otlp/src/lib.rs

+25
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,39 @@ impl ExportError for Error {
389389
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
390390
pub enum Protocol {
391391
/// GRPC protocol
392+
#[cfg_attr(feature = "serialize", serde(rename = "grpc"))]
392393
Grpc,
393394
/// HTTP protocol with binary protobuf
395+
#[cfg_attr(feature = "serialize", serde(rename = "http/protobuf"))]
394396
HttpBinary,
395397
/// HTTP protocol with JSON payload
398+
#[cfg_attr(feature = "serialize", serde(rename = "http/json"))]
396399
HttpJson,
397400
}
398401

399402
#[derive(Debug, Default)]
400403
#[doc(hidden)]
401404
/// Placeholder type when no exporter pipeline has been configured in telemetry pipeline.
402405
pub struct NoExporterConfig(());
406+
407+
#[cfg(test)]
408+
mod tests {
409+
410+
#[cfg(feature = "serialize")]
411+
#[test]
412+
fn test_protocol_serialization() {
413+
use super::Protocol;
414+
415+
for (protocol, expected) in [
416+
(Protocol::Grpc, r#""grpc""#),
417+
(Protocol::HttpBinary, r#""http/protobuf""#),
418+
(Protocol::HttpJson, r#""http/json""#),
419+
] {
420+
let serialized = serde_json::to_string(&protocol).unwrap();
421+
assert_eq!(serialized, expected);
422+
423+
let deserialized: Protocol = serde_json::from_str(&serialized).unwrap();
424+
assert_eq!(deserialized, protocol);
425+
}
426+
}
427+
}

0 commit comments

Comments
 (0)