Skip to content

Commit 4a6eed2

Browse files
authored
feat: [Trace Stats] Do not set ClientStatsPayload.hostname (#905)
# This PR As APM Stats team suggested, `ClientStatsPayload.hostname` should be left empty so the trace stats backend can aggregate stats properly. # Testing Still some undercounting. Expecting 5000 for the `highvolume` (with concurrency) tests, but seeing 4xxx for some runtimes. Will keep investigating. <img width="1457" height="381" alt="Screenshot 2025-10-23 at 3 28 04 PM" src="https://github.com/user-attachments/assets/6bb1e231-49de-4924-a476-826fe1e645ff" /> <img width="1453" height="369" alt="Screenshot 2025-10-23 at 3 29 21 PM" src="https://github.com/user-attachments/assets/91dbd642-a637-41e3-be3f-88f83b4a022c" /> # Notes #688 https://datadoghq.atlassian.net/browse/SVLS-6907
1 parent cf23e14 commit 4a6eed2

3 files changed

Lines changed: 7 additions & 31 deletions

File tree

bottlecap/src/bin/bottlecap/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ fn start_trace_agent(
992992
) {
993993
// Stats
994994
let (stats_concentrator_service, stats_concentrator_handle) =
995-
StatsConcentratorService::new(Arc::clone(config), tags_provider.clone());
995+
StatsConcentratorService::new(Arc::clone(config));
996996
tokio::spawn(stats_concentrator_service.run());
997997
let stats_aggregator: Arc<TokioMutex<StatsAggregator>> = Arc::new(TokioMutex::new(
998998
StatsAggregator::new_with_concentrator(stats_concentrator_handle.clone()),

bottlecap/src/traces/stats_aggregator.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,14 @@ impl StatsAggregator {
9191
#[allow(clippy::unwrap_used)]
9292
mod tests {
9393
use super::*;
94-
use crate::LAMBDA_RUNTIME_SLUG;
9594
use crate::config::Config;
96-
use crate::tags::provider::Provider as TagProvider;
9795
use crate::traces::stats_concentrator_service::StatsConcentratorService;
98-
use std::collections::HashMap;
9996
use std::sync::Arc;
10097

10198
#[test]
10299
fn test_add() {
103100
let config = Arc::new(Config::default());
104-
let tags_provider = Arc::new(TagProvider::new(
105-
config.clone(),
106-
LAMBDA_RUNTIME_SLUG.to_string(),
107-
&HashMap::new(),
108-
));
109-
let (_, concentrator) = StatsConcentratorService::new(config, tags_provider);
101+
let (_, concentrator) = StatsConcentratorService::new(config);
110102
let mut aggregator = StatsAggregator::new_with_concentrator(concentrator);
111103
let payload = ClientStatsPayload {
112104
hostname: "hostname".to_string(),
@@ -135,12 +127,7 @@ mod tests {
135127
#[tokio::test]
136128
async fn test_get_batch() {
137129
let config = Arc::new(Config::default());
138-
let tags_provider = Arc::new(TagProvider::new(
139-
config.clone(),
140-
LAMBDA_RUNTIME_SLUG.to_string(),
141-
&HashMap::new(),
142-
));
143-
let (_, concentrator) = StatsConcentratorService::new(config, tags_provider);
130+
let (_, concentrator) = StatsConcentratorService::new(config);
144131
let mut aggregator = StatsAggregator::new_with_concentrator(concentrator);
145132
let payload = ClientStatsPayload {
146133
hostname: "hostname".to_string(),
@@ -169,12 +156,7 @@ mod tests {
169156
#[tokio::test]
170157
async fn test_get_batch_full_entries() {
171158
let config = Arc::new(Config::default());
172-
let tags_provider = Arc::new(TagProvider::new(
173-
config.clone(),
174-
LAMBDA_RUNTIME_SLUG.to_string(),
175-
&HashMap::new(),
176-
));
177-
let (_, concentrator) = StatsConcentratorService::new(config, tags_provider);
159+
let (_, concentrator) = StatsConcentratorService::new(config);
178160
let mut aggregator = StatsAggregator::new(704, concentrator);
179161
// Payload below is 352 bytes
180162
let payload = ClientStatsPayload {

bottlecap/src/traces/stats_concentrator_service.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use tokio::sync::{mpsc, oneshot};
22

33
use crate::config::Config;
4-
use crate::tags::provider::Provider as TagProvider;
54
use datadog_trace_protobuf::pb;
65
use datadog_trace_protobuf::pb::{ClientStatsPayload, TracerPayload};
76
use datadog_trace_stats::span_concentrator::SpanConcentrator;
@@ -104,18 +103,14 @@ pub struct StatsConcentratorService {
104103
concentrator: SpanConcentrator,
105104
rx: mpsc::UnboundedReceiver<ConcentratorCommand>,
106105
tracer_metadata: TracerMetadata,
107-
hostname: String,
108106
config: Arc<Config>,
109107
}
110108

111109
// A service that handles add() and flush() requests in the same queue,
112110
// to avoid using mutex, which may cause lock contention.
113111
impl StatsConcentratorService {
114112
#[must_use]
115-
pub fn new(
116-
config: Arc<Config>,
117-
tags_provider: Arc<TagProvider>,
118-
) -> (Self, StatsConcentratorHandle) {
113+
pub fn new(config: Arc<Config>) -> (Self, StatsConcentratorHandle) {
119114
let (tx, rx) = mpsc::unbounded_channel();
120115
let handle = StatsConcentratorHandle::new(tx);
121116
// TODO: set span_kinds_stats_computed and peer_tag_keys
@@ -125,13 +120,11 @@ impl StatsConcentratorService {
125120
vec![],
126121
vec![],
127122
);
128-
let hostname = tags_provider.get_canonical_id().unwrap_or_default();
129123
let service: StatsConcentratorService = Self {
130124
concentrator,
131125
rx,
132126
// To be set when the first trace is received
133127
tracer_metadata: TracerMetadata::default(),
134-
hostname,
135128
config,
136129
};
137130
(service, handle)
@@ -161,7 +154,8 @@ impl StatsConcentratorService {
161154
None
162155
} else {
163156
Some(ClientStatsPayload {
164-
hostname: self.hostname.clone(),
157+
// Do not set hostname so the trace stats backend can aggregate stats properly
158+
hostname: String::new(),
165159
env: self.config.env.clone().unwrap_or("unknown-env".to_string()),
166160
// Version is not in the trace payload. Need to read it from config.
167161
version: self.config.version.clone().unwrap_or_default(),

0 commit comments

Comments
 (0)