Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
44 changes: 44 additions & 0 deletions examples/ffi/trace_exporter.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,52 @@ int log_init(const char* log_path) {
return 0;
}

int verify_structured_value_encoder(void) {
uint8_t text[] = "stable";
uint8_t binary[] = {0x00, 0xff};
ddog_TracerValueToken tokens[] = {
{.kind = DDOG_TRACER_VALUE_ARRAY, .child_count = 2},
{
.kind = DDOG_TRACER_VALUE_STRING,
.bytes = {.ptr = text, .len = sizeof(text) - 1},
},
{
.kind = DDOG_TRACER_VALUE_BINARY,
.bytes = {.ptr = binary, .len = sizeof(binary)},
},
};
ddog_TracerEncodedValue *blob = NULL;
ddog_TraceExporterError *err = ddog_tracer_encode_value(
(ddog_Slice_TracerValueToken){
.ptr = tokens,
.len = sizeof(tokens) / sizeof(tokens[0]),
},
&blob);
if (err) {
handle_error(err);
return 1;
}

memset(text, 'x', sizeof(text) - 1);
memset(binary, 'x', sizeof(binary));
static const uint8_t expected[] = {
0x92, 0xa6, 's','t','a','b','l','e', 0xc4, 0x02, 0x00, 0xff,
};
ddog_ByteSlice encoded = ddog_tracer_encoded_value_as_slice(blob);
int matches = encoded.len == sizeof(expected) &&
memcmp(encoded.ptr, expected, sizeof(expected)) == 0;
ddog_tracer_encoded_value_free(blob);
if (!matches) {
fprintf(stderr, "Structured value encoder did not return an owned blob\n");
return 1;
}
return 0;
}

int main(int argc, char** argv)
{
if (verify_structured_value_encoder() != 0) return 1;

// Initialize logger with optional path from command line
const char* log_path = (argc > 1) ? argv[1] : NULL;
if (log_init(log_path) != 0) {
Expand Down
11 changes: 11 additions & 0 deletions libdd-data-pipeline-ffi/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ typedef struct ddog_TraceExporter ddog_TraceExporter;
typedef struct ddog_TracerSpan ddog_TracerSpan;
typedef struct ddog_TracerTraceChunks ddog_TracerTraceChunks;
typedef struct ddog_TraceExporterCancelToken ddog_TraceExporterCancelToken;
typedef enum ddog_TracerValueKind {
DDOG_TRACER_VALUE_NIL = 0,
DDOG_TRACER_VALUE_BOOL = 1,
DDOG_TRACER_VALUE_I64 = 2,
DDOG_TRACER_VALUE_U64 = 3,
DDOG_TRACER_VALUE_F64 = 4,
DDOG_TRACER_VALUE_STRING = 5,
DDOG_TRACER_VALUE_BINARY = 6,
DDOG_TRACER_VALUE_ARRAY = 7,
DDOG_TRACER_VALUE_MAP = 8,
} ddog_TracerValueKind;
"""

[export]
Expand Down
1 change: 1 addition & 0 deletions libdd-data-pipeline-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

mod error;
mod response;
mod structured_value;
mod trace_exporter;
mod tracer;

Expand Down
Loading
Loading