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
Show file tree
Hide file tree
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
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);
}
}
}
Loading