Skip to content

feat: add generated proto models for profiles signal #2979

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

Merged
merged 9 commits into from
May 21, 2025
Merged
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-proto/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## vNext

- **Feature**: Added Rust code generation for profiles protos. [#2979](https://github.com/open-telemetry/opentelemetry-rust/pull/2979)
- Update `tonic` dependency version to 0.13
- - Update proto definitions to v1.6.0.

Expand Down
1 change: 1 addition & 0 deletions opentelemetry-proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ trace = ["opentelemetry/trace", "opentelemetry_sdk/trace"]
metrics = ["opentelemetry/metrics", "opentelemetry_sdk/metrics"]
logs = ["opentelemetry/logs", "opentelemetry_sdk/logs"]
zpages = ["trace"]
profiles = []
testing = ["opentelemetry/testing"]

# add ons
Expand Down
34 changes: 33 additions & 1 deletion opentelemetry-proto/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub(crate) mod serializers {
use crate::tonic::common::v1::any_value::{self, Value};
use crate::tonic::common::v1::AnyValue;
use serde::de::{self, MapAccess, Visitor};
use serde::ser::{SerializeMap, SerializeStruct};
use serde::ser::{SerializeMap, SerializeSeq, SerializeStruct};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::fmt;

Expand Down Expand Up @@ -174,6 +174,30 @@ pub(crate) mod serializers {
s.parse::<u64>().map_err(de::Error::custom)
}

pub fn serialize_vec_u64_to_string<S>(value: &[u64], serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let s = value.iter()
.map(|v| v.to_string())
.collect::<Vec<_>>();
let mut sq = serializer.serialize_seq(Some(s.len()))?;
for v in value {
sq.serialize_element(&v.to_string())?;
}
sq.end()
}

pub fn deserialize_vec_string_to_vec_u64<'de, D>(deserializer: D) -> Result<Vec<u64>, D::Error>
where
D: Deserializer<'de>,
{
let s: Vec<String> = Deserialize::deserialize(deserializer)?;
s.into_iter()
.map(|v| v.parse::<u64>().map_err(de::Error::custom))
.collect()
}

pub fn serialize_i64_to_string<S>(value: &i64, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
Expand Down Expand Up @@ -266,5 +290,13 @@ pub mod tonic {
pub mod v1;
}

/// Generated types used in zpages.
#[cfg(feature = "profiles")]
#[path = ""]
pub mod profiles {
#[path = "opentelemetry.proto.profiles.v1development.rs"]
pub mod v1;
}

pub use crate::transform::common::tonic::Attributes;
}

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions opentelemetry-proto/src/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ pub mod logs;

#[cfg(feature = "zpages")]
pub mod tracez;

#[cfg(feature = "profiles")]
pub mod profiles;
1 change: 1 addition & 0 deletions opentelemetry-proto/src/transform/profiles.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

11 changes: 11 additions & 0 deletions opentelemetry-proto/tests/grpc_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const TONIC_PROTO_FILES: &[&str] = &[
"src/proto/opentelemetry-proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto",
"src/proto/opentelemetry-proto/opentelemetry/proto/logs/v1/logs.proto",
"src/proto/opentelemetry-proto/opentelemetry/proto/collector/logs/v1/logs_service.proto",
"src/proto/opentelemetry-proto/opentelemetry/proto/profiles/v1development/profiles.proto",
"src/proto/tracez.proto",
];
const TONIC_INCLUDES: &[&str] = &["src/proto/opentelemetry-proto", "src/proto"];
Expand Down Expand Up @@ -66,6 +67,7 @@ fn build_tonic() {
"metrics.v1.Summary",
"metrics.v1.NumberDataPoint",
"metrics.v1.HistogramDataPoint",
"profiles.v1development.Function",
] {
builder = builder.type_attribute(
path,
Expand All @@ -87,6 +89,7 @@ fn build_tonic() {
"logs.v1.LogRecord.trace_id",
"metrics.v1.Exemplar.span_id",
"metrics.v1.Exemplar.trace_id",
"profiles.v1development.Profile.profile_id",
] {
builder = builder
.field_attribute(path, "#[cfg_attr(feature = \"with-serde\", serde(serialize_with = \"crate::proto::serializers::serialize_to_hex_string\", deserialize_with = \"crate::proto::serializers::deserialize_from_hex_string\"))]")
Expand All @@ -110,6 +113,14 @@ fn build_tonic() {
builder = builder
.field_attribute(path, "#[cfg_attr(feature = \"with-serde\", serde(serialize_with = \"crate::proto::serializers::serialize_u64_to_string\", deserialize_with = \"crate::proto::serializers::deserialize_string_to_u64\"))]")
}
for path in ["profiles.v1development.Profile.time_nanos"] {
builder = builder
.field_attribute(path, "#[cfg_attr(feature = \"with-serde\", serde(serialize_with = \"crate::proto::serializers::serialize_i64_to_string\", deserialize_with = \"crate::proto::serializers::deserialize_string_to_i64\"))]")
}
for path in ["profiles.v1development.Sample.timestamps_unix_nano"] {
builder = builder
.field_attribute(path, "#[cfg_attr(feature = \"with-serde\", serde(serialize_with = \"crate::proto::serializers::serialize_vec_u64_to_string\", deserialize_with = \"crate::proto::serializers::deserialize_vec_string_to_vec_u64\"))]")
}

// special serializer and deserializer for value
// The Value::value field must be hidden
Expand Down