Skip to content

Commit e6f8ad8

Browse files
feat(stats_exporter)!: add process tags to CSS payloads (#1709)
# What does this PR do? Add support for process tags in CSS payload. The process tags must be set at creation of the trace exporter and can't be updated without recreating the trace exporter # Motivation Process tags should be included in CSS payloads # Additional Notes This PR does not include setting the process tags on spans exporter by the stats exporter this can be done in the future but is out of the scope of this PR. # How to test the change? Added check for the process tags in unit tests. Co-authored-by: vianney.ruhlmann <vianney.ruhlmann@datadoghq.com>
1 parent c8a4b19 commit e6f8ad8

4 files changed

Lines changed: 60 additions & 4 deletions

File tree

libdd-data-pipeline-ffi/src/trace_exporter.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub struct TraceExporterConfig {
6565
client_computed_stats: bool,
6666
telemetry_cfg: Option<TelemetryConfig>,
6767
health_metrics_enabled: bool,
68+
process_tags: Option<String>,
6869
test_session_token: Option<String>,
6970
connection_timeout: Option<u64>,
7071
}
@@ -356,6 +357,26 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_client_computed_stats(
356357
)
357358
}
358359

360+
/// Sets the process tags to be included in the stats payload.
361+
#[no_mangle]
362+
pub unsafe extern "C" fn ddog_trace_exporter_config_set_process_tags(
363+
config: Option<&mut TraceExporterConfig>,
364+
process_tags: CharSlice,
365+
) -> Option<Box<ExporterError>> {
366+
catch_panic!(
367+
if let Option::Some(handle) = config {
368+
handle.process_tags = match sanitize_string(process_tags) {
369+
Ok(s) => Some(s),
370+
Err(e) => return Some(e),
371+
};
372+
None
373+
} else {
374+
gen_error!(ErrorCode::InvalidArgument)
375+
},
376+
gen_error!(ErrorCode::Panic)
377+
)
378+
}
379+
359380
/// Sets the `X-Datadog-Test-Session-Token` header. Only used for testing with the test agent.
360381
#[no_mangle]
361382
pub unsafe extern "C" fn ddog_trace_exporter_config_set_test_session_token(
@@ -423,6 +444,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_new(
423444
.set_env(config.env.as_ref().unwrap_or(&"".to_string()))
424445
.set_app_version(config.version.as_ref().unwrap_or(&"".to_string()))
425446
.set_service(config.service.as_ref().unwrap_or(&"".to_string()))
447+
.set_process_tags(config.process_tags.as_deref().unwrap_or(""))
426448
.set_input_format(config.input_format)
427449
.set_output_format(config.output_format)
428450
.set_connection_timeout(config.connection_timeout);
@@ -537,6 +559,7 @@ mod tests {
537559
assert!(!cfg.compute_stats);
538560
assert!(cfg.telemetry_cfg.is_none());
539561
assert!(!cfg.health_metrics_enabled);
562+
assert!(cfg.process_tags.is_none());
540563
assert!(cfg.test_session_token.is_none());
541564
assert!(cfg.connection_timeout.is_none());
542565

@@ -726,6 +749,27 @@ mod tests {
726749
}
727750
}
728751

752+
#[test]
753+
fn config_process_tags_test() {
754+
unsafe {
755+
let error = ddog_trace_exporter_config_set_process_tags(None, CharSlice::from("k:v"));
756+
assert_eq!(error.as_ref().unwrap().code, ErrorCode::InvalidArgument);
757+
758+
ddog_trace_exporter_error_free(error);
759+
760+
let mut config = Some(TraceExporterConfig::default());
761+
let error = ddog_trace_exporter_config_set_process_tags(
762+
config.as_mut(),
763+
CharSlice::from("key1:val1,key2:val2"),
764+
);
765+
766+
assert_eq!(error, None);
767+
768+
let cfg = config.unwrap();
769+
assert_eq!(cfg.process_tags.as_ref().unwrap(), "key1:val1,key2:val2");
770+
}
771+
}
772+
729773
#[test]
730774
fn config_client_computed_stats_test() {
731775
unsafe {

libdd-data-pipeline/src/stats_exporter.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ fn encode_stats_payload(
168168
sequence,
169169
stats: buckets,
170170
git_commit_sha: meta.git_commit_sha.clone(),
171+
process_tags: meta.process_tags.clone(),
171172
// These fields are unused or will be set by the Agent
172173
service: String::new(),
173174
container_id: String::new(),
174175
tags: Vec::new(),
175176
agent_aggregation: String::new(),
176177
image_tag: String::new(),
177-
process_tags: String::new(),
178178
process_tags_hash: 0,
179179
}
180180
}
@@ -217,6 +217,7 @@ mod tests {
217217
language: "rust".into(),
218218
tracer_version: "0.0.0".into(),
219219
runtime_id: "e39d6d12-0752-489f-b488-cf80006c0378".into(),
220+
process_tags: "key1:value1,key2:value2".into(),
220221
..Default::default()
221222
}
222223
}
@@ -257,7 +258,8 @@ mod tests {
257258
when.method(POST)
258259
.header("Content-type", "application/msgpack")
259260
.path("/v0.6/stats")
260-
.body_includes("libdatadog-test");
261+
.body_includes("libdatadog-test")
262+
.body_includes("key1:value1,key2:value2");
261263
then.status(200).body("");
262264
})
263265
.await;
@@ -318,7 +320,8 @@ mod tests {
318320
when.method(POST)
319321
.header("Content-type", "application/msgpack")
320322
.path("/v0.6/stats")
321-
.body_includes("libdatadog-test");
323+
.body_includes("libdatadog-test")
324+
.body_includes("key1:value1,key2:value2");
322325
then.status(200).body("");
323326
})
324327
.await;
@@ -356,7 +359,8 @@ mod tests {
356359
when.method(POST)
357360
.header("Content-type", "application/msgpack")
358361
.path("/v0.6/stats")
359-
.body_includes("libdatadog-test");
362+
.body_includes("libdatadog-test")
363+
.body_includes("key1:value1,key2:value2");
360364
then.status(200).body("");
361365
})
362366
.await;

libdd-data-pipeline/src/trace_exporter/builder.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub struct TraceExporterBuilder {
3434
language_interpreter: String,
3535
language_interpreter_vendor: String,
3636
git_commit_sha: String,
37+
process_tags: String,
3738
input_format: TraceExporterInputFormat,
3839
output_format: TraceExporterOutputFormat,
3940
dogstatsd_url: Option<String>,
@@ -111,6 +112,11 @@ impl TraceExporterBuilder {
111112
self
112113
}
113114

115+
pub fn set_process_tags(&mut self, process_tags: &str) -> &mut Self {
116+
process_tags.clone_into(&mut self.process_tags);
117+
self
118+
}
119+
114120
/// Set the `Datadog-Meta-Tracer-Version` header
115121
pub fn set_tracer_version(&mut self, tracer_version: &str) -> &mut Self {
116122
tracer_version.clone_into(&mut self.tracer_version);
@@ -309,6 +315,7 @@ impl TraceExporterBuilder {
309315
language_interpreter_vendor: self.language_interpreter_vendor,
310316
language: self.language,
311317
git_commit_sha: self.git_commit_sha,
318+
process_tags: self.process_tags,
312319
client_computed_stats: self.client_computed_stats,
313320
client_computed_top_level: self.client_computed_top_level,
314321
hostname: self.hostname,

libdd-data-pipeline/src/trace_exporter/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ pub struct TracerMetadata {
128128
pub language_interpreter: String,
129129
pub language_interpreter_vendor: String,
130130
pub git_commit_sha: String,
131+
pub process_tags: String,
131132
pub client_computed_stats: bool,
132133
pub client_computed_top_level: bool,
133134
}

0 commit comments

Comments
 (0)