Skip to content

Commit

Permalink
Add 'src_library' tag to metrics collect in the sidecar.
Browse files Browse the repository at this point in the history
  • Loading branch information
hoolioh committed May 30, 2024
1 parent 872637c commit bf33702
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
33 changes: 24 additions & 9 deletions sidecar/src/self_telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
],
));
}

Expand Down
4 changes: 2 additions & 2 deletions trace-mini-agent/src/trace_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ mod tests {

assert_eq!(
expected_tracer_payload,
tracer_payload.unwrap().tracer_payloads[0]
tracer_payload.unwrap().get_payloads()[0]
);
}

Expand Down Expand Up @@ -283,7 +283,7 @@ mod tests {
};
assert_eq!(
expected_tracer_payload,
tracer_payload.unwrap().tracer_payloads[0]
tracer_payload.unwrap().get_payloads()[0]
);
}
}
7 changes: 6 additions & 1 deletion trace-utils/src/trace_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ pub fn construct_tracer_payload(
pub fn coalesce_send_data(mut data: Vec<SendData>) -> Vec<SendData> {
// 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.
Expand Down
15 changes: 12 additions & 3 deletions trace-utils/src/tracer_header_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
Expand All @@ -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());
Expand Down

0 comments on commit bf33702

Please sign in to comment.