-
Notifications
You must be signed in to change notification settings - Fork 15
[profiling] Support OTel signal #1181
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
Draft
danielsn
wants to merge
29
commits into
main
Choose a base branch
from
dsn/otel-proto
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 9 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
4b9d3be
[profiling] Support Otel protobuf
danielsn ab97024
vendor protoc
danielsn 93b17ae
serialize
danielsn c610684
dockerfile
danielsn 234c466
emit otel
danielsn ae123cd
Merge branch 'main' into dsn/otel-proto
danielsn b08a0df
miri ignore
danielsn e4c8724
don't checkout that file
danielsn 8f69381
more miri ignore
danielsn 7a0dca2
Merge branch 'main' into dsn/otel-proto
danielsn 4edfdef
PR Comment: Move prelude to file
danielsn 5c1b2af
simplify tests
danielsn 29f6c67
simplify the tests a bit more
danielsn 4004cb5
remove unneeded comments
danielsn f3682ee
PR comment: don't rename types
danielsn b63529e
cleanup tests
danielsn 819f571
serialize the example
danielsn d78a973
Merge branch 'main' into dsn/otel-proto
danielsn dcef39a
simplify tests
danielsn 3e1238c
improve profile.rs tests
danielsn d3e8ff2
assert default expected strings
danielsn 4009cc4
Merge branch 'main' into dsn/otel-proto
danielsn 8cc1624
PR comments
danielsn ec50f57
don't reformat outside file
danielsn df89e53
Merge branch 'main' into dsn/otel-proto
danielsn f5f73ac
Merge branch 'main' into dsn/otel-proto
danielsn 1a3440f
endpoint labels
danielsn 7da33a2
cleaner code for the labelset
danielsn d77157c
split out tests
danielsn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright 2025-Present Datadog, Inc. https://www.datadoghq.com/ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
[package] | ||
name = "datadog-profiling-otel" | ||
rust-version.workspace = true | ||
edition.workspace = true | ||
version.workspace = true | ||
license.workspace = true | ||
|
||
[lib] | ||
bench = false | ||
|
||
[dependencies] | ||
prost = "0.13" | ||
prost-types = "0.13" | ||
zstd = "0.13" | ||
anyhow = "1.0" | ||
|
||
[build-dependencies] | ||
prost-build = "0.13" | ||
protoc-bin-vendored = "3.0.0" | ||
|
||
[dev-dependencies] | ||
bolero = "0.13" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# datadog-profiling-otel | ||
|
||
This module provides Rust bindings for the OpenTelemetry profiling protobuf definitions, generated using the `prost` library. | ||
|
||
## Usage | ||
|
||
### Basic Setup | ||
|
||
Add this to your `Cargo.toml`: | ||
|
||
```toml | ||
[dependencies] | ||
datadog-profiling-otel = "20.0.0" | ||
``` | ||
|
||
### Creating Profile Data | ||
|
||
```rust | ||
use datadog_profiling_otel::*; | ||
|
||
// Create a profiles dictionary | ||
let mut profiles_dict = ProfilesDictionary::default(); | ||
profiles_dict.string_table.push("cpu".to_string()); | ||
profiles_dict.string_table.push("nanoseconds".to_string()); | ||
|
||
// Create a sample type | ||
let sample_type = ValueType { | ||
type_strindex: 0, // "cpu" | ||
unit_strindex: 1, // "nanoseconds" | ||
aggregation_temporality: AggregationTemporality::Delta.into(), | ||
}; | ||
|
||
// Create a profile | ||
let mut profile = Profile::default(); | ||
profile.sample_type = Some(sample_type); | ||
profile.time_nanos = std::time::SystemTime::now() | ||
.duration_since(std::time::UNIX_EPOCH) | ||
.unwrap() | ||
.as_nanos() as i64; | ||
|
||
// Assemble the complete profiles data | ||
let mut profiles_data = ProfilesData::default(); | ||
profiles_data.dictionary = Some(profiles_dict); | ||
|
||
let mut scope_profiles = ScopeProfiles::default(); | ||
scope_profiles.profiles.push(profile); | ||
|
||
let mut resource_profiles = ResourceProfiles::default(); | ||
resource_profiles.scope_profiles.push(scope_profiles); | ||
|
||
profiles_data.resource_profiles.push(resource_profiles); | ||
``` | ||
danielsn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
### Running Examples | ||
|
||
```bash | ||
# Run the basic usage example | ||
cargo run --example basic_usage | ||
|
||
# Run tests | ||
cargo test | ||
|
||
# Build | ||
cargo build | ||
``` | ||
|
||
## Module Structure | ||
|
||
The generated code follows the OpenTelemetry protobuf structure: | ||
|
||
- `ProfilesData`: Top-level container for all profile data | ||
- `ResourceProfiles`: Profiles grouped by resource | ||
- `ScopeProfiles`: Profiles grouped by instrumentation scope | ||
- `Profile`: Individual profile with samples and metadata | ||
- `ProfilesDictionary`: Shared data (strings, mappings, locations, etc.) | ||
- `Sample`: Individual measurements with stack traces | ||
- `Location`: Function locations in the call stack | ||
- `Function`: Function information | ||
- `Mapping`: Binary/library mapping information | ||
|
||
## Dependencies | ||
|
||
- `prost`: Protobuf implementation | ||
- `prost-types`: Additional protobuf types | ||
- `prost-build`: Build-time protobuf compilation | ||
danielsn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## License | ||
|
||
Apache-2.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2025-Present Datadog, Inc. https://www.datadoghq.com/ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::env; | ||
use std::path::PathBuf; | ||
|
||
fn main() { | ||
// protoc is required to compile proto files. This uses protoc-bin-vendored to provide | ||
// the protoc binary, setting the env var to tell prost_build where to find it. | ||
std::env::set_var("PROTOC", protoc_bin_vendored::protoc_bin_path().unwrap()); | ||
|
||
// Tell Cargo to rerun this build script if the proto files change | ||
println!("cargo:rerun-if-changed=profiles.proto"); | ||
println!("cargo:rerun-if-changed=opentelemetry/proto/common/v1/common.proto"); | ||
println!("cargo:rerun-if-changed=opentelemetry/proto/resource/v1/resource.proto"); | ||
|
||
// Create the output directory | ||
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); | ||
|
||
// Configure prost-build | ||
let mut config = prost_build::Config::new(); | ||
config.out_dir(&out_dir); | ||
|
||
// Compile the proto files - include all proto files so imports work correctly | ||
config | ||
.compile_protos( | ||
&[ | ||
"opentelemetry/proto/common/v1/common.proto", | ||
"opentelemetry/proto/resource/v1/resource.proto", | ||
"profiles.proto", | ||
], | ||
&["."], | ||
) | ||
.expect("Failed to compile protobuf files"); | ||
|
||
// Generate the module file with correct structure | ||
let module_content = r#" | ||
// Copyright 2025-Present Datadog, Inc. https://www.datadoghq.com/ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// This module is generated by prost-build from profiles.proto | ||
#[allow(clippy::all)] | ||
pub mod opentelemetry { | ||
pub mod proto { | ||
pub mod common { | ||
pub mod v1 { | ||
include!(concat!(env!("OUT_DIR"), "/opentelemetry.proto.common.v1.rs")); | ||
} | ||
} | ||
pub mod resource { | ||
pub mod v1 { | ||
include!(concat!(env!("OUT_DIR"), "/opentelemetry.proto.resource.v1.rs")); | ||
} | ||
} | ||
pub mod profiles { | ||
pub mod v1development { | ||
include!(concat!(env!("OUT_DIR"), "/opentelemetry.proto.profiles.v1development.rs")); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Re-export commonly used types | ||
pub use opentelemetry::proto::profiles::v1development::*; | ||
pub use opentelemetry::proto::common::v1::*; | ||
pub use opentelemetry::proto::resource::v1::*; | ||
"#; | ||
|
||
std::fs::write(out_dir.join("mod.rs"), module_content).expect("Failed to write module file"); | ||
danielsn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2025-Present Datadog, Inc. https://www.datadoghq.com/ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// This example demonstrates how to use the generated protobuf code | ||
// from the OpenTelemetry profiles.proto file. | ||
|
||
fn main() { | ||
use datadog_profiling_otel::*; | ||
|
||
// Create a simple profile with some basic data | ||
let mut profiles_dict = ProfilesDictionary::default(); | ||
|
||
// Add some strings to the string table | ||
profiles_dict.string_table.push("cpu".to_string()); | ||
profiles_dict.string_table.push("nanoseconds".to_string()); | ||
profiles_dict.string_table.push("main".to_string()); | ||
|
||
// Create a sample type | ||
let sample_type = ValueType { | ||
type_strindex: 0, // "cpu" | ||
unit_strindex: 1, // "nanoseconds" | ||
aggregation_temporality: AggregationTemporality::Delta.into(), | ||
}; | ||
|
||
// Create a profile | ||
let profile = Profile { | ||
sample_type: Some(sample_type), | ||
time_nanos: std::time::SystemTime::now() | ||
.duration_since(std::time::UNIX_EPOCH) | ||
.unwrap() | ||
.as_nanos() as i64, | ||
..Default::default() | ||
}; | ||
|
||
// Create profiles data | ||
danielsn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
let mut profiles_data = ProfilesData { | ||
dictionary: Some(profiles_dict), | ||
..Default::default() | ||
}; | ||
|
||
let mut scope_profiles = ScopeProfiles::default(); | ||
scope_profiles.profiles.push(profile); | ||
|
||
let mut resource_profiles = ResourceProfiles::default(); | ||
resource_profiles.scope_profiles.push(scope_profiles); | ||
|
||
profiles_data.resource_profiles.push(resource_profiles); | ||
|
||
println!("Successfully created OpenTelemetry profile data!"); | ||
println!( | ||
"Profile contains {} resource profiles", | ||
profiles_data.resource_profiles.len() | ||
); | ||
println!( | ||
"Time: {}", | ||
profiles_data.resource_profiles[0].scope_profiles[0].profiles[0].time_nanos | ||
); | ||
danielsn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
40 changes: 40 additions & 0 deletions
40
datadog-profiling-otel/opentelemetry/proto/common/v1/common.proto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2023, OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
syntax = "proto3"; | ||
|
||
package opentelemetry.proto.common.v1; | ||
|
||
// KeyValue is a key-value pair that is used to store Span attributes, Link | ||
// attributes, etc. | ||
message KeyValue { | ||
string key = 1; | ||
oneof value { | ||
string string_value = 2; | ||
bool bool_value = 3; | ||
int64 int_value = 4; | ||
double double_value = 5; | ||
bytes bytes_value = 6; | ||
} | ||
} | ||
|
||
// InstrumentationScope is a message representing the instrumentation scope information | ||
// such as the fully qualified name and version. | ||
message InstrumentationScope { | ||
// An empty instrumentation scope name means the name is unknown. | ||
string name = 1; | ||
string version = 2; | ||
repeated KeyValue attributes = 3; | ||
uint32 dropped_attributes_count = 4; | ||
} |
29 changes: 29 additions & 0 deletions
29
datadog-profiling-otel/opentelemetry/proto/resource/v1/resource.proto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2023, OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
syntax = "proto3"; | ||
|
||
package opentelemetry.proto.resource.v1; | ||
|
||
import "opentelemetry/proto/common/v1/common.proto"; | ||
|
||
// Resource information. | ||
message Resource { | ||
// Set of attributes that describe the resource. | ||
repeated opentelemetry.proto.common.v1.KeyValue attributes = 1; | ||
|
||
// dropped_attributes_count is the number of dropped attributes. If the value is 0, | ||
// then no attributes were dropped. | ||
uint32 dropped_attributes_count = 2; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.