Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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.

1 change: 1 addition & 0 deletions bin_tests/tests/crashtracker_bin_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ fn test_crasht_tracking_validate_callstack() {
test_crash_tracking_callstack()
}

#[cfg(not(any(all(target_arch = "x86_64", target_env = "musl"), target_os = "macos")))]
fn test_crash_tracking_callstack() {
let (_, crashtracker_receiver) = setup_crashtracking_crates(BuildProfile::Release);

Expand Down
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"
23 changes: 23 additions & 0 deletions datadog-profiling-otel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# datadog-profiling-otel

This module provides Rust bindings for the OpenTelemetry profiling protobuf definitions, generated using the `prost` library.
This crate implements serialization of data into the otel profiling format; if you're building a profiler you usually don't want to use this crate directly, and instead should use datadog-profiling and ask it to serialize using ottel.

## Usage

See the [basic_usage.rs](examples/basic_usage.rs) example for a complete demonstration of how to create OpenTelemetry profile data.

### Running Examples

```bash
# Run the basic usage example
cargo run --example basic_usage

# Run tests
cargo test

# Build
cargo build
```


35 changes: 35 additions & 0 deletions datadog-profiling-otel/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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");
}
55 changes: 55 additions & 0 deletions datadog-profiling-otel/examples/basic_usage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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::*;

let mut profiles_dict = ProfilesDictionary::default();

profiles_dict.string_table.push("cpu".to_string());
profiles_dict.string_table.push("nanoseconds".to_string());
profiles_dict.string_table.push("main".to_string());

let sample_type = ValueType {
type_strindex: 0, // "cpu"
unit_strindex: 1, // "nanoseconds"
aggregation_temporality: AggregationTemporality::Delta.into(),
};

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()
};

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
);
let serialized = profiles_data.serialize_into_compressed_proto().unwrap();
println!("Serialized size: {} bytes", serialized.len());
}
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