From 975301d05f910a172b58aed6e330e8caf9adfd78 Mon Sep 17 00:00:00 2001 From: Levi Morrison Date: Tue, 17 Mar 2026 20:10:26 -0600 Subject: [PATCH] feat(profiling): thread id/name as well-known strs --- .../src/profiles/profiles_dictionary.rs | 12 +++++++++++ .../collections/parallel/string_set.rs | 14 +++++++++++++ .../src/profiles/collections/string_set.rs | 6 +++++- .../src/profiles/collections/thin_str.rs | 20 +++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/libdd-profiling-ffi/src/profiles/profiles_dictionary.rs b/libdd-profiling-ffi/src/profiles/profiles_dictionary.rs index d3d3aa0162..24abadcb31 100644 --- a/libdd-profiling-ffi/src/profiles/profiles_dictionary.rs +++ b/libdd-profiling-ffi/src/profiles/profiles_dictionary.rs @@ -46,6 +46,18 @@ pub static DDOG_PROF_STRINGID2_TRACE_ENDPOINT: StringId2 = #[no_mangle] pub static DDOG_PROF_STRINGID2_SPAN_ID: StringId2 = StringId2::from(StringRef::SPAN_ID); +/// A StringId that represents the string "thread id". +/// This is always available in every string set and can be used without +/// needing to insert it into a string set. +#[no_mangle] +pub static DDOG_PROF_STRINGID2_THREAD_ID: StringId2 = StringId2::from(StringRef::THREAD_ID); + +/// A StringId that represents the string "thread name". +/// This is always available in every string set and can be used without +/// needing to insert it into a string set. +#[no_mangle] +pub static DDOG_PROF_STRINGID2_THREAD_NAME: StringId2 = StringId2::from(StringRef::THREAD_NAME); + const NULL_PROFILES_DICTIONARY: &CStr = c"passed a null pointer for a ProfilesDictionary"; /// Allocates a new `ProfilesDictionary` and writes a handle to it in `handle`. diff --git a/libdd-profiling/src/profiles/collections/parallel/string_set.rs b/libdd-profiling/src/profiles/collections/parallel/string_set.rs index ceab5d5f17..9b1f60564a 100644 --- a/libdd-profiling/src/profiles/collections/parallel/string_set.rs +++ b/libdd-profiling/src/profiles/collections/parallel/string_set.rs @@ -109,6 +109,8 @@ mod tests { "local root span id", "trace endpoint", "span id", + "thread id", + "thread name", ]; for (expected, id) in strs.iter().copied().zip(WELL_KNOWN_STRING_REFS) { let actual: &str = id.0.deref(); @@ -140,6 +142,12 @@ mod tests { let str = set.get(StringRef::SPAN_ID); assert_eq!(str, "span id"); + + let str = set.get(StringRef::THREAD_ID); + assert_eq!(str, "thread id"); + + let str = set.get(StringRef::THREAD_NAME); + assert_eq!(str, "thread name"); }; let id = set.try_insert("").unwrap(); @@ -156,6 +164,12 @@ mod tests { let id = set.try_insert("span id").unwrap(); assert_eq!(&*id.0, &*StringRef::SPAN_ID.0); + + let id = set.try_insert("thread id").unwrap(); + assert_eq!(&*id.0, &*StringRef::THREAD_ID.0); + + let id = set.try_insert("thread name").unwrap(); + assert_eq!(&*id.0, &*StringRef::THREAD_NAME.0); } #[test] diff --git a/libdd-profiling/src/profiles/collections/string_set.rs b/libdd-profiling/src/profiles/collections/string_set.rs index 23a51b166c..f5c73ee559 100644 --- a/libdd-profiling/src/profiles/collections/string_set.rs +++ b/libdd-profiling/src/profiles/collections/string_set.rs @@ -58,14 +58,18 @@ impl StringRef { pub const LOCAL_ROOT_SPAN_ID: StringRef = StringRef(ThinStr::local_root_span_id()); pub const TRACE_ENDPOINT: StringRef = StringRef(ThinStr::trace_endpoint()); pub const SPAN_ID: StringRef = StringRef(ThinStr::span_id()); + pub const THREAD_ID: StringRef = StringRef(ThinStr::thread_id()); + pub const THREAD_NAME: StringRef = StringRef(ThinStr::thread_name()); } -pub const WELL_KNOWN_STRING_REFS: [StringRef; 5] = [ +pub const WELL_KNOWN_STRING_REFS: [StringRef; 7] = [ StringRef::EMPTY, StringRef::END_TIMESTAMP_NS, StringRef::LOCAL_ROOT_SPAN_ID, StringRef::TRACE_ENDPOINT, StringRef::SPAN_ID, + StringRef::THREAD_ID, + StringRef::THREAD_NAME, ]; /// Holds unique strings and provides [`StringRef`]s to fetch them later. diff --git a/libdd-profiling/src/profiles/collections/thin_str.rs b/libdd-profiling/src/profiles/collections/thin_str.rs index 1850ccf40a..ef646d0fc7 100644 --- a/libdd-profiling/src/profiles/collections/thin_str.rs +++ b/libdd-profiling/src/profiles/collections/thin_str.rs @@ -132,6 +132,24 @@ impl ThinStr<'static> { }, } } + + pub const fn thread_id() -> ThinStr<'static> { + ThinStr { + inner: ThinSlice { + thin_ptr: THREAD_ID.as_thin_ptr(), + _marker: PhantomData, + }, + } + } + + pub const fn thread_name() -> ThinStr<'static> { + ThinStr { + inner: ThinSlice { + thin_ptr: THREAD_NAME.as_thin_ptr(), + _marker: PhantomData, + }, + } + } } impl Default for ThinStr<'static> { @@ -527,6 +545,8 @@ static END_TIMESTAMP_NS: ConstString<16> = ConstString::new("end_timestamp_ns"); static LOCAL_ROOT_SPAN_ID: ConstString<18> = ConstString::new("local root span id"); static TRACE_ENDPOINT: ConstString<14> = ConstString::new("trace endpoint"); static SPAN_ID: ConstString<7> = ConstString::new("span id"); +static THREAD_ID: ConstString<9> = ConstString::new("thread id"); +static THREAD_NAME: ConstString<11> = ConstString::new("thread name"); #[cfg(test)] mod tests {