Skip to content
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

Fix serde #1856

Closed
wants to merge 4 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct AnyValue {
/// The value is one of the listed fields. It is valid for all values to be unspecified
/// in which case this AnyValue is considered to be "empty".
#[prost(oneof = "any_value::Value", tags = "1, 2, 3, 4, 5, 6, 7")]
#[cfg_attr(feature = "with-serde", serde(flatten))]
pub value: ::core::option::Option<any_value::Value>,
}
/// Nested message and enum types in `AnyValue`.
Expand Down Expand Up @@ -80,13 +81,6 @@ pub struct KeyValue {
#[prost(string, tag = "1")]
pub key: ::prost::alloc::string::String,
#[prost(message, optional, tag = "2")]
#[cfg_attr(
feature = "with-serde",
serde(
serialize_with = "crate::proto::serializers::serialize_to_value",
deserialize_with = "crate::proto::serializers::deserialize_from_value"
)
)]
pub value: ::core::option::Option<AnyValue>,
}
/// InstrumentationScope is a message representing the instrumentation scope information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ pub struct Metric {
/// reported value type for the data points, as well as the relatationship to
/// the time interval over which they are reported.
#[prost(oneof = "metric::Data", tags = "5, 7, 9, 10, 11")]
#[cfg_attr(feature = "with-serde", serde(flatten))]
pub data: ::core::option::Option<metric::Data>,
}
/// Nested message and enum types in `Metric`.
Expand Down Expand Up @@ -325,6 +326,7 @@ pub struct NumberDataPoint {
/// The value itself. A point is considered invalid when one of the recognized
/// value fields is not present inside this oneof.
#[prost(oneof = "number_data_point::Value", tags = "4, 6")]
#[cfg_attr(feature = "with-serde", serde(flatten))]
pub value: ::core::option::Option<number_data_point::Value>,
}
/// Nested message and enum types in `NumberDataPoint`.
Expand Down Expand Up @@ -674,6 +676,7 @@ pub struct Exemplar {
/// considered invalid when one of the recognized value fields is not present
/// inside this oneof.
#[prost(oneof = "exemplar::Value", tags = "3, 6")]
#[cfg_attr(feature = "with-serde", serde(flatten))]
pub value: ::core::option::Option<exemplar::Value>,
}
/// Nested message and enum types in `Exemplar`.
Expand Down
15 changes: 12 additions & 3 deletions opentelemetry-proto/tests/grpc_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,18 @@ fn build_tonic() {
}

// add custom serializer and deserializer for AnyValue
for path in ["common.v1.KeyValue.value", "logs.v1.LogRecord.body"] {
builder = builder
.field_attribute(path, "#[cfg_attr(feature =\"with-serde\", serde(serialize_with = \"crate::proto::serializers::serialize_to_value\", deserialize_with = \"crate::proto::serializers::deserialize_from_value\"))]");
builder = builder
.field_attribute("logs.v1.LogRecord.body", "#[cfg_attr(feature =\"with-serde\", serde(serialize_with = \"crate::proto::serializers::serialize_to_value\", deserialize_with = \"crate::proto::serializers::deserialize_from_value\"))]");

// flatten
for path in [
"common.v1.AnyValue.value",
"metrics.v1.Metric.data",
"metrics.v1.NumberDataPoint.value",
"metrics.v1.Exemplar.value",
] {
builder =
builder.field_attribute(path, "#[cfg_attr(feature =\"with-serde\", serde(flatten))]");
}

builder
Expand Down
Loading