Skip to content

Commit 5b0d578

Browse files
authored
feat: [Trace Stats] Handle container_id and is_trace_root (#872)
## This PR Set two fields for trace stats: - container_id - is_trace_root For other fields not supported yet, change the comment from `TODO: handle this` to `Not supported yet` because I'm not sure if I will support them. We can do this when there's a need. ## Notes Jira: https://datadoghq.atlassian.net/browse/SVLS-7593
1 parent 210ca32 commit 5b0d578

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

bottlecap/src/traces/stats_concentrator.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub struct AggregationKey {
2323
pub resource: String,
2424
// e.g. "serverless"
2525
pub r#type: String,
26+
pub is_trace_root: bool,
2627
}
2728

2829
// Aggregated stats for a time interval across all the aggregation keys.
@@ -49,6 +50,7 @@ pub struct TracerMetadata {
4950
pub tracer_version: String,
5051
// e.g. "f45568ad09d5480b99087d86ebda26e6"
5152
pub runtime_id: String,
53+
pub container_id: String,
5254
}
5355

5456
pub struct StatsConcentrator {
@@ -161,18 +163,17 @@ impl StatsConcentrator {
161163
lang: tracer_metadata.language.clone(),
162164
tracer_version: tracer_metadata.tracer_version.clone(),
163165
runtime_id: tracer_metadata.runtime_id.clone(),
164-
// TODO: handle this
166+
// Not supported yet
165167
sequence: 0,
166-
// TODO: handle this
168+
// Not supported yet
167169
agent_aggregation: String::new(),
168170
service: aggregation_key.service.clone(),
169-
// TODO: handle this
170-
container_id: String::new(),
171-
// TODO: handle this
171+
container_id: tracer_metadata.container_id.clone(),
172+
// Not supported yet
172173
tags: vec![],
173-
// TODO: handle this
174+
// Not supported yet
174175
git_commit_sha: String::new(),
175-
// TODO: handle this
176+
// Not supported yet
176177
image_tag: String::new(),
177178
stats: vec![pb::ClientStatsBucket {
178179
start: timestamp,
@@ -181,29 +182,32 @@ impl StatsConcentrator {
181182
service: aggregation_key.service.clone(),
182183
name: aggregation_key.name.clone(),
183184
resource: aggregation_key.resource.clone(),
184-
// TODO: handle this
185+
// Not supported yet
185186
http_status_code: 0,
186187
r#type: aggregation_key.r#type.clone(),
187-
// TODO: handle this
188+
// Reserved field, not currently used by tracers
188189
db_type: String::new(),
189190
hits: stats.hits.try_into().unwrap_or_default(),
190191
errors: stats.errors.try_into().unwrap_or_default(),
191192
duration: stats.duration.try_into().unwrap_or_default(),
192-
// TODO: handle this
193+
// Not supported yet
193194
ok_summary: vec![],
194-
// TODO: handle this
195+
// Not supported yet
195196
error_summary: vec![],
196-
// TODO: handle this
197+
// Not supported yet
197198
synthetics: false,
198199
top_level_hits: stats.top_level_hits.round() as u64,
199-
// TODO: handle this
200+
// Not supported yet
200201
span_kind: String::new(),
201-
// TODO: handle this
202+
// Not supported yet
202203
peer_tags: vec![],
203-
// TODO: handle this
204-
is_trace_root: 1,
204+
is_trace_root: if aggregation_key.is_trace_root {
205+
pb::Trilean::True.into()
206+
} else {
207+
pb::Trilean::False.into()
208+
},
205209
}],
206-
// TODO: handle this
210+
// Not supported yet
207211
agent_time_shift: 0,
208212
}],
209213
}

bottlecap/src/traces/stats_concentrator_service.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ impl StatsConcentratorHandle {
6363
language: trace.language_name.clone(),
6464
tracer_version: trace.tracer_version.clone(),
6565
runtime_id: trace.runtime_id.clone(),
66+
container_id: trace.container_id.clone(),
6667
};
6768
self.tx
6869
.send(ConcentratorCommand::SetTracerMetadata(tracer_metadata))

bottlecap/src/traces/stats_generator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl StatsGenerator {
4848
name: span.name.clone(),
4949
resource: span.resource.clone(),
5050
r#type: span.r#type.clone(),
51+
is_trace_root: span.parent_id == 0,
5152
},
5253
stats: Stats {
5354
hits: 1,

0 commit comments

Comments
 (0)