Skip to content
Merged
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
29 changes: 15 additions & 14 deletions libdd-library-config/src/tracer_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ impl TracerMetadata {
threadlocal_attribute_keys,
} = self;

#[cfg_attr(not(feature = "otel-thread-ctx"), allow(unused_mut))]
let mut attributes = vec![
let resource_attrs = vec![
key_value_opt("service.name", service_name),
key_value_opt("service.instance.id", runtime_id),
key_value_opt("service.version", service_version),
Expand All @@ -128,14 +127,18 @@ impl TracerMetadata {
key_value_opt("container.id", container_id),
];

// `mut` is only needed when `otel-thread-ctx` is enabled.
#[allow(unused_mut)]
let mut extra_attributes = vec![key_value_opt("datadog.process_tags", process_tags)];
Comment thread
yannham marked this conversation as resolved.

#[cfg(feature = "otel-thread-ctx")]
if let Some(threadlocal_attribute_keys) = threadlocal_attribute_keys.as_ref() {
attributes.push(key_value(
extra_attributes.push(key_value(
Comment thread
yannham marked this conversation as resolved.
"threadlocal.schema_version",
"tlsdesc_v1_dev".to_owned(),
));

attributes.push(KeyValue {
extra_attributes.push(KeyValue {
key: "threadlocal.attribute_key_map".to_owned(),
value: Some(AnyValue {
value: Some(any_value::Value::ArrayValue(ArrayValue {
Expand All @@ -156,11 +159,11 @@ impl TracerMetadata {

ProcessContext {
resource: Some(Resource {
attributes,
attributes: resource_attrs,
dropped_attributes_count: 0,
entity_refs: vec![],
}),
extra_attributes: vec![key_value_opt("datadog.process_tags", process_tags)],
extra_attributes,
}
}
}
Expand Down Expand Up @@ -237,10 +240,8 @@ mod tests {
use libdd_trace_protobuf::opentelemetry::proto::common::v1::any_value;
use libdd_trace_protobuf::opentelemetry::proto::common::v1::{AnyValue, ProcessContext};

fn find_attr<'a>(ctx: &'a ProcessContext, key: &str) -> Option<&'a AnyValue> {
ctx.resource
.as_ref()?
.attributes
fn find_extra_attr<'a>(ctx: &'a ProcessContext, key: &str) -> Option<&'a AnyValue> {
ctx.extra_attributes
.iter()
.find(|kv| kv.key == key)?
.value
Expand Down Expand Up @@ -270,8 +271,8 @@ mod tests {
fn threadlocal_attrs_absent_when_keys_empty() {
let ctx = TracerMetadata::default().to_otel_process_ctx();

assert!(find_attr(&ctx, "threadlocal.schema_version").is_none());
assert!(find_attr(&ctx, "threadlocal.attribute_key_map").is_none());
assert!(find_extra_attr(&ctx, "threadlocal.schema_version").is_none());
assert!(find_extra_attr(&ctx, "threadlocal.attribute_key_map").is_none());
}

#[cfg(feature = "otel-thread-ctx")]
Expand All @@ -288,15 +289,15 @@ mod tests {
.to_otel_process_ctx();

// Schema version attribute
let schema_version = find_attr(&ctx, "threadlocal.schema_version")
let schema_version = find_extra_attr(&ctx, "threadlocal.schema_version")
.expect("threadlocal.schema_version should be present");
assert_eq!(
schema_version.value,
Some(any_value::Value::StringValue("tlsdesc_v1_dev".to_owned()))
);

// Key map attribute: ordered array of key name strings
let key_map = find_attr(&ctx, "threadlocal.attribute_key_map")
let key_map = find_extra_attr(&ctx, "threadlocal.attribute_key_map")
.expect("threadlocal.attribute_key_map should be present");
let array = match &key_map.value {
Some(any_value::Value::ArrayValue(a)) => a,
Expand Down
Loading