Skip to content

Commit 3495804

Browse files
authored
Merge branch 'main' into igor/versioning/fix_doc_warnings
2 parents 041d2a5 + 660c550 commit 3495804

31 files changed

+2716
-314
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
.gitignore @Datadog/libdatadog
1212
.gitlab-ci.yml @Datadog/apm-common-components-core
1313
.gitlab/benchmarks.yml @Datadog/apm-common-components-core
14+
.gitlab/fuzz.yml @Datadog/chaos-platform
1415
benchmark/ @Datadog/apm-common-components-core
1516
bin_tests/ @Datadog/libdatadog-profiling
1617
build-common/ @Datadog/apm-common-components-core
@@ -64,6 +65,7 @@ tests/spawn_from_lib/ @Datadog/libdatadog-php @Datadog/libdatadog
6465
tests/windows_package/ @Datadog/apm-common-components-core
6566
tools/ @Datadog/apm-common-components-core
6667
windows/ @Datadog/libdatadog-core
68+
fuzz/ @Datadog/chaos-platform
6769

6870
# Specific overrides (must come after their general patterns above)
6971
bin_tests/tests/test_the_tests.rs @Datadog/libdatadog-core

.github/workflows/test.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,22 +234,35 @@ jobs:
234234
cmake -S .. -DDatadog_ROOT=$LIBDD_OUTPUT_FOLDER
235235
cmake --build .
236236
fi
237-
- name: "Test building CXX bindings (Unix)"
237+
- name: "Test building CXX bindings - Crashinfo (Unix)"
238238
shell: bash
239239
if: matrix.platform != 'windows-latest'
240240
run: |
241241
set -e
242242
cd examples/cxx
243243
./build-and-run-crashinfo.sh
244+
- name: "Test building CXX bindings - Profiling (Unix)"
245+
shell: bash
246+
if: matrix.platform != 'windows-latest'
247+
run: |
248+
set -e
249+
cd examples/cxx
250+
./build-profiling.sh
244251
- name: "Setup MSVC (Windows)"
245252
if: matrix.platform == 'windows-latest'
246253
uses: ilammy/msvc-dev-cmd@v1
247-
- name: "Test building CXX bindings (Windows)"
254+
- name: "Test building CXX bindings - Crashinfo (Windows)"
248255
shell: pwsh
249256
if: matrix.platform == 'windows-latest'
250257
run: |
251258
cd examples/cxx
252259
.\build-and-run-crashinfo.ps1
260+
- name: "Test building CXX bindings - Profiling (Windows)"
261+
shell: pwsh
262+
if: matrix.platform == 'windows-latest'
263+
run: |
264+
cd examples/cxx
265+
.\build-profiling.ps1
253266
254267
cross-centos7:
255268
name: build and test using cross - on centos7

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ build/
1111
cmake-build-debug
1212
deliverables
1313
docker-linux-target
14+
release
1415
target
1516
tmp
1617
__fuzz__
@@ -25,3 +26,7 @@ docker-sync.yml
2526
libtest.so
2627
libtest_cpp.so
2728
examples/cxx/crashinfo
29+
examples/cxx/crashinfo.exe
30+
examples/cxx/profiling
31+
examples/cxx/profiling.exe
32+
profile.pprof

.gitlab-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ variables:
77

88
include:
99
- local: .gitlab/benchmarks.yml
10+
- local: .gitlab/fuzz.yml
1011

1112
trigger_internal_build:
1213
variables:

.gitlab/fuzz.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Fuzzing job configuration
2+
# This job discovers, builds, and uploads all cargo-fuzz targets to the internal fuzzing infrastructure
3+
# See ci/README_FUZZING.md for more information
4+
5+
variables:
6+
BASE_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:libdatadog-benchmarks
7+
8+
fuzz:
9+
tags: ["arch:amd64"]
10+
needs: []
11+
image:
12+
name: $BASE_CI_IMAGE
13+
rules:
14+
# runs on gitlab schedule and on merge to main.
15+
# Also allow manual run in branches for ease of debug / testing
16+
- if: '$CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "schedule"'
17+
allow_failure: true
18+
- if: $CI_COMMIT_BRANCH == "main"
19+
allow_failure: true
20+
- when: manual
21+
allow_failure: true
22+
timeout: 1h
23+
script:
24+
- VAULT_VERSION=1.15.4 && curl -fsSL "https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_linux_amd64.zip" -o vault.zip && unzip vault.zip && mv vault /usr/local/bin/vault && rm vault.zip && chmod +x /usr/local/bin/vault
25+
- rustup default nightly
26+
- cargo install cargo-fuzz
27+
- pip3 install requests toml
28+
- python3 fuzz/fuzz_infra.py
29+
allow_failure: true
30+
variables:
31+
KUBERNETES_SERVICE_ACCOUNT_OVERWRITE: libdatadog

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/cxx/README.md

Lines changed: 84 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
1-
# CXX Bindings Example for libdd-crashtracker
1+
# CXX Bindings Examples
22

3-
This example demonstrates how to use the CXX bindings for the libdd-crashtracker crate, providing a safer and more idiomatic C++ API compared to the traditional C FFI.
3+
This directory contains C++ examples demonstrating the CXX bindings for libdatadog components.
44

5-
## Features
5+
CXX bindings provide a safer and more idiomatic C++ API compared to the traditional C FFI bindings, with automatic memory management and exception handling.
66

7-
The CXX bindings provide access to:
7+
## Examples
88

9-
### Core Types
9+
### Crashtracker (`crashinfo.cpp`)
10+
11+
Demonstrates building crash reports using the CXX bindings for `libdd-crashtracker`.
12+
13+
**Build and run:**
14+
15+
Unix (Linux/macOS):
16+
```bash
17+
./build-and-run-crashinfo.sh
18+
```
19+
20+
Windows:
21+
```powershell
22+
.\build-and-run-crashinfo.ps1
23+
```
24+
25+
**Key features:**
26+
- Type-safe crash report builder API
27+
- Support for stack traces, frames, and metadata
28+
- Process and OS information
29+
- Automatic memory management
30+
- Exception-based error handling
31+
32+
**Core Types:**
1033
- `CrashInfoBuilder` - Builder for constructing crash information
1134
- `StackFrame` - Individual stack frame with debug info and addresses
1235
- `StackTrace` - Collection of stack frames
@@ -15,115 +38,85 @@ The CXX bindings provide access to:
1538
- `ProcInfo` - Process information
1639
- `OsInfo` - Operating system information
1740

18-
### Enums
19-
- `ErrorKind` - Type of error (Panic, UnhandledException, UnixSignal)
20-
- `BuildIdType` - Build ID format (GNU, GO, PDB, SHA1)
21-
- `FileType` - Binary file format (APK, ELF, PE)
41+
**Enums:**
42+
- `CxxErrorKind` - Type of error (Panic, UnhandledException, UnixSignal)
43+
- `CxxBuildIdType` - Build ID format (GNU, GO, PDB, SHA1)
44+
- `CxxFileType` - Binary file format (APK, ELF, PE)
2245

23-
### Key API
46+
### Profiling (`profiling.cpp`)
2447

25-
**Object Creation:**
26-
```cpp
27-
auto builder = CrashInfoBuilder::create();
28-
auto frame = StackFrame::create();
29-
auto stacktrace = StackTrace::create();
30-
```
48+
Demonstrates building profiling data and exporting to Datadog using the CXX bindings for `libdd-profiling`.
3149

32-
**CrashInfoBuilder Methods:**
33-
- `set_kind(CxxErrorKind)` - Set error type (Panic, UnhandledException, UnixSignal)
34-
- `with_message(String)` - Set error message
35-
- `with_counter(String, i64)` - Add a named counter
36-
- `with_log_message(String, bool)` - Add a log message
37-
- `with_fingerprint(String)` - Set crash fingerprint
38-
- `with_incomplete(bool)` - Mark as incomplete
39-
- `set_metadata(Metadata)` - Set library metadata
40-
- `set_proc_info(ProcInfo)` - Set process information
41-
- `set_os_info(OsInfo)` - Set OS information
42-
- `add_stack(Box<StackTrace>)` - Add a stack trace
43-
- `with_timestamp_now()` - Set current timestamp
44-
- `with_file(String)` - Add a file to the report
45-
46-
**StackFrame Methods:**
47-
- `with_function(String)`, `with_file(String)`, `with_line(u32)`, `with_column(u32)` - Set debug info
48-
- `with_ip(usize)`, `with_sp(usize)` - Set instruction/stack pointers
49-
- `with_module_base_address(usize)`, `with_symbol_address(usize)` - Set base addresses
50-
- `with_build_id(String)` - Set build ID
51-
- `build_id_type(CxxBuildIdType)` - Set build ID format (GNU, GO, PDB, SHA1)
52-
- `file_type(CxxFileType)` - Set binary format (APK, ELF, PE)
53-
- `with_path(String)` - Set module path
54-
- `with_relative_address(usize)` - Set relative address
55-
56-
**StackTrace Methods:**
57-
- `add_frame(Box<StackFrame>, bool)` - Add a frame (bool = incomplete)
58-
- `mark_complete()` - Mark trace as complete
59-
60-
**Building & Output:**
61-
```cpp
62-
auto crash_info = crashinfo_build(std::move(builder));
63-
auto json = crash_info->to_json();
64-
```
65-
66-
## Building and Running
67-
68-
### Unix (Linux/macOS)
69-
70-
The `build-and-run-crashinfo.sh` script handles the entire build process:
50+
**Build and run:**
7151

52+
Unix (Linux/macOS):
7253
```bash
73-
./examples/cxx/build-and-run-crashinfo.sh
54+
./build-profiling.sh
7455
```
7556

76-
### Windows
77-
78-
The `build-and-run-crashinfo.ps1` PowerShell script handles the build process on Windows:
79-
57+
Windows:
8058
```powershell
81-
.\examples\cxx\build-and-run-crashinfo.ps1
59+
.\build-profiling.ps1
8260
```
8361

84-
**Prerequisites for Windows:**
85-
- Either MSVC (via Visual Studio) or MinGW/LLVM with C++ compiler
86-
- PowerShell 5.0 or later (comes with Windows 10+)
87-
- Rust toolchain
62+
**Key features:**
63+
- Type-safe API for building profiles
64+
- Support for samples, locations, mappings, and labels
65+
- String interning for efficient memory usage
66+
- Upscaling rules (Poisson and Proportional)
67+
- Endpoint tracking for web service profiling
68+
- Pprof format serialization with zstd compression
69+
- **Export to Datadog** via agent or agentless mode
70+
- Support for attaching additional compressed files
71+
- Per-profile tags and metadata
72+
- Automatic memory management
73+
- Exception-based error handling
74+
- Modern C++20 syntax with designated initializers and `std::format`
8875

89-
The build script will:
90-
1. Build libdd-crashtracker with the `cxx` feature enabled
91-
2. Find the CXX bridge headers and libraries
92-
3. Compile the C++ example (automatically detects MSVC or MinGW/Clang)
93-
4. Run the example and display the output
76+
**Core Types:**
77+
- `Profile` - Profile builder for collecting samples
78+
- `ProfileExporter` - Exporter for sending profiles to Datadog
79+
- `Tag` - Key-value tags for profile metadata
80+
- `AttachmentFile` - Additional file to attach to profile (name + data bytes)
9481

95-
## Example Output
82+
**Export Modes:**
9683

97-
The example creates a crash report with:
98-
- Error kind and message
99-
- Library metadata with tags
100-
- Process and OS information
101-
- A stack trace with multiple frames (debug info + binary addresses)
102-
- Counters and log messages
103-
- Timestamp
84+
By default, the example saves the profile to `profile.pprof`. To export to Datadog, set environment variables:
85+
86+
1. **Agent mode**: Sends profiles to the local Datadog agent
87+
```bash
88+
DD_AGENT_URL=http://localhost:8126 ./build-profiling.sh
89+
```
90+
91+
2. **Agentless mode**: Sends profiles directly to Datadog intake
92+
```bash
93+
DD_API_KEY=your-api-key DD_SITE=datadoghq.com ./build-profiling.sh
94+
```
95+
96+
**API Example:**
10497

105-
The output is a JSON object that can be sent to Datadog's crash tracking service.
98+
See [`profiling.cpp`](profiling.cpp) for a complete example showing profile creation, sample collection, and exporting to Datadog with optional attachments and metadata.
10699

107-
## Notes
100+
**Requirements:**
101+
- C++20 compiler
102+
- For agent mode: Datadog agent running (default: localhost:8126)
103+
- For agentless mode: Valid Datadog API key
108104

109-
- The CXX bindings use `rust::String` types which need to be converted to `std::string` for use with standard C++ streams
110-
- All functions that can fail will use exceptions (standard C++ exception handling)
111-
- The bindings are type-safe and prevent many common C FFI errors
112-
- Memory is managed automatically through RAII and smart pointers
105+
## Build Scripts
113106

114-
## Comparison to C FFI
107+
The examples use a consolidated build system:
115108

116-
The CXX bindings provide several advantages over the traditional C FFI:
109+
- **Unix (Linux/macOS)**: `build-and-run.sh <crate-name> <example-name>`
110+
- **Windows**: `build-and-run.ps1 -CrateName <crate-name> -ExampleName <example-name>`
117111

118-
1. **Type Safety**: No void pointers, proper type checking at compile time
119-
2. **Memory Safety**: Automatic memory management through smart pointers
120-
3. **Ergonomics**: More natural C++ idioms, no need for manual handle management
121-
4. **Error Handling**: Exceptions instead of error codes
122-
5. **String Handling**: Seamless `rust::String` ↔ C++ string interop
112+
Convenience wrappers are provided for each example:
113+
- `build-and-run-crashinfo.sh` / `build-and-run-crashinfo.ps1`
114+
- `build-profiling.sh` / `build-profiling.ps1`
123115

124116
## Requirements
125117

126118
- C++20 or later
127119
- Rust toolchain
120+
- C++ compiler (clang++ or g++)
128121
- Platform: macOS, Linux, or Windows
129122
- Windows: Requires MSVC (via Visual Studio) or MinGW/LLVM

0 commit comments

Comments
 (0)