Skip to content

Commit e268076

Browse files
lloekiekump
andauthored
feat: Add FFI for trace exporter (#1952)
# What does this PR do? Add span-building and trace-sending FFI functions to `libdd-data-pipeline-ffi`, enabling language tracers to construct spans field-by-field through the C API instead of passing pre-serialized msgpack. New types: - `TracerSpan`: opaque handle wrapping `Span<BytesData>` - `TracerTraceChunks`: opaque handle wrapping `Vec<Vec<SpanBytes>>` New functions: - `ddog_tracer_span_new`, `_free`, `_set_meta`, `_set_metric` - `ddog_tracer_trace_chunks_new`, `_free`, `_begin_chunk`, `_push_span` - `ddog_trace_exporter_send_trace_chunks` # Motivation The Ruby tracer needs a native trace export path that bypasses Ruby-side msgpack serialization. This provides the FFI surface for it; the corresponding C extension in `dd-trace-rb` calls these functions. Continuation of the prototype in #1661, reworked to stay close to `main`: the generic `TraceExporter<H>` and `SharedRuntime` are untouched; this is purely additive. # Additional Notes Spans are consumed on push, chunks are consumed on send — single-ownership enforced at the API level. `libdd-trace-utils` is promoted from dev-dependency to regular dependency since the FFI crate now needs `SpanBytes` at build time. Sibling PR for Ruby is at: DataDog/dd-trace-rb#5690 # How to test the change? `cargo test -p libdd-data-pipeline-ffi --lib` — 39 tests, all passing. The existing `trace_exporter` tests are unaffected. Co-authored-by: edmund.kump <edmund.kump@datadoghq.com>
1 parent dd71a87 commit e268076

5 files changed

Lines changed: 614 additions & 3 deletions

File tree

libdd-data-pipeline-ffi/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ libdd-data-pipeline = { path = "../libdd-data-pipeline" }
3535
libdd-shared-runtime = { version = "1.0.0", path = "../libdd-shared-runtime" }
3636
libdd-common-ffi = { path = "../libdd-common-ffi", default-features = false }
3737
libdd-tinybytes = { path = "../libdd-tinybytes" }
38+
libdd-trace-utils = { path = "../libdd-trace-utils" }
3839
tracing = { version = "0.1", default-features = false }

libdd-data-pipeline-ffi/cbindgen.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ include_guard = "DDOG_DATA_PIPELINE_H"
1111
includes = ["common.h"]
1212
after_includes = """
1313
typedef struct ddog_TraceExporter ddog_TraceExporter;
14+
typedef struct ddog_TracerSpan ddog_TracerSpan;
15+
typedef struct ddog_TracerTraceChunks ddog_TracerTraceChunks;
1416
"""
1517

1618
[export]
1719
prefix = "ddog_"
1820
renaming_overrides_prefixing = true
19-
exclude = ["TraceExporter"]
21+
exclude = ["TraceExporter", "TracerSpan", "TracerTraceChunks"]
2022

2123
[export.rename]
2224
"ByteSlice" = "ddog_ByteSlice"
@@ -27,6 +29,9 @@ exclude = ["TraceExporter"]
2729
"ExporterResponse" = "ddog_TraceExporterResponse"
2830
"ExporterErrorCode" = "ddog_TraceExporterErrorCode"
2931
"ExporterError" = "ddog_TraceExporterError"
32+
"TracerSpan" = "ddog_TracerSpan"
33+
"TracerSpanFields" = "ddog_TracerSpanFields"
34+
"TracerTraceChunks" = "ddog_TracerTraceChunks"
3035

3136
[export.mangle]
3237
rename_types = "PascalCase"
@@ -40,4 +45,4 @@ must_use = "DDOG_CHECK_RETURN"
4045

4146
[parse]
4247
parse_deps = true
43-
include = ["libdd-common", "libdd-common-ffi", "libdd-shared-runtime", "libdd-data-pipeline"]
48+
include = ["libdd-common", "libdd-common-ffi", "libdd-shared-runtime", "libdd-data-pipeline", "libdd-trace-utils"]

libdd-data-pipeline-ffi/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
mod error;
1010
mod response;
1111
mod trace_exporter;
12+
mod tracer;
1213

1314
#[cfg(all(feature = "catch_panic", panic = "unwind"))]
1415
macro_rules! catch_panic {

libdd-data-pipeline-ffi/src/trace_exporter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use libdd_data_pipeline::trace_exporter::{
1414
TraceExporterInputFormat, TraceExporterOutputFormat,
1515
};
1616

17-
type TraceExporter = GenericTraceExporter<NativeCapabilities>;
17+
pub(crate) type TraceExporter = GenericTraceExporter<NativeCapabilities>;
1818

1919
use libdd_shared_runtime::SharedRuntime;
2020
use std::{ptr::NonNull, sync::Arc, time::Duration};

0 commit comments

Comments
 (0)