Skip to content

Commit 6e108c7

Browse files
yannhamclaude
andcommitted
feat: extend process ctx with thread-ctx attrs
Adds `threadlocal_attribute_keys: Vec<String>` to `TracerMetadata`. When non-empty, `to_otel_process_ctx()` appends two resource attributes to the published `ProcessContext` protobuf: - `threadlocal.schema_version`: fixed string `"tlsdesc_v1_dev"` (will become `"tlsdesc_v1"` once the OTEP is merged). - `threadlocal.attribute_key_map`: array of key name strings; index `i` maps to key index `i` in per-thread TLS records. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8bfc3fb commit 6e108c7

1 file changed

Lines changed: 51 additions & 14 deletions

File tree

libdd-library-config/src/tracer_metadata.rs

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ pub struct TracerMetadata {
3333
/// Container id seen by the application.
3434
#[serde(skip_serializing_if = "Option::is_none")]
3535
pub container_id: Option<String>,
36+
/// Ordered list of attribute key names for thread-level context records. Key indices from
37+
/// thread context records index into this table. Keep empty if thread-level context is not
38+
/// used.
39+
///
40+
/// This field is specific to OTel process context. It is ignored for (de)serialization, and is
41+
/// only used when converting to an OTel process context in
42+
/// [TracerMetadata::to_otel_process_ctx].
43+
#[serde(skip)]
44+
pub threadlocal_attribute_keys: Vec<String>,
3645
}
3746

3847
impl Default for TracerMetadata {
@@ -48,6 +57,7 @@ impl Default for TracerMetadata {
4857
service_version: None,
4958
process_tags: None,
5059
container_id: None,
60+
threadlocal_attribute_keys: vec![],
5161
}
5262
}
5363
}
@@ -57,7 +67,10 @@ impl TracerMetadata {
5767
const OTEL_SDK_NAME: &str = "libdatadog";
5868

5969
pub fn to_otel_process_ctx(&self) -> otel_proto::common::v1::ProcessContext {
60-
use otel_proto::common::v1::{any_value, AnyValue, KeyValue};
70+
use otel_proto::{
71+
common::v1::{any_value, AnyValue, ArrayValue, KeyValue, ProcessContext},
72+
resource::v1::Resource,
73+
};
6174

6275
fn key_value(key: &'static str, val: String) -> KeyValue {
6376
KeyValue {
@@ -89,21 +102,45 @@ impl TracerMetadata {
89102
service_version,
90103
process_tags,
91104
container_id,
105+
threadlocal_attribute_keys,
92106
} = self;
93107

94-
otel_proto::common::v1::ProcessContext {
95-
resource: Some(otel_proto::resource::v1::Resource {
96-
attributes: vec![
97-
key_value_opt("service.name", service_name),
98-
key_value_opt("service.instance.id", runtime_id),
99-
key_value_opt("service.version", service_version),
100-
key_value_opt("deployment.environment.name", service_env),
101-
key_value("telemetry.sdk.language", tracer_language.clone()),
102-
key_value("telemetry.sdk.version", tracer_version.clone()),
103-
key_value("telemetry.sdk.name", Self::OTEL_SDK_NAME.to_owned()),
104-
key_value("host.name", hostname.clone()),
105-
key_value_opt("container.id", container_id),
106-
],
108+
let mut attributes = vec![
109+
key_value_opt("service.name", service_name),
110+
key_value_opt("service.instance.id", runtime_id),
111+
key_value_opt("service.version", service_version),
112+
key_value_opt("deployment.environment.name", service_env),
113+
key_value("telemetry.sdk.language", tracer_language.clone()),
114+
key_value("telemetry.sdk.version", tracer_version.clone()),
115+
key_value("telemetry.sdk.name", Self::OTEL_SDK_NAME.to_owned()),
116+
key_value("host.name", hostname.clone()),
117+
key_value_opt("container.id", container_id),
118+
];
119+
120+
if !threadlocal_attribute_keys.is_empty() {
121+
attributes.push(key_value(
122+
"threadlocal.schema_version",
123+
"tlsdesc_v1_dev".to_owned(),
124+
));
125+
attributes.push(KeyValue {
126+
key: "threadlocal.attribute_key_map".to_owned(),
127+
value: Some(AnyValue {
128+
value: Some(any_value::Value::ArrayValue(ArrayValue {
129+
values: threadlocal_attribute_keys
130+
.iter()
131+
.map(|k| AnyValue {
132+
value: Some(any_value::Value::StringValue(k.clone())),
133+
})
134+
.collect(),
135+
})),
136+
}),
137+
key_ref: 0,
138+
});
139+
}
140+
141+
ProcessContext {
142+
resource: Some(Resource {
143+
attributes,
107144
dropped_attributes_count: 0,
108145
entity_refs: vec![],
109146
}),

0 commit comments

Comments
 (0)