Skip to content

Commit a03994a

Browse files
committed
feat(data-pipeline-ffi): add function to manipulate meta_struct
Signed-off-by: Alexandre Rulleau <[email protected]>
1 parent ccdf107 commit a03994a

File tree

1 file changed

+61
-4
lines changed

1 file changed

+61
-4
lines changed

data-pipeline-ffi/src/span.rs

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ pub unsafe extern "C" fn ddog_get_trace(ptr: *mut TracesBytes, index: usize) ->
210210
&mut object[index] as *mut TraceBytes
211211
}
212212

213-
// ------------------ TracesBytes ------------------
213+
// ------------------ TraceBytes ------------------
214214

215215
#[no_mangle]
216216
#[allow(clippy::missing_safety_doc)]
@@ -247,6 +247,21 @@ pub unsafe extern "C" fn ddog_get_trace_size(ptr: *mut TraceBytes) -> usize {
247247
object.len()
248248
}
249249

250+
#[no_mangle]
251+
#[allow(clippy::missing_safety_doc)]
252+
pub unsafe extern "C" fn ddog_get_span(ptr: *mut TraceBytes, index: usize) -> *mut SpanBytes {
253+
if ptr.is_null() {
254+
return std::ptr::null_mut();
255+
}
256+
257+
let object = &mut *ptr;
258+
if index >= object.len() {
259+
return std::ptr::null_mut();
260+
}
261+
262+
&mut object[index] as *mut SpanBytes
263+
}
264+
250265
// ------------------- SpanBytes -------------------
251266

252267
#[no_mangle]
@@ -347,13 +362,13 @@ pub unsafe extern "C" fn ddog_get_span_trace_id(ptr: *mut SpanBytes) -> u64 {
347362

348363
#[no_mangle]
349364
#[allow(clippy::missing_safety_doc)]
350-
pub unsafe extern "C" fn ddog_set_span_span_id(ptr: *mut SpanBytes, value: u64) {
365+
pub unsafe extern "C" fn ddog_set_span_id(ptr: *mut SpanBytes, value: u64) {
351366
set_numeric_field!(ptr, value, span_id);
352367
}
353368

354369
#[no_mangle]
355370
#[allow(clippy::missing_safety_doc)]
356-
pub unsafe extern "C" fn ddog_get_span_span_id(ptr: *mut SpanBytes) -> u64 {
371+
pub unsafe extern "C" fn ddog_get_span_id(ptr: *mut SpanBytes) -> u64 {
357372
get_numeric_field!(ptr, span_id)
358373
}
359374

@@ -525,6 +540,47 @@ pub unsafe extern "C" fn ddog_add_span_meta_struct(
525540
);
526541
}
527542

543+
#[no_mangle]
544+
#[allow(clippy::missing_safety_doc)]
545+
pub unsafe extern "C" fn ddog_del_span_meta_struct(ptr: *mut SpanBytes, key: CharSlice) {
546+
remove_hashmap!(ptr, key, meta_struct);
547+
}
548+
549+
#[no_mangle]
550+
#[allow(clippy::missing_safety_doc)]
551+
pub unsafe extern "C" fn ddog_get_span_meta_struct(
552+
ptr: *mut SpanBytes,
553+
key: CharSlice,
554+
) -> CharSlice<'static> {
555+
if ptr.is_null() {
556+
return CharSlice::empty();
557+
}
558+
559+
let span = &mut *ptr;
560+
561+
let bytes_str_key = BytesString::from_slice(key.as_bytes()).unwrap_or_default();
562+
563+
match span.meta_struct.get(&bytes_str_key) {
564+
Some(value) => CharSlice::from_raw_parts(value.as_ptr().cast(), value.len()),
565+
None => CharSlice::empty(),
566+
}
567+
}
568+
569+
#[no_mangle]
570+
#[allow(clippy::missing_safety_doc)]
571+
pub unsafe extern "C" fn ddog_has_span_meta_struct(ptr: *mut SpanBytes, key: CharSlice) -> bool {
572+
exists_hashmap!(ptr, key, meta_struct);
573+
}
574+
575+
#[no_mangle]
576+
#[allow(clippy::missing_safety_doc)]
577+
pub unsafe extern "C" fn ddog_span_meta_struct_get_keys(
578+
span_ptr: *mut SpanBytes,
579+
out_count: *mut usize,
580+
) -> *mut CharSlice<'static> {
581+
get_keys_hashmap!(span_ptr, out_count, meta_struct)
582+
}
583+
528584
#[no_mangle]
529585
#[allow(clippy::missing_safety_doc)]
530586
pub unsafe extern "C" fn ddog_span_free_keys_ptr(keys_ptr: *mut CharSlice<'static>, count: usize) {
@@ -681,6 +737,7 @@ pub unsafe extern "C" fn ddog_serialize_trace_into_c_string(
681737
}
682738
}
683739

740+
#[allow(clippy::missing_safety_doc)]
684741
pub unsafe fn serialize_traces_into_mapped_memory(
685742
traces_ptr: *const TracesBytes,
686743
buf_ptr: *mut c_void,
@@ -896,7 +953,7 @@ mod tests {
896953
ddog_set_span_resource(span_ptr, CharSlice::from("resource"));
897954
ddog_set_span_type(span_ptr, CharSlice::from("type"));
898955
ddog_set_span_trace_id(span_ptr, 1);
899-
ddog_set_span_span_id(span_ptr, 2);
956+
ddog_set_span_id(span_ptr, 2);
900957
ddog_set_span_parent_id(span_ptr, 3);
901958
ddog_set_span_start(span_ptr, 4);
902959
ddog_set_span_duration(span_ptr, 5);

0 commit comments

Comments
 (0)