Skip to content

Commit 2453a51

Browse files
authored
process_discovery: expose threadlocal_attribute_keys (#135)
Add the optional `threadlocal_attribute_keys: Option<Vec<String>>` field to the NAPI `TracerMetadata` and forward it to libdatadog's `tracer_metadata::TracerMetadata`. When set, libdatadog's `to_otel_process_ctx` injects: threadlocal.schema_version = "tlsdesc_v1_dev" threadlocal.attribute_key_map = ["datadog.local_root_span_id", ...threadlocal_attribute_keys] into the OTel process context, giving an out-of-process reader the name table for the uint8 key indices that OTEP-4947 thread-context records carry on the wire. The implicit `datadog.local_root_span_id` key is prepended by libdatadog itself; callers only supply their *additional* keys (entry 0 in this list = wire key index 1). The field is gated behind libdatadog's `otel-thread-ctx` Cargo feature, which arrived after v29.0.0. Bump the `libdd-library-config` dependency to v35.0.0 (matches the version already pinned by the crashtracker crate in this workspace) and enable the feature. Existing 8-arg constructor calls keep working because the new field is optional. The test exercises both the absent and present forms.
1 parent 0c3f048 commit 2453a51

4 files changed

Lines changed: 38 additions & 6 deletions

File tree

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/process_discovery/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ crate-type = ["cdylib", "rlib"]
88

99
[dependencies]
1010
anyhow = "1"
11-
libdd-library-config = { git = "https://github.com/DataDog/libdatadog.git", tag = "v29.0.0" }
11+
libdd-library-config = { git = "https://github.com/DataDog/libdatadog.git", tag = "v35.0.0", features = ["otel-thread-ctx"] }
1212

1313
napi = { version = "2" }
1414
napi-derive = { version = "2", default-features = false }

crates/process_discovery/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ pub struct TracerMetadata {
2121
pub service_version: Option<String>,
2222
pub process_tags: Option<String>,
2323
pub container_id: Option<String>,
24+
/// Ordered list of attribute key names for thread-level OTEP-4947
25+
/// context records. Key indices on the wire index into this list.
26+
/// libdatadog's OTel process-context conversion prepends the
27+
/// implicit `datadog.local_root_span_id` entry at wire index 0, so
28+
/// callers should only set their additional keys here — entry 0 in
29+
/// this list corresponds to wire key index 1.
30+
///
31+
/// `null`/omitted (the default) disables the thread-context-related
32+
/// attributes in the OTel process context entirely.
33+
pub threadlocal_attribute_keys: Option<Vec<String>>,
2434
}
2535

2636
#[napi]
@@ -36,6 +46,7 @@ pub fn store_metadata(data: &TracerMetadata) -> napi::Result<NapiAnonymousFileHa
3646
service_version: data.service_version.clone(),
3747
process_tags: data.process_tags.clone(),
3848
container_id: data.container_id.clone(),
49+
threadlocal_attribute_keys: data.threadlocal_attribute_keys.clone(),
3950
});
4051

4152
match res {

test/process-discovery.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@ const metadata = new process_discovery.TracerMetadata(
2222
const cfg_handle = process_discovery.storeMetadata(metadata)
2323
assert(cfg_handle !== undefined)
2424

25+
// Same shape, plus a thread-local attribute key map (OTEP-4947). libdatadog
26+
// implicitly prepends `datadog.local_root_span_id` at wire index 0; entries
27+
// here start at wire index 1.
28+
const metadata_with_threadlocal = new process_discovery.TracerMetadata(
29+
'7938685c-19dd-490f-b9b3-8aae4c22f898',
30+
'1.0.0',
31+
'my_hostname',
32+
'my_svc',
33+
'my_env',
34+
'my_version',
35+
undefined,
36+
undefined,
37+
['endpoint', 'http.status'],
38+
)
39+
assert.deepStrictEqual(
40+
metadata_with_threadlocal.threadlocalAttributeKeys,
41+
['endpoint', 'http.status'],
42+
)
43+
const cfg_handle_threadlocal = process_discovery.storeMetadata(metadata_with_threadlocal)
44+
assert(cfg_handle_threadlocal !== undefined)
45+
2546
if (process.platform === 'linux') {
2647
const contains_datadog_memfd = (fds) => {
2748
for (const fd in fds) {

0 commit comments

Comments
 (0)