Skip to content

Commit 5b456dd

Browse files
authored
fix(proto): add serde(default) to Events and Status (#1485)
This should allow all fields in event to be optional, which is needed to decode JSON strings ## Changes - add `serde(default)` to `Events` for tonic generated types - add `serde(default)` to `Status` for tonic generated types ## Merge requirement checklist * [x] [CONTRIBUTING](https://github.com/open-telemetry/opentelemetry-rust/blob/main/CONTRIBUTING.md) guidelines followed * [x] Unit tests added/updated (if applicable) * [ ] Appropriate `CHANGELOG.md` files updated for non-trivial, user-facing changes * [ ] Changes in public API reviewed (if applicable)
1 parent 67e6a71 commit 5b456dd

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

opentelemetry-proto/src/proto/tonic/opentelemetry.proto.trace.v1.rs

+1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ pub mod span {
198198
#[cfg_attr(feature = "with-schemars", derive(schemars::JsonSchema))]
199199
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
200200
#[cfg_attr(feature = "with-serde", serde(rename_all = "camelCase"))]
201+
#[cfg_attr(feature = "with-serde", serde(default))]
201202
#[allow(clippy::derive_partial_eq_without_eq)]
202203
#[derive(Clone, PartialEq, ::prost::Message)]
203204
pub struct Event {

opentelemetry-proto/tests/grpc_build.rs

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ fn build_tonic() {
8282
"trace.v1.ResourceSpans",
8383
"common.v1.InstrumentationScope",
8484
"resource.v1.Resource",
85+
"trace.v1.Span.Event",
86+
"trace.v1.Span.Status",
8587
] {
8688
builder = builder.type_attribute(
8789
path,

opentelemetry-proto/tests/json_deserialize.rs

+15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod json_deserialize {
33
use opentelemetry_proto::tonic::collector::trace::v1::ExportTraceServiceRequest;
44
use opentelemetry_proto::tonic::common::v1::any_value::Value;
55
use opentelemetry_proto::tonic::common::v1::KeyValue;
6+
use opentelemetry_proto::tonic::trace::v1::span::Event;
67

78
// copied from example json file
89
// see https://github.com/open-telemetry/opentelemetry-proto/blob/v1.0.0/examples/trace.json
@@ -69,6 +70,13 @@ mod json_deserialize {
6970
}
7071
"#;
7172

73+
const EVENT_JSON: &str = r#"
74+
{
75+
"name": "my_event",
76+
"time_unix_nano": 1234567890
77+
}
78+
"#;
79+
7280
#[test]
7381
fn test_deserialize_traces() {
7482
let request: ExportTraceServiceRequest = serde_json::from_str(TRACES_JSON).unwrap();
@@ -139,4 +147,11 @@ mod json_deserialize {
139147
Value::StringValue("my.service".to_string())
140148
);
141149
}
150+
151+
#[test]
152+
fn test_event() {
153+
let event_json: Event = serde_json::from_str(EVENT_JSON).unwrap();
154+
assert_eq!(event_json.name, "my_event".to_string());
155+
assert_eq!(event_json.attributes.len(), 0);
156+
}
142157
}

0 commit comments

Comments
 (0)