Skip to content

feat: Align tracer FFI error and response types with common conventions#2029

Draft
lloeki wants to merge 5 commits into
lloeki/ffi-for-trace-exporterfrom
lloeki/ffi-for-trace-exporter-improved
Draft

feat: Align tracer FFI error and response types with common conventions#2029
lloeki wants to merge 5 commits into
lloeki/ffi-for-trace-exporterfrom
lloeki/ffi-for-trace-exporter-improved

Conversation

@lloeki
Copy link
Copy Markdown
Member

@lloeki lloeki commented May 22, 2026

What does this PR do?

Two improvements to the tracer FFI surface in libdd-data-pipeline-ffi:

  1. Use ddog_MaybeError for tracer construction functions. Switch
    ddog_tracer_span_new, set_meta, set_metric, trace_chunks_new,
    begin_chunk, and push_span from Option<Box<ExporterError>> to
    MaybeError (Option<ddog_Error>). These functions only produce error
    messages — the error code is never used by callers — so the simpler
    ddog_Error type is sufficient. send_trace_chunks retains
    ExporterError because callers need the error code for HTTP response
    classification.

  2. Return ByteSlice from ddog_trace_exporter_response_get_body.
    Replace the separate *const u8 return + out_len out-parameter with
    a single ByteSlice return value, matching the existing slice
    conventions in libdd-common-ffi.

Motivation

FUP to #1952. C consumers (dd-trace-rb) can now use the existing
read_ddogerr_string_and_drop / get_error_details_and_drop helpers
from datadog_ruby_common.h instead of custom error handling for tracer
construction functions. The ByteSlice return avoids an awkward split
between return value and out-parameter for the response body.

Additional Notes

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

All 40 tests pass (13 tracer + 3 response + 24 trace_exporter).

@datadog-official
Copy link
Copy Markdown

datadog-official Bot commented May 22, 2026

Pipelines  Tests

Fix all issues with BitsAI

⚠️ Warnings

🚦 13 Pipeline jobs failed

DataDog/apm-reliability/libdatadog | benchmarks   View in Datadog   GitLab

🔧 Fix in code (Fix with Cursor). Compilation error: feature `edition2024` is required but not stabilized in Cargo version 1.84.1.

Lint | clippy #ubuntu-latest 1.84.1   View in Datadog   GitHub Actions

🔧 Fix in code (Fix with Cursor). Compilation error in Cargo.toml: feature `edition2024` is required but not stabilized in Cargo 1.84.1.

Lint | clippy #ubuntu-latest nightly-2026-02-08   View in Datadog   GitHub Actions

🔧 Fix in code (Fix with Cursor). Compilation error in libdd-trace-obfuscation/src/replacer.rs:129: variables can be used directly in the `format!` string.

View all 13 failed jobs.

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 66.37%
Overall Coverage: 72.72% (-0.02%)

Useful? React with 👍 / 👎

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

@lloeki lloeki changed the base branch from main to lloeki/ffi-for-trace-exporter May 22, 2026 12:24
@lloeki lloeki force-pushed the lloeki/ffi-for-trace-exporter-improved branch from 405e95f to dc8aeb9 Compare May 22, 2026 12:42
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

📚 Documentation Check Results

⚠️ 1161 documentation warning(s) found

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


Updated: 2026-05-22 13:43:09 UTC | Commit: aef5537 | missing-docs job results

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

🔒 Cargo Deny Results

No issues found!

📦 libdd-data-pipeline-ffi - ✅ No issues


Updated: 2026-05-22 13:44:23 UTC | Commit: aef5537 | dependency-check job results

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

Clippy Allow Annotation Report

Comparing clippy allow annotations between branches:

Summary by Rule

Rule Base Branch PR Branch Change

Annotation Counts by File

File Base Branch PR Branch Change

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 15 15 No change (0%)
Total 198 198 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.

@lloeki lloeki force-pushed the lloeki/ffi-for-trace-exporter-improved branch from dc8aeb9 to b3784be Compare May 22, 2026 12:50
lloeki added 3 commits May 22, 2026 14:55
Switch tracer span and chunk construction functions from
`Option<Box<ExporterError>>` to `MaybeError` (`Option<ddog_Error>`).
These functions only produce error messages (the error code is never
used by callers), so the simpler `ddog_Error` type is sufficient.

This lets C consumers use the existing `read_ddogerr_string_and_drop`
and `get_error_details_and_drop` helpers instead of custom error
handling.

`send_trace_chunks` retains `ExporterError` because callers need
the error code for HTTP response classification.
Replace the separate `*const u8` return + `out_len` out-parameter with
a single `ByteSlice` return value. This bundles pointer and length
into one FFI-safe struct, matching the existing slice conventions in
libdd-common-ffi and avoiding the awkward split between return value
and out-parameter.
Wrap the `fields` parameter in `Option` so the function can check for
null and return an error instead of undefined behavior. cbindgen
produces the same C signature (`const ddog_TracerSpanFields *`).
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 22, 2026

Codecov Report

❌ Patch coverage is 66.37168% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.72%. Comparing base (5e2089f) to head (1425e68).

Additional details and impacted files
@@                        Coverage Diff                        @@
##           lloeki/ffi-for-trace-exporter    #2029      +/-   ##
=================================================================
- Coverage                          72.73%   72.72%   -0.02%     
=================================================================
  Files                                459      459              
  Lines                              76096    76065      -31     
=================================================================
- Hits                               55352    55316      -36     
- Misses                             20744    20749       +5     
Components Coverage Δ
libdd-crashtracker 65.42% <ø> (+0.19%) ⬆️
libdd-crashtracker-ffi 38.53% <ø> (+1.70%) ⬆️
libdd-alloc 98.77% <ø> (ø)
libdd-data-pipeline 85.07% <66.37%> (+0.02%) ⬆️
libdd-data-pipeline-ffi 72.77% <66.37%> (-0.20%) ⬇️
libdd-common 79.83% <ø> (+0.02%) ⬆️
libdd-common-ffi 74.49% <ø> (+0.07%) ⬆️
libdd-telemetry 73.37% <ø> (ø)
libdd-telemetry-ffi 31.36% <ø> (ø)
libdd-dogstatsd-client 82.64% <ø> (ø)
datadog-ipc 74.75% <ø> (ø)
libdd-profiling 81.69% <ø> (ø)
libdd-profiling-ffi 64.79% <ø> (ø)
libdd-sampling 97.46% <ø> (ø)
datadog-sidecar 28.55% <ø> (-0.51%) ⬇️
datdog-sidecar-ffi 7.01% <ø> (-2.51%) ⬇️
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.86% <ø> (ø)
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 force-pushed the lloeki/ffi-for-trace-exporter branch from 9d7998b to 5e2089f Compare May 22, 2026 13:13
@lloeki lloeki force-pushed the lloeki/ffi-for-trace-exporter-improved branch from b3784be to 34f795a Compare May 22, 2026 13:13
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.

2 participants