diff --git a/opentelemetry-proto/src/proto/tonic/opentelemetry.proto.common.v1.rs b/opentelemetry-proto/src/proto/tonic/opentelemetry.proto.common.v1.rs index f8fe252297..828e3f8c86 100644 --- a/opentelemetry-proto/src/proto/tonic/opentelemetry.proto.common.v1.rs +++ b/opentelemetry-proto/src/proto/tonic/opentelemetry.proto.common.v1.rs @@ -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, } /// Nested message and enum types in `AnyValue`. @@ -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, } /// InstrumentationScope is a message representing the instrumentation scope information diff --git a/opentelemetry-proto/src/proto/tonic/opentelemetry.proto.metrics.v1.rs b/opentelemetry-proto/src/proto/tonic/opentelemetry.proto.metrics.v1.rs index 462305014f..d5e27fcc1e 100644 --- a/opentelemetry-proto/src/proto/tonic/opentelemetry.proto.metrics.v1.rs +++ b/opentelemetry-proto/src/proto/tonic/opentelemetry.proto.metrics.v1.rs @@ -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, } /// Nested message and enum types in `Metric`. @@ -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, } /// Nested message and enum types in `NumberDataPoint`. @@ -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, } /// Nested message and enum types in `Exemplar`. diff --git a/opentelemetry-proto/tests/grpc_build.rs b/opentelemetry-proto/tests/grpc_build.rs index 8477a4e626..0eb761d897 100644 --- a/opentelemetry-proto/tests/grpc_build.rs +++ b/opentelemetry-proto/tests/grpc_build.rs @@ -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