Skip to content
Draft
Show file tree
Hide file tree
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 Aug 11, 2025
ab97024
vendor protoc
danielsn Aug 14, 2025
93b17ae
serialize
danielsn Aug 14, 2025
c610684
dockerfile
danielsn Aug 14, 2025
234c466
emit otel
danielsn Aug 14, 2025
ae123cd
Merge branch 'main' into dsn/otel-proto
danielsn Aug 14, 2025
b08a0df
miri ignore
danielsn Aug 14, 2025
e4c8724
don't checkout that file
danielsn Aug 14, 2025
8f69381
more miri ignore
danielsn Aug 14, 2025
7a0dca2
Merge branch 'main' into dsn/otel-proto
danielsn Sep 10, 2025
4edfdef
PR Comment: Move prelude to file
danielsn Sep 10, 2025
5c1b2af
simplify tests
danielsn Sep 10, 2025
29f6c67
simplify the tests a bit more
danielsn Sep 10, 2025
4004cb5
remove unneeded comments
danielsn Sep 10, 2025
f3682ee
PR comment: don't rename types
danielsn Sep 10, 2025
b63529e
cleanup tests
danielsn Sep 10, 2025
819f571
serialize the example
danielsn Sep 10, 2025
d78a973
Merge branch 'main' into dsn/otel-proto
danielsn Sep 11, 2025
dcef39a
simplify tests
danielsn Sep 11, 2025
3e1238c
improve profile.rs tests
danielsn Sep 11, 2025
d3e8ff2
assert default expected strings
danielsn Sep 11, 2025
4009cc4
Merge branch 'main' into dsn/otel-proto
danielsn Sep 11, 2025
8cc1624
PR comments
danielsn Sep 11, 2025
ec50f57
don't reformat outside file
danielsn Sep 11, 2025
df89e53
Merge branch 'main' into dsn/otel-proto
danielsn Sep 12, 2025
f5f73ac
Merge branch 'main' into dsn/otel-proto
danielsn Sep 15, 2025
1a3440f
endpoint labels
danielsn Sep 15, 2025
7da33a2
cleaner code for the labelset
danielsn Sep 15, 2025
d77157c
split out tests
danielsn Sep 16, 2025
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
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ members = [
"datadog-live-debugger-ffi",
"datadog-profiling",
"datadog-profiling-ffi",
"datadog-profiling-otel",
"datadog-profiling-protobuf",
"datadog-profiling-replayer",
"datadog-remote-config",
Expand Down
9 changes: 8 additions & 1 deletion LICENSE-3rdparty.yml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion datadog-profiling-ffi/src/profiles/datatypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,8 @@ pub unsafe extern "C" fn ddog_prof_Profile_serialize(
}

let end_time = end_time.map(SystemTime::from);
old_profile.serialize_into_compressed_pprof(end_time, None)
// TODO: make this an option instead of hardcoding to otel
old_profile.serialize_into_compressed_otel(end_time, None)
})()
.context("ddog_prof_Profile_serialize failed")
.into()
Expand Down
25 changes: 25 additions & 0 deletions datadog-profiling-otel/Cargo.toml
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"
89 changes: 89 additions & 0 deletions datadog-profiling-otel/README.md
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);
```

### 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

## License

Apache-2.0
70 changes: 70 additions & 0 deletions datadog-profiling-otel/build.rs
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");
}
58 changes: 58 additions & 0 deletions datadog-profiling-otel/examples/basic_usage.rs
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
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
);
}
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;
}
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;
}
Loading
Loading