From bf33702f9c49ecae9d24bdbdb0b62a1baf27ff72 Mon Sep 17 00:00:00 2001 From: Julio Gonzalez Date: Fri, 24 May 2024 14:35:41 +0200 Subject: [PATCH] Add 'src_library' tag to metrics collect in the sidecar. --- sidecar/src/self_telemetry.rs | 33 ++++++++++++++++++------- trace-mini-agent/src/trace_processor.rs | 4 +-- trace-utils/src/trace_utils.rs | 7 +++++- trace-utils/src/tracer_header_tags.rs | 15 ++++++++--- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/sidecar/src/self_telemetry.rs b/sidecar/src/self_telemetry.rs index a710ddb736..74498be9aa 100644 --- a/sidecar/src/self_telemetry.rs +++ b/sidecar/src/self_telemetry.rs @@ -68,63 +68,78 @@ impl<'a> MetricData<'a> { futures.push(self.send( self.logs_created, count as f64, - vec![Tag::new("level", level.as_str().to_lowercase()).unwrap()], + vec![ + Tag::new("level", level.as_str().to_lowercase()).unwrap(), + Tag::new("src_library", "libdatadog").unwrap(), + ], )); } if trace_metrics.api_requests > 0 { futures.push(self.send( self.trace_api_requests, trace_metrics.api_requests as f64, - vec![], + vec![Tag::new("src_library", "libdatadog").unwrap()], )); } if trace_metrics.api_errors_network > 0 { futures.push(self.send( self.trace_api_errors, trace_metrics.api_errors_network as f64, - vec![Tag::new("type", "network").unwrap()], + vec![ + Tag::new("type", "network").unwrap(), + Tag::new("src_library", "libdatadog").unwrap(), + ], )); } if trace_metrics.api_errors_timeout > 0 { futures.push(self.send( self.trace_api_errors, trace_metrics.api_errors_timeout as f64, - vec![Tag::new("type", "timeout").unwrap()], + vec![ + Tag::new("type", "timeout").unwrap(), + Tag::new("src_library", "libdatadog").unwrap(), + ], )); } if trace_metrics.api_errors_status_code > 0 { futures.push(self.send( self.trace_api_errors, trace_metrics.api_errors_status_code as f64, - vec![Tag::new("type", "status_code").unwrap()], + vec![ + Tag::new("type", "status_code").unwrap(), + Tag::new("src_library", "libdatadog").unwrap(), + ], )); } if trace_metrics.bytes_sent > 0 { futures.push(self.send( self.trace_api_bytes, trace_metrics.bytes_sent as f64, - vec![], + vec![Tag::new("src_library", "libdatadog").unwrap()], )); } if trace_metrics.chunks_sent > 0 { futures.push(self.send( self.trace_chunk_sent, trace_metrics.chunks_sent as f64, - vec![], + vec![Tag::new("src_library", "libdatadog").unwrap()], )); } if trace_metrics.chunks_dropped > 0 { futures.push(self.send( self.trace_chunk_dropped, trace_metrics.chunks_dropped as f64, - vec![], + vec![Tag::new("src_library", "libdatadog").unwrap()], )); } for (status_code, count) in &trace_metrics.api_responses_count_per_code { futures.push(self.send( self.trace_api_responses, *count as f64, - vec![Tag::new("status_code", status_code.to_string().as_str()).unwrap()], + vec![ + Tag::new("status_code", status_code.to_string().as_str()).unwrap(), + Tag::new("src_library", "libdatadog").unwrap(), + ], )); } diff --git a/trace-mini-agent/src/trace_processor.rs b/trace-mini-agent/src/trace_processor.rs index 11185123cb..e9a4866322 100644 --- a/trace-mini-agent/src/trace_processor.rs +++ b/trace-mini-agent/src/trace_processor.rs @@ -213,7 +213,7 @@ mod tests { assert_eq!( expected_tracer_payload, - tracer_payload.unwrap().tracer_payloads[0] + tracer_payload.unwrap().get_payloads()[0] ); } @@ -283,7 +283,7 @@ mod tests { }; assert_eq!( expected_tracer_payload, - tracer_payload.unwrap().tracer_payloads[0] + tracer_payload.unwrap().get_payloads()[0] ); } } diff --git a/trace-utils/src/trace_utils.rs b/trace-utils/src/trace_utils.rs index 105bd06f99..7fd10a4f1d 100644 --- a/trace-utils/src/trace_utils.rs +++ b/trace-utils/src/trace_utils.rs @@ -81,7 +81,12 @@ pub fn construct_tracer_payload( pub fn coalesce_send_data(mut data: Vec) -> Vec { // TODO trace payloads with identical data except for chunk could be merged? - data.sort_unstable_by(|a, b| a.get_target().url.to_string().cmp(&b.get_target().url.to_string())); + data.sort_unstable_by(|a, b| { + a.get_target() + .url + .to_string() + .cmp(&b.get_target().url.to_string()) + }); data.dedup_by(|a, b| { if a.get_target().url == b.get_target().url { // Size is only an approximation. In practice it won't vary much, but be safe here. diff --git a/trace-utils/src/tracer_header_tags.rs b/trace-utils/src/tracer_header_tags.rs index 899980f8dc..9c12281591 100644 --- a/trace-utils/src/tracer_header_tags.rs +++ b/trace-utils/src/tracer_header_tags.rs @@ -105,7 +105,10 @@ mod tests { assert_eq!(map.len(), 6); assert_eq!(map.get("datadog-meta-lang").unwrap(), "test-lang"); assert_eq!(map.get("datadog-meta-lang-version").unwrap(), "2.0"); - assert_eq!(map.get("datadog-meta-lang-interpreter").unwrap(), "interpreter"); + assert_eq!( + map.get("datadog-meta-lang-interpreter").unwrap(), + "interpreter" + ); assert_eq!(map.get("datadog-meta-lang-vendor").unwrap(), "vendor"); assert_eq!(map.get("datadog-meta-tracer-version").unwrap(), "1.0"); assert_eq!(map.get("datadog-container-id").unwrap(), "id"); @@ -128,7 +131,10 @@ mod tests { assert_eq!(map.len(), 5); assert_eq!(map.get("datadog-meta-lang").unwrap(), "test-lang"); assert_eq!(map.get("datadog-meta-lang-version").unwrap(), "2.0"); - assert_eq!(map.get("datadog-meta-lang-interpreter").unwrap(), "interpreter"); + assert_eq!( + map.get("datadog-meta-lang-interpreter").unwrap(), + "interpreter" + ); assert_eq!(map.get("datadog-meta-lang-vendor").unwrap(), "vendor"); assert_eq!(map.get("datadog-meta-tracer-version").unwrap(), "1.0"); assert_eq!(map.get("datadog-container-id"), None); @@ -140,7 +146,10 @@ mod tests { header_map.insert("datadog-meta-lang", "test-lang".parse().unwrap()); header_map.insert("datadog-meta-lang-version", "2.0".parse().unwrap()); - header_map.insert("datadog-meta-lang-interpreter", "interpreter".parse().unwrap()); + header_map.insert( + "datadog-meta-lang-interpreter", + "interpreter".parse().unwrap(), + ); header_map.insert("datadog-meta-lang-vendor", "vendor".parse().unwrap()); header_map.insert("datadog-meta-tracer-version", "1.0".parse().unwrap()); header_map.insert("datadog-container-id", "id".parse().unwrap());