Skip to content

Add fork safety hooks and cancellation token for trace exporter FFI#2051

Open
lloeki wants to merge 2 commits into
mainfrom
lloeki/ffi-for-trace-exporter-fork-safety
Open

Add fork safety hooks and cancellation token for trace exporter FFI#2051
lloeki wants to merge 2 commits into
mainfrom
lloeki/ffi-for-trace-exporter-fork-safety

Conversation

@lloeki
Copy link
Copy Markdown
Member

@lloeki lloeki commented May 28, 2026

What does this PR do?

Add fork safety and cooperative cancellation support to the trace exporter FFI:

  1. Fork hooks: Expose ddog_trace_exporter_before_fork, _after_fork_in_parent,
    and _after_fork_in_child that delegate to the underlying SharedRuntime. These
    allow C callers to coordinate the tokio runtime lifecycle around process forks.

  2. Cancellation token: Introduce ddog_trace_exporter_cancel_token_new, _cancel,
    and _drop for managing cancellation tokens. Thread the token into
    ddog_trace_exporter_send_trace_chunks via tokio::select! so callers can
    cooperatively abort in-flight HTTP requests.

Motivation

FUP to #1952.

Ruby application servers (Puma, Unicorn, Passenger) fork worker processes. The tokio
runtime does not survive fork() — its threads are not carried over. Without the fork
hooks, the trace exporter is dead in child processes.

The existing RUBY_UBF_IO unblock function on the dd-trace-rb side sends a signal
that cannot actually cancel an in-flight Rust HTTP request. The cancellation token
enables cooperative abort: when Ruby interrupts a thread (shutdown, Thread#kill),
the UBF cancels the token, which causes tokio::select! to abort the send and return
promptly.

Additional Notes

  • Added a pub fn shared_runtime() accessor to TraceExporter since the field was private.
  • The cancellation token uses Handle<CancellationToken> from libdd-common-ffi, same
    pattern as profiling-ffi, with a ddog_TraceExporterCancelToken cbindgen rename to
    avoid symbol conflicts.
  • The cancel parameter on send_trace_chunks is nullable; passing NULL preserves
    existing behavior.

AI was used to accelerate implementation; all code was reviewed and understood.

How to test the change?

cargo test -p libdd-data-pipeline-ffi --lib

46 tests pass (40 existing + 6 new for fork hooks and cancellation token).

@datadog-official
Copy link
Copy Markdown

datadog-official Bot commented May 28, 2026

Pipelines  Tests

Fix all issues with BitsAI

⚠️ Warnings

🚦 5 Pipeline jobs failed

Lint | rustfmt   View in Datadog   GitHub Actions

🔧 Fix in code (Fix with Cursor). Compilation error: unexpected indent found in tracer.rs:319:1.

Required checks pass | allchecks   View in Datadog   GitHub Actions

🔄 Retry job. This looks flaky and may succeed on retry. Some checks have failed or timed out. Review the workflow run summary for details.

Test FFI | FFI alpine-build via docker bake   View in Datadog   GitHub Actions

🛟 This job is unlikely to succeed on retry. Please review your pipeline configuration. Cargo.lock needs updating. Remove the --locked flag to update it and allow network access during cargo fetch.

View all 5 failed jobs.

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 34.88%
Overall Coverage: 72.87% (-0.05%)

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: c5c339a | Docs | Datadog PR Page | Give us feedback!

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 28, 2026

📚 Documentation Check Results

⚠️ 2227 documentation warning(s) found

📦 libdd-data-pipeline-ffi - 1169 warning(s)

📦 libdd-data-pipeline - 1058 warning(s)


Updated: 2026-05-29 11:44:46 UTC | Commit: 5e16401 | missing-docs job results

@github-actions
Copy link
Copy Markdown
Contributor

Clippy Allow Annotation Report

Comparing clippy allow annotations between branches:

  • Base Branch: origin/main
  • PR Branch: origin/lloeki/ffi-for-trace-exporter-fork-safety

Summary by Rule

Rule Base Branch PR Branch Change
unwrap_used 2 2 No change (0%)
Total 2 2 No change (0%)

Annotation Counts by File

File Base Branch PR Branch Change
libdd-data-pipeline/src/trace_exporter/mod.rs 2 2 No change (0%)

Annotation Stats by Crate

Crate Base Branch PR Branch Change
clippy-annotation-reporter 5 5 No change (0%)
datadog-ffe-ffi 1 1 No change (0%)
datadog-ipc 21 21 No change (0%)
datadog-live-debugger 6 6 No change (0%)
datadog-live-debugger-ffi 10 10 No change (0%)
datadog-profiling-replayer 4 4 No change (0%)
datadog-remote-config 3 3 No change (0%)
datadog-sidecar 57 57 No change (0%)
libdd-common 13 13 No change (0%)
libdd-common-ffi 12 12 No change (0%)
libdd-data-pipeline 5 5 No change (0%)
libdd-ddsketch 2 2 No change (0%)
libdd-dogstatsd-client 1 1 No change (0%)
libdd-profiling 13 13 No change (0%)
libdd-telemetry 20 20 No change (0%)
libdd-tinybytes 4 4 No change (0%)
libdd-trace-normalization 2 2 No change (0%)
libdd-trace-obfuscation 3 3 No change (0%)
libdd-trace-stats 1 1 No change (0%)
libdd-trace-utils 13 13 No change (0%)
Total 196 196 No change (0%)

About This Report

This report tracks Clippy allow annotations for specific rules, showing how they've changed in this PR. Decreasing the number of these annotations generally improves code quality.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 28, 2026

🔒 Cargo Deny Results

⚠️ 10 issue(s) found, showing only errors (advisories, bans, sources)

📦 libdd-data-pipeline-ffi - 5 error(s)

Show output
error[unsound]: Rand is unsound with a custom logger using `rand::rng()`
    ┌─ /home/runner/work/libdatadog/libdatadog/Cargo.lock:222:1
    │
222 │ rand 0.8.5 registry+https://github.com/rust-lang/crates.io-index
    │ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ unsound advisory detected
    │
    ├ ID: RUSTSEC-2026-0097
    ├ Advisory: https://rustsec.org/advisories/RUSTSEC-2026-0097
    ├ It has been reported (by @lopopolo) that the `rand` library is [unsound](https://rust-lang.github.io/unsafe-code-guidelines/glossary.html#soundness-of-code--of-a-library) (i.e. that safe code using the public API can cause Undefined Behaviour) when all the following conditions are met:
      
      - The `log` and `thread_rng` features are enabled
      - A [custom logger](https://docs.rs/log/latest/log/#implementing-a-logger) is defined
      - The custom logger accesses `rand::rng()` (previously `rand::thread_rng()`) and calls any `TryRng` (previously `RngCore`) methods on `ThreadRng`
      - The `ThreadRng` (attempts to) reseed while called from the custom logger (this happens every 64 kB of generated data)
      - Trace-level logging is enabled or warn-level logging is enabled and the random source (the `getrandom` crate) is unable to provide a new seed
      
      `TryRng` (previously `RngCore`) methods for `ThreadRng` use `unsafe` code to cast `*mut BlockRng<ReseedingCore>` to `&mut BlockRng<ReseedingCore>`. When all the above conditions are met this results in an aliased mutable reference, violating the Stacked Borrows rules. Miri is able to detect this violation in sample code. Since construction of [aliased mutable references is Undefined Behaviour](https://doc.rust-lang.org/stable/nomicon/references.html), the behaviour of optimized builds is hard to predict.
    ├ Announcement: https://github.com/rust-random/rand/pull/1763
    ├ Solution: Upgrade to >=0.10.1 OR <0.10.0, >=0.9.3 OR <0.9.0, >=0.8.6 (try `cargo update -p rand`)
    ├ rand v0.8.5
      ├── libdd-common v4.1.0
      │   ├── libdd-capabilities-impl v2.0.0
      │   │   ├── libdd-data-pipeline v5.0.0
      │   │   │   └── libdd-data-pipeline-ffi v34.0.0
      │   │   ├── libdd-data-pipeline-ffi v34.0.0 (*)
      │   │   ├── libdd-shared-runtime v1.0.0
      │   │   │   ├── libdd-data-pipeline v5.0.0 (*)
      │   │   │   ├── libdd-data-pipeline-ffi v34.0.0 (*)
      │   │   │   ├── libdd-telemetry v5.0.0
      │   │   │   │   └── libdd-data-pipeline v5.0.0 (*)
      │   │   │   └── libdd-trace-stats v4.0.0
      │   │   │       └── libdd-data-pipeline v5.0.0 (*)
      │   │   ├── libdd-trace-stats v4.0.0 (*)
      │   │   └── libdd-trace-utils v5.0.0
      │   │       ├── libdd-data-pipeline v5.0.0 (*)
      │   │       ├── (dev) libdd-data-pipeline-ffi v34.0.0 (*)
      │   │       ├── libdd-trace-obfuscation v3.1.0
      │   │       │   └── libdd-trace-stats v4.0.0 (*)
      │   │       ├── libdd-trace-stats v4.0.0 (*)
      │   │       └── (dev) libdd-trace-utils v5.0.0 (*)
      │   ├── libdd-common-ffi v34.0.0
      │   │   └── libdd-data-pipeline-ffi v34.0.0 (*)
      │   ├── libdd-data-pipeline v5.0.0 (*)
      │   ├── libdd-dogstatsd-client v3.0.0
      │   │   └── libdd-data-pipeline v5.0.0 (*)
      │   ├── libdd-shared-runtime v1.0.0 (*)
      │   ├── libdd-telemetry v5.0.0 (*)
      │   ├── libdd-trace-obfuscation v3.1.0 (*)
      │   ├── libdd-trace-stats v4.0.0 (*)
      │   └── libdd-trace-utils v5.0.0 (*)
      ├── (dev) libdd-data-pipeline v5.0.0 (*)
      ├── (dev) libdd-trace-normalization v2.0.0
      │   └── libdd-trace-utils v5.0.0 (*)
      ├── (dev) libdd-trace-stats v4.0.0 (*)
      ├── libdd-trace-utils v5.0.0 (*)
      └── proptest v1.5.0
          └── (dev) libdd-tinybytes v1.1.1
              ├── libdd-data-pipeline v5.0.0 (*)
              ├── libdd-data-pipeline-ffi v34.0.0 (*)
              ├── (dev) libdd-tinybytes v1.1.1 (*)
              └── libdd-trace-utils v5.0.0 (*)

error[vulnerability]: Name constraints for URI names were incorrectly accepted
    ┌─ /home/runner/work/libdatadog/libdatadog/Cargo.lock:246:1
    │
246 │ rustls-webpki 0.103.10 registry+https://github.com/rust-lang/crates.io-index
    │ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ security vulnerability detected
    │
    ├ ID: RUSTSEC-2026-0098
    ├ Advisory: https://rustsec.org/advisories/RUSTSEC-2026-0098
    ├ Name constraints for URI names were ignored and therefore accepted.
      
      Note this library does not provide an API for asserting URI names, and URI name constraints are otherwise not implemented.  URI name constraints are now rejected unconditionally.
      
      Since name constraints are restrictions on otherwise properly-issued certificates, this bug is reachable only after signature verification and requires misissuance to exploit.
      
      This vulnerability is identified as [GHSA-965h-392x-2mh5](https://github.com/rustls/webpki/security/advisories/GHSA-965h-392x-2mh5). Thank you to @1seal for the report.
    ├ Solution: Upgrade to >=0.103.12, <0.104.0-alpha.1 OR >=0.104.0-alpha.6 (try `cargo update -p rustls-webpki`)
    ├ rustls-webpki v0.103.10
      └── rustls v0.23.37
          ├── hyper-rustls v0.27.7
          │   └── libdd-common v4.1.0
          │       ├── libdd-capabilities-impl v2.0.0
          │       │   ├── libdd-data-pipeline v5.0.0
          │       │   │   └── libdd-data-pipeline-ffi v34.0.0
          │       │   ├── libdd-data-pipeline-ffi v34.0.0 (*)
          │       │   ├── libdd-shared-runtime v1.0.0
          │       │   │   ├── libdd-data-pipeline v5.0.0 (*)
          │       │   │   ├── libdd-data-pipeline-ffi v34.0.0 (*)
          │       │   │   ├── libdd-telemetry v5.0.0
          │       │   │   │   └── libdd-data-pipeline v5.0.0 (*)
          │       │   │   └── libdd-trace-stats v4.0.0
          │       │   │       └── libdd-data-pipeline v5.0.0 (*)
          │       │   ├── libdd-trace-stats v4.0.0 (*)
          │       │   └── libdd-trace-utils v5.0.0
          │       │       ├── libdd-data-pipeline v5.0.0 (*)
          │       │       ├── (dev) libdd-data-pipeline-ffi v34.0.0 (*)
          │       │       ├── libdd-trace-obfuscation v3.1.0
          │       │       │   └── libdd-trace-stats v4.0.0 (*)
          │       │       ├── libdd-trace-stats v4.0.0 (*)
          │       │       └── (dev) libdd-trace-utils v5.0.0 (*)
          │       ├── libdd-common-ffi v34.0.0
          │       │   └── libdd-data-pipeline-ffi v34.0.0 (*)
          │       ├── libdd-data-pipeline v5.0.0 (*)
          │       ├── libdd-dogstatsd-client v3.0.0
          │       │   └── libdd-data-pipeline v5.0.0 (*)
          │       ├── libdd-shared-runtime v1.0.0 (*)
          │       ├── libdd-telemetry v5.0.0 (*)
          │       ├── libdd-trace-obfuscation v3.1.0 (*)
          │       ├── libdd-trace-stats v4.0.0 (*)
          │       └── libdd-trace-utils v5.0.0 (*)
          ├── libdd-common v4.1.0 (*)
          └── tokio-rustls v0.26.0
              ├── hyper-rustls v0.27.7 (*)
              └── libdd-common v4.1.0 (*)

error[vulnerability]: Name constraints were accepted for certificates asserting a wildcard name
    ┌─ /home/runner/work/libdatadog/libdatadog/Cargo.lock:246:1
    │
246 │ rustls-webpki 0.103.10 registry+https://github.com/rust-lang/crates.io-index
    │ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ security vulnerability detected
    │
    ├ ID: RUSTSEC-2026-0099
    ├ Advisory: https://rustsec.org/advisories/RUSTSEC-2026-0099
    ├ Permitted subtree name constraints for DNS names were accepted for certificates asserting a wildcard name.
      
      This was incorrect because, given a name constraint of `accept.example.com`, `*.example.com` could feasibly allow a name of `reject.example.com` which is outside the constraint.
      This is very similar to [CVE-2025-61727](https://go.dev/issue/76442).
      
      Since name constraints are restrictions on otherwise properly-issued certificates, this bug is reachable only after signature verification and requires misissuance to exploit.
      
      This vulnerability is identified as [GHSA-xgp8-3hg3-c2mh](https://github.com/rustls/webpki/security/advisories/GHSA-xgp8-3hg3-c2mh). Thank you to @1seal for the report.
    ├ Solution: Upgrade to >=0.103.12, <0.104.0-alpha.1 OR >=0.104.0-alpha.6 (try `cargo update -p rustls-webpki`)
    ├ rustls-webpki v0.103.10
      └── rustls v0.23.37
          ├── hyper-rustls v0.27.7
          │   └── libdd-common v4.1.0
          │       ├── libdd-capabilities-impl v2.0.0
          │       │   ├── libdd-data-pipeline v5.0.0
          │       │   │   └── libdd-data-pipeline-ffi v34.0.0
          │       │   ├── libdd-data-pipeline-ffi v34.0.0 (*)
          │       │   ├── libdd-shared-runtime v1.0.0
          │       │   │   ├── libdd-data-pipeline v5.0.0 (*)
          │       │   │   ├── libdd-data-pipeline-ffi v34.0.0 (*)
          │       │   │   ├── libdd-telemetry v5.0.0
          │       │   │   │   └── libdd-data-pipeline v5.0.0 (*)
          │       │   │   └── libdd-trace-stats v4.0.0
          │       │   │       └── libdd-data-pipeline v5.0.0 (*)
          │       │   ├── libdd-trace-stats v4.0.0 (*)
          │       │   └── libdd-trace-utils v5.0.0
          │       │       ├── libdd-data-pipeline v5.0.0 (*)
          │       │       ├── (dev) libdd-data-pipeline-ffi v34.0.0 (*)
          │       │       ├── libdd-trace-obfuscation v3.1.0
          │       │       │   └── libdd-trace-stats v4.0.0 (*)
          │       │       ├── libdd-trace-stats v4.0.0 (*)
          │       │       └── (dev) libdd-trace-utils v5.0.0 (*)
          │       ├── libdd-common-ffi v34.0.0
          │       │   └── libdd-data-pipeline-ffi v34.0.0 (*)
          │       ├── libdd-data-pipeline v5.0.0 (*)
          │       ├── libdd-dogstatsd-client v3.0.0
          │       │   └── libdd-data-pipeline v5.0.0 (*)
          │       ├── libdd-shared-runtime v1.0.0 (*)
          │       ├── libdd-telemetry v5.0.0 (*)
          │       ├── libdd-trace-obfuscation v3.1.0 (*)
          │       ├── libdd-trace-stats v4.0.0 (*)
          │       └── libdd-trace-utils v5.0.0 (*)
          ├── libdd-common v4.1.0 (*)
          └── tokio-rustls v0.26.0
              ├── hyper-rustls v0.27.7 (*)
              └── libdd-common v4.1.0 (*)

error[vulnerability]: Reachable panic in certificate revocation list parsing
    ┌─ /home/runner/work/libdatadog/libdatadog/Cargo.lock:246:1
    │
246 │ rustls-webpki 0.103.10 registry+https://github.com/rust-lang/crates.io-index
    │ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ security vulnerability detected
    │
    ├ ID: RUSTSEC-2026-0104
    ├ Advisory: https://rustsec.org/advisories/RUSTSEC-2026-0104
    ├ A panic was reachable when parsing certificate revocation lists via [`BorrowedCertRevocationList::from_der`]
      or [`OwnedCertRevocationList::from_der`].  This was the result of mishandling a syntactically valid empty
      `BIT STRING` appearing in the `onlySomeReasons` element of a `IssuingDistributionPoint` CRL extension.
      
      This panic is reachable prior to a CRL's signature being verified.
      
      Applications that do not use CRLs are not affected.
      
      Thank you to @tynus3 for the report.
    ├ Solution: Upgrade to >=0.103.13, <0.104.0-alpha.1 OR >=0.104.0-alpha.7 (try `cargo update -p rustls-webpki`)
    ├ rustls-webpki v0.103.10
      └── rustls v0.23.37
          ├── hyper-rustls v0.27.7
          │   └── libdd-common v4.1.0
          │       ├── libdd-capabilities-impl v2.0.0
          │       │   ├── libdd-data-pipeline v5.0.0
          │       │   │   └── libdd-data-pipeline-ffi v34.0.0
          │       │   ├── libdd-data-pipeline-ffi v34.0.0 (*)
          │       │   ├── libdd-shared-runtime v1.0.0
          │       │   │   ├── libdd-data-pipeline v5.0.0 (*)
          │       │   │   ├── libdd-data-pipeline-ffi v34.0.0 (*)
          │       │   │   ├── libdd-telemetry v5.0.0
          │       │   │   │   └── libdd-data-pipeline v5.0.0 (*)
          │       │   │   └── libdd-trace-stats v4.0.0
          │       │   │       └── libdd-data-pipeline v5.0.0 (*)
          │       │   ├── libdd-trace-stats v4.0.0 (*)
          │       │   └── libdd-trace-utils v5.0.0
          │       │       ├── libdd-data-pipeline v5.0.0 (*)
          │       │       ├── (dev) libdd-data-pipeline-ffi v34.0.0 (*)
          │       │       ├── libdd-trace-obfuscation v3.1.0
          │       │       │   └── libdd-trace-stats v4.0.0 (*)
          │       │       ├── libdd-trace-stats v4.0.0 (*)
          │       │       └── (dev) libdd-trace-utils v5.0.0 (*)
          │       ├── libdd-common-ffi v34.0.0
          │       │   └── libdd-data-pipeline-ffi v34.0.0 (*)
          │       ├── libdd-data-pipeline v5.0.0 (*)
          │       ├── libdd-dogstatsd-client v3.0.0
          │       │   └── libdd-data-pipeline v5.0.0 (*)
          │       ├── libdd-shared-runtime v1.0.0 (*)
          │       ├── libdd-telemetry v5.0.0 (*)
          │       ├── libdd-trace-obfuscation v3.1.0 (*)
          │       ├── libdd-trace-stats v4.0.0 (*)
          │       └── libdd-trace-utils v5.0.0 (*)
          ├── libdd-common v4.1.0 (*)
          └── tokio-rustls v0.26.0
              ├── hyper-rustls v0.27.7 (*)
              └── libdd-common v4.1.0 (*)

error[vulnerability]: Denial of Service via Stack Exhaustion
    ┌─ /home/runner/work/libdatadog/libdatadog/Cargo.lock:287:1
    │
287 │ time 0.3.41 registry+https://github.com/rust-lang/crates.io-index
    │ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ security vulnerability detected
    │
    ├ ID: RUSTSEC-2026-0009
    ├ Advisory: https://rustsec.org/advisories/RUSTSEC-2026-0009
    ├ ## Impact
      
      When user-provided input is provided to any type that parses with the RFC 2822 format, a denial of
      service attack via stack exhaustion is possible. The attack relies on formally deprecated and
      rarely-used features that are part of the RFC 2822 format used in a malicious manner. Ordinary,
      non-malicious input will never encounter this scenario.
      
      ## Patches
      
      A limit to the depth of recursion was added in v0.3.47. From this version, an error will be returned
      rather than exhausting the stack.
      
      ## Workarounds
      
      Limiting the length of user input is the simplest way to avoid stack exhaustion, as the amount of
      the stack consumed would be at most a factor of the length of the input.
    ├ Announcement: https://github.com/time-rs/time/blob/main/CHANGELOG.md#0347-2026-02-05
    ├ Solution: Upgrade to >=0.3.47 (try `cargo update -p time`)
    ├ time v0.3.41
      └── tracing-appender v0.2.3
          └── libdd-log v1.0.0
              └── (dev) libdd-data-pipeline v5.0.0
                  └── libdd-data-pipeline-ffi v34.0.0

advisories FAILED, bans ok, sources ok

📦 libdd-data-pipeline - 5 error(s)

Show output
error[unsound]: Rand is unsound with a custom logger using `rand::rng()`
    ┌─ /home/runner/work/libdatadog/libdatadog/Cargo.lock:214:1
    │
214 │ rand 0.8.5 registry+https://github.com/rust-lang/crates.io-index
    │ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ unsound advisory detected
    │
    ├ ID: RUSTSEC-2026-0097
    ├ Advisory: https://rustsec.org/advisories/RUSTSEC-2026-0097
    ├ It has been reported (by @lopopolo) that the `rand` library is [unsound](https://rust-lang.github.io/unsafe-code-guidelines/glossary.html#soundness-of-code--of-a-library) (i.e. that safe code using the public API can cause Undefined Behaviour) when all the following conditions are met:
      
      - The `log` and `thread_rng` features are enabled
      - A [custom logger](https://docs.rs/log/latest/log/#implementing-a-logger) is defined
      - The custom logger accesses `rand::rng()` (previously `rand::thread_rng()`) and calls any `TryRng` (previously `RngCore`) methods on `ThreadRng`
      - The `ThreadRng` (attempts to) reseed while called from the custom logger (this happens every 64 kB of generated data)
      - Trace-level logging is enabled or warn-level logging is enabled and the random source (the `getrandom` crate) is unable to provide a new seed
      
      `TryRng` (previously `RngCore`) methods for `ThreadRng` use `unsafe` code to cast `*mut BlockRng<ReseedingCore>` to `&mut BlockRng<ReseedingCore>`. When all the above conditions are met this results in an aliased mutable reference, violating the Stacked Borrows rules. Miri is able to detect this violation in sample code. Since construction of [aliased mutable references is Undefined Behaviour](https://doc.rust-lang.org/stable/nomicon/references.html), the behaviour of optimized builds is hard to predict.
    ├ Announcement: https://github.com/rust-random/rand/pull/1763
    ├ Solution: Upgrade to >=0.10.1 OR <0.10.0, >=0.9.3 OR <0.9.0, >=0.8.6 (try `cargo update -p rand`)
    ├ rand v0.8.5
      ├── libdd-common v4.1.0
      │   ├── libdd-capabilities-impl v2.0.0
      │   │   ├── libdd-data-pipeline v5.0.0
      │   │   ├── libdd-shared-runtime v1.0.0
      │   │   │   ├── libdd-data-pipeline v5.0.0 (*)
      │   │   │   ├── libdd-telemetry v5.0.0
      │   │   │   │   └── libdd-data-pipeline v5.0.0 (*)
      │   │   │   └── libdd-trace-stats v4.0.0
      │   │   │       └── libdd-data-pipeline v5.0.0 (*)
      │   │   ├── libdd-trace-stats v4.0.0 (*)
      │   │   └── libdd-trace-utils v5.0.0
      │   │       ├── libdd-data-pipeline v5.0.0 (*)
      │   │       ├── libdd-trace-obfuscation v3.1.0
      │   │       │   └── libdd-trace-stats v4.0.0 (*)
      │   │       ├── libdd-trace-stats v4.0.0 (*)
      │   │       └── (dev) libdd-trace-utils v5.0.0 (*)
      │   ├── libdd-data-pipeline v5.0.0 (*)
      │   ├── libdd-dogstatsd-client v3.0.0
      │   │   └── libdd-data-pipeline v5.0.0 (*)
      │   ├── libdd-shared-runtime v1.0.0 (*)
      │   ├── libdd-telemetry v5.0.0 (*)
      │   ├── libdd-trace-obfuscation v3.1.0 (*)
      │   ├── libdd-trace-stats v4.0.0 (*)
      │   └── libdd-trace-utils v5.0.0 (*)
      ├── (dev) libdd-data-pipeline v5.0.0 (*)
      ├── (dev) libdd-trace-normalization v2.0.0
      │   └── libdd-trace-utils v5.0.0 (*)
      ├── (dev) libdd-trace-stats v4.0.0 (*)
      ├── libdd-trace-utils v5.0.0 (*)
      └── proptest v1.5.0
          └── (dev) libdd-tinybytes v1.1.1
              ├── libdd-data-pipeline v5.0.0 (*)
              ├── (dev) libdd-tinybytes v1.1.1 (*)
              └── libdd-trace-utils v5.0.0 (*)

error[vulnerability]: Name constraints for URI names were incorrectly accepted
    ┌─ /home/runner/work/libdatadog/libdatadog/Cargo.lock:238:1
    │
238 │ rustls-webpki 0.103.10 registry+https://github.com/rust-lang/crates.io-index
    │ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ security vulnerability detected
    │
    ├ ID: RUSTSEC-2026-0098
    ├ Advisory: https://rustsec.org/advisories/RUSTSEC-2026-0098
    ├ Name constraints for URI names were ignored and therefore accepted.
      
      Note this library does not provide an API for asserting URI names, and URI name constraints are otherwise not implemented.  URI name constraints are now rejected unconditionally.
      
      Since name constraints are restrictions on otherwise properly-issued certificates, this bug is reachable only after signature verification and requires misissuance to exploit.
      
      This vulnerability is identified as [GHSA-965h-392x-2mh5](https://github.com/rustls/webpki/security/advisories/GHSA-965h-392x-2mh5). Thank you to @1seal for the report.
    ├ Solution: Upgrade to >=0.103.12, <0.104.0-alpha.1 OR >=0.104.0-alpha.6 (try `cargo update -p rustls-webpki`)
    ├ rustls-webpki v0.103.10
      └── rustls v0.23.37
          ├── hyper-rustls v0.27.7
          │   └── libdd-common v4.1.0
          │       ├── libdd-capabilities-impl v2.0.0
          │       │   ├── libdd-data-pipeline v5.0.0
          │       │   ├── libdd-shared-runtime v1.0.0
          │       │   │   ├── libdd-data-pipeline v5.0.0 (*)
          │       │   │   ├── libdd-telemetry v5.0.0
          │       │   │   │   └── libdd-data-pipeline v5.0.0 (*)
          │       │   │   └── libdd-trace-stats v4.0.0
          │       │   │       └── libdd-data-pipeline v5.0.0 (*)
          │       │   ├── libdd-trace-stats v4.0.0 (*)
          │       │   └── libdd-trace-utils v5.0.0
          │       │       ├── libdd-data-pipeline v5.0.0 (*)
          │       │       ├── libdd-trace-obfuscation v3.1.0
          │       │       │   └── libdd-trace-stats v4.0.0 (*)
          │       │       ├── libdd-trace-stats v4.0.0 (*)
          │       │       └── (dev) libdd-trace-utils v5.0.0 (*)
          │       ├── libdd-data-pipeline v5.0.0 (*)
          │       ├── libdd-dogstatsd-client v3.0.0
          │       │   └── libdd-data-pipeline v5.0.0 (*)
          │       ├── libdd-shared-runtime v1.0.0 (*)
          │       ├── libdd-telemetry v5.0.0 (*)
          │       ├── libdd-trace-obfuscation v3.1.0 (*)
          │       ├── libdd-trace-stats v4.0.0 (*)
          │       └── libdd-trace-utils v5.0.0 (*)
          ├── libdd-common v4.1.0 (*)
          └── tokio-rustls v0.26.0
              ├── hyper-rustls v0.27.7 (*)
              └── libdd-common v4.1.0 (*)

error[vulnerability]: Name constraints were accepted for certificates asserting a wildcard name
    ┌─ /home/runner/work/libdatadog/libdatadog/Cargo.lock:238:1
    │
238 │ rustls-webpki 0.103.10 registry+https://github.com/rust-lang/crates.io-index
    │ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ security vulnerability detected
    │
    ├ ID: RUSTSEC-2026-0099
    ├ Advisory: https://rustsec.org/advisories/RUSTSEC-2026-0099
    ├ Permitted subtree name constraints for DNS names were accepted for certificates asserting a wildcard name.
      
      This was incorrect because, given a name constraint of `accept.example.com`, `*.example.com` could feasibly allow a name of `reject.example.com` which is outside the constraint.
      This is very similar to [CVE-2025-61727](https://go.dev/issue/76442).
      
      Since name constraints are restrictions on otherwise properly-issued certificates, this bug is reachable only after signature verification and requires misissuance to exploit.
      
      This vulnerability is identified as [GHSA-xgp8-3hg3-c2mh](https://github.com/rustls/webpki/security/advisories/GHSA-xgp8-3hg3-c2mh). Thank you to @1seal for the report.
    ├ Solution: Upgrade to >=0.103.12, <0.104.0-alpha.1 OR >=0.104.0-alpha.6 (try `cargo update -p rustls-webpki`)
    ├ rustls-webpki v0.103.10
      └── rustls v0.23.37
          ├── hyper-rustls v0.27.7
          │   └── libdd-common v4.1.0
          │       ├── libdd-capabilities-impl v2.0.0
          │       │   ├── libdd-data-pipeline v5.0.0
          │       │   ├── libdd-shared-runtime v1.0.0
          │       │   │   ├── libdd-data-pipeline v5.0.0 (*)
          │       │   │   ├── libdd-telemetry v5.0.0
          │       │   │   │   └── libdd-data-pipeline v5.0.0 (*)
          │       │   │   └── libdd-trace-stats v4.0.0
          │       │   │       └── libdd-data-pipeline v5.0.0 (*)
          │       │   ├── libdd-trace-stats v4.0.0 (*)
          │       │   └── libdd-trace-utils v5.0.0
          │       │       ├── libdd-data-pipeline v5.0.0 (*)
          │       │       ├── libdd-trace-obfuscation v3.1.0
          │       │       │   └── libdd-trace-stats v4.0.0 (*)
          │       │       ├── libdd-trace-stats v4.0.0 (*)
          │       │       └── (dev) libdd-trace-utils v5.0.0 (*)
          │       ├── libdd-data-pipeline v5.0.0 (*)
          │       ├── libdd-dogstatsd-client v3.0.0
          │       │   └── libdd-data-pipeline v5.0.0 (*)
          │       ├── libdd-shared-runtime v1.0.0 (*)
          │       ├── libdd-telemetry v5.0.0 (*)
          │       ├── libdd-trace-obfuscation v3.1.0 (*)
          │       ├── libdd-trace-stats v4.0.0 (*)
          │       └── libdd-trace-utils v5.0.0 (*)
          ├── libdd-common v4.1.0 (*)
          └── tokio-rustls v0.26.0
              ├── hyper-rustls v0.27.7 (*)
              └── libdd-common v4.1.0 (*)

error[vulnerability]: Reachable panic in certificate revocation list parsing
    ┌─ /home/runner/work/libdatadog/libdatadog/Cargo.lock:238:1
    │
238 │ rustls-webpki 0.103.10 registry+https://github.com/rust-lang/crates.io-index
    │ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ security vulnerability detected
    │
    ├ ID: RUSTSEC-2026-0104
    ├ Advisory: https://rustsec.org/advisories/RUSTSEC-2026-0104
    ├ A panic was reachable when parsing certificate revocation lists via [`BorrowedCertRevocationList::from_der`]
      or [`OwnedCertRevocationList::from_der`].  This was the result of mishandling a syntactically valid empty
      `BIT STRING` appearing in the `onlySomeReasons` element of a `IssuingDistributionPoint` CRL extension.
      
      This panic is reachable prior to a CRL's signature being verified.
      
      Applications that do not use CRLs are not affected.
      
      Thank you to @tynus3 for the report.
    ├ Solution: Upgrade to >=0.103.13, <0.104.0-alpha.1 OR >=0.104.0-alpha.7 (try `cargo update -p rustls-webpki`)
    ├ rustls-webpki v0.103.10
      └── rustls v0.23.37
          ├── hyper-rustls v0.27.7
          │   └── libdd-common v4.1.0
          │       ├── libdd-capabilities-impl v2.0.0
          │       │   ├── libdd-data-pipeline v5.0.0
          │       │   ├── libdd-shared-runtime v1.0.0
          │       │   │   ├── libdd-data-pipeline v5.0.0 (*)
          │       │   │   ├── libdd-telemetry v5.0.0
          │       │   │   │   └── libdd-data-pipeline v5.0.0 (*)
          │       │   │   └── libdd-trace-stats v4.0.0
          │       │   │       └── libdd-data-pipeline v5.0.0 (*)
          │       │   ├── libdd-trace-stats v4.0.0 (*)
          │       │   └── libdd-trace-utils v5.0.0
          │       │       ├── libdd-data-pipeline v5.0.0 (*)
          │       │       ├── libdd-trace-obfuscation v3.1.0
          │       │       │   └── libdd-trace-stats v4.0.0 (*)
          │       │       ├── libdd-trace-stats v4.0.0 (*)
          │       │       └── (dev) libdd-trace-utils v5.0.0 (*)
          │       ├── libdd-data-pipeline v5.0.0 (*)
          │       ├── libdd-dogstatsd-client v3.0.0
          │       │   └── libdd-data-pipeline v5.0.0 (*)
          │       ├── libdd-shared-runtime v1.0.0 (*)
          │       ├── libdd-telemetry v5.0.0 (*)
          │       ├── libdd-trace-obfuscation v3.1.0 (*)
          │       ├── libdd-trace-stats v4.0.0 (*)
          │       └── libdd-trace-utils v5.0.0 (*)
          ├── libdd-common v4.1.0 (*)
          └── tokio-rustls v0.26.0
              ├── hyper-rustls v0.27.7 (*)
              └── libdd-common v4.1.0 (*)

error[vulnerability]: Denial of Service via Stack Exhaustion
    ┌─ /home/runner/work/libdatadog/libdatadog/Cargo.lock:278:1
    │
278 │ time 0.3.41 registry+https://github.com/rust-lang/crates.io-index
    │ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ security vulnerability detected
    │
    ├ ID: RUSTSEC-2026-0009
    ├ Advisory: https://rustsec.org/advisories/RUSTSEC-2026-0009
    ├ ## Impact
      
      When user-provided input is provided to any type that parses with the RFC 2822 format, a denial of
      service attack via stack exhaustion is possible. The attack relies on formally deprecated and
      rarely-used features that are part of the RFC 2822 format used in a malicious manner. Ordinary,
      non-malicious input will never encounter this scenario.
      
      ## Patches
      
      A limit to the depth of recursion was added in v0.3.47. From this version, an error will be returned
      rather than exhausting the stack.
      
      ## Workarounds
      
      Limiting the length of user input is the simplest way to avoid stack exhaustion, as the amount of
      the stack consumed would be at most a factor of the length of the input.
    ├ Announcement: https://github.com/time-rs/time/blob/main/CHANGELOG.md#0347-2026-02-05
    ├ Solution: Upgrade to >=0.3.47 (try `cargo update -p time`)
    ├ time v0.3.41
      └── tracing-appender v0.2.3
          └── libdd-log v1.0.0
              └── (dev) libdd-data-pipeline v5.0.0

advisories FAILED, bans ok, sources ok

Updated: 2026-05-29 11:46:08 UTC | Commit: 5e16401 | dependency-check job results

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 28, 2026

Codecov Report

❌ Patch coverage is 34.88372% with 84 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.86%. Comparing base (1fb8aca) to head (c5c339a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2051      +/-   ##
==========================================
- Coverage   72.88%   72.86%   -0.02%     
==========================================
  Files         460      460              
  Lines       76463    76584     +121     
==========================================
+ Hits        55731    55805      +74     
- Misses      20732    20779      +47     
Components Coverage Δ
libdd-crashtracker 65.36% <ø> (-0.03%) ⬇️
libdd-crashtracker-ffi 36.82% <ø> (ø)
libdd-alloc 98.77% <ø> (ø)
libdd-data-pipeline 84.66% <34.88%> (-0.99%) ⬇️
libdd-data-pipeline-ffi 72.95% <35.71%> (-3.23%) ⬇️
libdd-common 79.89% <ø> (ø)
libdd-common-ffi 74.41% <ø> (ø)
libdd-telemetry 73.37% <ø> (+0.02%) ⬆️
libdd-telemetry-ffi 31.36% <ø> (ø)
libdd-dogstatsd-client 82.64% <ø> (ø)
datadog-ipc 76.22% <ø> (+1.46%) ⬆️
libdd-profiling 81.69% <ø> (ø)
libdd-profiling-ffi 64.79% <ø> (ø)
libdd-sampling 97.46% <ø> (ø)
datadog-sidecar 29.19% <ø> (ø)
datdog-sidecar-ffi 10.17% <ø> (ø)
spawn-worker 48.86% <ø> (ø)
libdd-tinybytes 93.80% <ø> (ø)
libdd-trace-normalization 81.71% <ø> (ø)
libdd-trace-obfuscation 87.30% <ø> (ø)
libdd-trace-protobuf 68.25% <ø> (ø)
libdd-trace-utils 88.94% <ø> (ø)
libdd-tracer-flare 86.88% <ø> (ø)
libdd-log 74.83% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lloeki lloeki marked this pull request as ready for review May 28, 2026 14:40
@lloeki lloeki requested a review from a team as a code owner May 28, 2026 14:40
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 22e92370e5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +39 to +40
tokio = { version = "1.23", features = ["macros"] }
tokio-util = "0.7.11"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Regenerate Cargo.lock for the new dependencies

Adding tokio/tokio-util to this crate without committing the corresponding root Cargo.lock update breaks locked builds: I checked cargo check -p libdd-data-pipeline-ffi --locked, and Cargo exits with the lock file /workspace/libdatadog/Cargo.lock needs to be updated. Any CI or consumer build using the repository lockfile will fail before compiling this crate until the lock entry for libdd-data-pipeline-ffi includes these new dependencies.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

@marcotc marcotc May 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edit: I think I was wrong, looks like a legit failure: https://github.com/DataDog/libdatadog/actions/runs/26578731968/job/78305509370?pr=2051

original comment:
This feels like a case of "AI doesn't know how "libdd-data-pipeline-ffi" is used.
This might information be worth writing down (maybe in https://github.com/DataDog/libdatadog/blob/22e92370e5d66c0efd6ac5fe949bd8b6514fd902/libdd-data-pipeline-ffi/README.md, or other place if this is common across multiple libdatadog/* crates).

"TracerSpan" = "ddog_TracerSpan"
"TracerSpanFields" = "ddog_TracerSpanFields"
"TracerTraceChunks" = "ddog_TracerTraceChunks"
"Handle_TokioCancellationToken" = "ddog_TraceExporterCancelToken"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Declare the opaque cancellation token type in cbindgen

With only the handle rename here, cbindgen emits typedef ddog_CancellationToken ddog_TokioCancellationToken; in data-pipeline.h, but this header only includes common.h, which does not define ddog_CancellationToken; I regenerated the header and cc -fsyntax-only reports unknown type name 'ddog_CancellationToken'. C/C++ consumers that include the generated data-pipeline header will not compile when this new token type is present, so this needs the same opaque token rename/forward declaration pattern used by the profiling FFI header.

Useful? React with 👍 / 👎.

///
/// All clones of the same token observe the cancellation. If the token is
/// currently passed to [`ddog_trace_exporter_send_trace_chunks`], the
/// in-flight HTTP request will be aborted cooperatively.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does cooperatively mean here?

/// Cancel a cancellation token.
///
/// All clones of the same token observe the cancellation. If the token is
/// currently passed to [`ddog_trace_exporter_send_trace_chunks`], the
Copy link
Copy Markdown
Member

@marcotc marcotc May 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// currently passed to [`ddog_trace_exporter_send_trace_chunks`], the
/// currently help by [`ddog_trace_exporter_send_trace_chunks`], the

Wouldn't "currently held" be more accurate than "currently passed" here, since "ddog_trace_exporter_send_trace_chunks" might have finished its work already, thus not holding the token anymore?


/// Cancel a cancellation token.
///
/// All clones of the same token observe the cancellation. If the token is
Copy link
Copy Markdown
Member

@marcotc marcotc May 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the token was not passed to ddog_trace_exporter_send_trace_chunks, but will soon, is a cancellation: scheduled to happen; ddog_trace_exporter_send_trace_chunks won't start because it's already cancelled; nothing?
It's good to document what happens when the token is not held yet.
And also, if the token is no longer held (aka ddog_trace_exporter_send_trace_chunks is done), which I assume means nothing happens on ddog_trace_exporter_cancel_token_cancel.

Comment on lines +315 to +318
/// # Safety
///
/// * `token` must point to a valid [`Handle`] returned by
/// [`ddog_trace_exporter_cancel_token_new`].
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// # Safety
///
/// * `token` must point to a valid [`Handle`] returned by
/// [`ddog_trace_exporter_cancel_token_new`].
/// * `token` is the return of [`ddog_trace_exporter_cancel_token_new`].

I don't think we need to say that we should give this function a "valid" input.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same applies to ddog_trace_exporter_cancel_token_drop.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's more of these Safety comment blocks in down this file. All the ones in a similar "type-checked argument must be type-valid" is likely not needed.


/// Free a cancellation token handle.
///
/// After this call the pointer is invalid and must not be reused.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is useful additional information "After this call the pointer is invalid and must not be reused.".

Freed resources cannot be used and are likely invalid.

If we want to provide additional context here, the only thing I can think of is: what happens if you free it while ddog_trace_exporter_send_trace_chunks still owns it. But I feel like that's kind of a natural contract in Rust/native: freeing things in use == bad.
Not sure if we need an extra comment here.

/// * `chunks` is consumed and must not be used after this call.
/// * If `response_out` is non-null it must point to valid writable memory for a
/// `Box<ExporterResponse>`.
/// * If `cancel` is non-null it must point to a valid cancellation token handle.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment to those in ddog_trace_exporter_cancel_token_cancel: is it even possible to pass an invalid cancellation token since the argument is typed *mut Handle<TokioCancellationToken>?

Copy link
Copy Markdown
Member

@marcotc marcotc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Despite my other comments, the implementation looks good 👍

exporter: Option<&TraceExporter>,
chunks: Box<TracerTraceChunks>,
response_out: Option<NonNull<Box<ExporterResponse>>>,
mut cancel: *mut Handle<TokioCancellationToken>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to not use the Handle and use an Option<&TokioCancellationToken> instead. This way the null pointer is treated as None without any conversion.

Comment on lines +394 to +415
let block_result = exporter.shared_runtime().block_on(async {
tokio::select! {
res = exporter.send_trace_chunks_async(chunks.0) => res,
_ = ct.cancelled() => Err(
std::io::Error::new(
std::io::ErrorKind::Interrupted,
"send cancelled via cancellation token",
).into()
),
}
});
match block_result {
Ok(inner) => inner,
Err(io_err) => Err(io_err.into()),
}
None
} else {
exporter.send_trace_chunks(chunks.0)
};

match result {
Ok(resp) => {
if let Some(out) = response_out {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cancel token is a nice add-on and should be added to the actual trace exporter, we try to keep logic in the *-ffi crates to a minimum.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the send_trace_chunks_async has a bug and shouldn't be used currently (it should have been marked as experimental). I can get it fixed, but the simplest way to bypass it is to add support for the cancel token to send_trace_chunks

Comment on lines +212 to +216
/// Returns a reference to the underlying [`SharedRuntime`].
pub fn shared_runtime(&self) -> &SharedRuntime {
&self.shared_runtime
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SharedRuntime reference in the TraceExporter should remain private if you need to interact with the SharedRuntime (e.g. for fork hooks) you should create a SharedRuntime with libdd-shared-runtime-ffi and pass it to the TraceExporter builder

Comment on lines +394 to +404
let block_result = exporter.shared_runtime().block_on(async {
tokio::select! {
res = exporter.send_trace_chunks_async(chunks.0) => res,
_ = ct.cancelled() => Err(
std::io::Error::new(
std::io::ErrorKind::Interrupted,
"send cancelled via cancellation token",
).into()
),
}
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be called out in the function's doc that using the cancel token may result in data loss

lloeki added 2 commits May 29, 2026 13:40
Add `ddog_trace_exporter_before_fork`, `_after_fork_in_parent`, and
`_after_fork_in_child` that delegate to the underlying SharedRuntime.
These allow C callers to coordinate the tokio runtime lifecycle around
process forks.
Introduce `ddog_trace_exporter_cancel_token_new`, `_cancel`, and
`_drop` for managing cancellation tokens. Thread the token into
`ddog_trace_exporter_send_trace_chunks` via `tokio::select!` so
callers can cooperatively abort in-flight HTTP requests.
@lloeki lloeki force-pushed the lloeki/ffi-for-trace-exporter-fork-safety branch from 22e9237 to c5c339a Compare May 29, 2026 11:42
@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented May 29, 2026

Artifact Size Benchmark Report

aarch64-alpine-linux-musl
Artifact Baseline Commit Change
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.so 7.63 MB 7.70 MB +.81% (+64.09 KB) 🔍
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.a 82.94 MB 83.30 MB +.42% (+361.62 KB) 🔍
aarch64-unknown-linux-gnu
Artifact Baseline Commit Change
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.a 94.03 MB 94.39 MB +.38% (+370.55 KB) 🔍
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.25 MB 10.33 MB +.69% (+73.07 KB) 🔍
libdatadog-x64-windows
Artifact Baseline Commit Change
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.dll 24.53 MB 24.64 MB +.42% (+107.50 KB) 🔍
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.lib 83.96 KB 85.86 KB +2.26% (+1.90 KB) ⚠️
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.pdb 178.26 MB 178.69 MB +.23% (+432.00 KB) 🔍
/libdatadog-x64-windows/debug/static/datadog_profiling_ffi.lib 915.33 MB 917.23 MB +.20% (+1.90 MB) 🔍
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.dll 8.03 MB 8.07 MB +.55% (+45.50 KB) 🔍
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.lib 83.96 KB 85.86 KB +2.26% (+1.90 KB) ⚠️
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.pdb 23.77 MB 23.86 MB +.36% (+88.00 KB) 🔍
/libdatadog-x64-windows/release/static/datadog_profiling_ffi.lib 47.43 MB 47.62 MB +.40% (+194.81 KB) 🔍
libdatadog-x86-windows
Artifact Baseline Commit Change
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.dll 21.27 MB 21.36 MB +.43% (+94.50 KB) 🔍
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.lib 85.29 KB 87.22 KB +2.26% (+1.93 KB) ⚠️
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.pdb 182.23 MB 182.71 MB +.26% (+488.00 KB) 🔍
/libdatadog-x86-windows/debug/static/datadog_profiling_ffi.lib 908.49 MB 910.38 MB +.20% (+1.88 MB) 🔍
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.dll 6.20 MB 6.23 MB +.51% (+33.00 KB) 🔍
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.lib 85.29 KB 87.22 KB +2.26% (+1.93 KB) ⚠️
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.pdb 25.48 MB 25.57 MB +.33% (+88.00 KB) 🔍
/libdatadog-x86-windows/release/static/datadog_profiling_ffi.lib 45.08 MB 45.25 MB +.37% (+174.87 KB) 🔍
x86_64-alpine-linux-musl
Artifact Baseline Commit Change
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.a 73.95 MB 74.27 MB +.43% (+327.84 KB) 🔍
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.so 8.52 MB 8.56 MB +.36% (+32.09 KB) 🔍
x86_64-unknown-linux-gnu
Artifact Baseline Commit Change
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.a 89.36 MB 89.69 MB +.36% (+332.41 KB) 🔍
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.36 MB 10.39 MB +.32% (+34.67 KB) 🔍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants