-
Notifications
You must be signed in to change notification settings - Fork 19
feat!: integrate obfuscation to the stats exporter [APMSP-2764] #1819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c23938d
f2621f3
6659152
0602070
d41ad73
36cca8f
1ffcde1
02ab474
0994585
5a40e9a
4eb0aa3
50c0469
e7b04a6
1567e34
edd4a19
a7dc804
1723dc2
f758d03
0d3da7b
3808360
3e8388f
3feddef
fd1a97e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,8 @@ use libdd_capabilities::{HttpClientTrait, MaybeSend}; | |||||||
| use libdd_common::Endpoint; | ||||||||
| use libdd_shared_runtime::Worker; | ||||||||
| use libdd_trace_protobuf::pb; | ||||||||
| #[cfg(feature = "stats-obfuscation")] | ||||||||
| use libdd_trace_stats::span_concentrator::SharedStatsComputationObfuscationConfig; | ||||||||
| use libdd_trace_stats::span_concentrator::SpanConcentrator; | ||||||||
| use libdd_trace_utils::send_with_retry::{send_with_retry, RetryStrategy}; | ||||||||
| use tracing::error; | ||||||||
|
|
@@ -34,6 +36,8 @@ pub struct StatsExporter<H: HttpClientTrait> { | |||||||
| meta: TracerMetadata, | ||||||||
| sequence_id: AtomicU64, | ||||||||
| client: H, | ||||||||
| #[cfg(feature = "stats-obfuscation")] | ||||||||
| obfuscation_config: SharedStatsComputationObfuscationConfig, | ||||||||
| } | ||||||||
|
|
||||||||
| impl<H: HttpClientTrait> StatsExporter<H> { | ||||||||
|
|
@@ -43,14 +47,14 @@ impl<H: HttpClientTrait> StatsExporter<H> { | |||||||
| /// - `concentrator` SpanConcentrator storing the stats to be sent to the agent | ||||||||
| /// - `meta` metadata used in ClientStatsPayload and as headers to send stats to the agent | ||||||||
| /// - `endpoint` the Endpoint used to send stats to the agent | ||||||||
| /// - `cancellation_token` Token used to safely shutdown the exporter by force flushing the | ||||||||
| /// concentrator | ||||||||
| pub fn new( | ||||||||
| flush_interval: time::Duration, | ||||||||
| concentrator: Arc<Mutex<SpanConcentrator>>, | ||||||||
| meta: TracerMetadata, | ||||||||
| endpoint: Endpoint, | ||||||||
| client: H, | ||||||||
| #[cfg(feature = "stats-obfuscation")] | ||||||||
| obfuscation_config: SharedStatsComputationObfuscationConfig, | ||||||||
| ) -> Self { | ||||||||
| Self { | ||||||||
| flush_interval, | ||||||||
|
|
@@ -59,6 +63,8 @@ impl<H: HttpClientTrait> StatsExporter<H> { | |||||||
| meta, | ||||||||
| sequence_id: AtomicU64::new(0), | ||||||||
| client, | ||||||||
| #[cfg(feature = "stats-obfuscation")] | ||||||||
| obfuscation_config, | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
|
|
@@ -91,6 +97,16 @@ impl<H: HttpClientTrait> StatsExporter<H> { | |||||||
| libdd_common::header::APPLICATION_MSGPACK, | ||||||||
| ); | ||||||||
|
|
||||||||
| #[cfg(feature = "stats-obfuscation")] | ||||||||
| if self.obfuscation_config.load().enabled { | ||||||||
| headers.insert( | ||||||||
| http::HeaderName::from_static("datadog-obfuscation-version"), | ||||||||
| http::HeaderValue::from_static( | ||||||||
| crate::trace_exporter::stats::SUPPORTED_OBFUSCATION_VERSION_STR, | ||||||||
| ), | ||||||||
| ); | ||||||||
| } | ||||||||
|
|
||||||||
| let result = send_with_retry( | ||||||||
| &self.client, | ||||||||
| &self.endpoint, | ||||||||
|
|
@@ -194,6 +210,8 @@ mod tests { | |||||||
| use httpmock::MockServer; | ||||||||
| use libdd_capabilities_impl::NativeCapabilities; | ||||||||
| use libdd_shared_runtime::SharedRuntime; | ||||||||
| #[cfg(feature = "stats-obfuscation")] | ||||||||
| use libdd_trace_stats::span_concentrator::StatsComputationObfuscationConfig; | ||||||||
| use libdd_trace_utils::span::{trace_utils, v04::SpanSlice}; | ||||||||
|
Eldolfin marked this conversation as resolved.
|
||||||||
| use libdd_trace_utils::test_utils::poll_for_mock_hit; | ||||||||
| use time::Duration; | ||||||||
|
|
@@ -231,6 +249,8 @@ mod tests { | |||||||
| SystemTime::now() - BUCKETS_DURATION * 3, | ||||||||
| vec![], | ||||||||
| vec![], | ||||||||
| #[cfg(feature = "stats-obfuscation")] | ||||||||
| None, | ||||||||
| ); | ||||||||
| let mut trace = vec![]; | ||||||||
|
|
||||||||
|
|
@@ -272,6 +292,8 @@ mod tests { | |||||||
| get_test_metadata(), | ||||||||
| Endpoint::from_url(stats_url_from_agent_url(&server.url("/")).unwrap()), | ||||||||
| NativeCapabilities::new_client(), | ||||||||
| #[cfg(feature = "stats-obfuscation")] | ||||||||
| StatsComputationObfuscationConfig::disabled(), | ||||||||
| ); | ||||||||
|
|
||||||||
| let send_status = stats_exporter.send(true).await; | ||||||||
|
|
@@ -299,6 +321,8 @@ mod tests { | |||||||
| get_test_metadata(), | ||||||||
| Endpoint::from_url(stats_url_from_agent_url(&server.url("/")).unwrap()), | ||||||||
| NativeCapabilities::new_client(), | ||||||||
|
||||||||
| NativeCapabilities::new_client(), | |
| NativeCapabilities::new_client(), | |
| #[cfg(feature = "stats-obfuscation")] |
Copilot
AI
Apr 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test passes StatsComputationObfuscationConfig::disabled() without a #[cfg(feature = "stats-obfuscation")] guard. When stats-obfuscation is off, StatsExporter::new won’t accept this extra argument and the test won’t compile; gate the argument (or the entire test) on the feature.
Copilot
AI
Apr 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test passes StatsComputationObfuscationConfig::disabled() without a #[cfg(feature = "stats-obfuscation")] guard. With the feature disabled, the call signature changes and this test won’t compile; wrap the argument in #[cfg(feature = "stats-obfuscation")] or cfg-gate the test.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -299,6 +299,11 @@ impl TraceExporterBuilder { | |
|
|
||
| #[cfg(not(target_arch = "wasm32"))] | ||
| { | ||
|
Eldolfin marked this conversation as resolved.
|
||
| #[cfg(feature = "stats-obfuscation")] | ||
| use libdd_trace_stats::span_concentrator::StatsComputationObfuscationConfig; | ||
|
|
||
| use crate::trace_exporter::stats::StatsComputationConfig; | ||
|
|
||
| let info_endpoint = Endpoint::from_url(add_path(&agent_url, INFO_ENDPOINT)); | ||
| let (info_fetcher, info_response_observer) = | ||
| AgentInfoFetcher::<H>::new(info_endpoint.clone(), Duration::from_secs(5 * 60)); | ||
|
|
@@ -378,7 +383,13 @@ impl TraceExporterBuilder { | |
| shared_runtime, | ||
| dogstatsd, | ||
| common_stats_tags: vec![libdatadog_version], | ||
| client_side_stats: ArcSwap::new(stats.into()), | ||
| client_side_stats: StatsComputationConfig { | ||
| status: ArcSwap::new(stats.into()), | ||
|
Eldolfin marked this conversation as resolved.
|
||
| #[cfg(feature = "stats-obfuscation")] | ||
| obfuscation_config: Arc::new(ArcSwap::from_pointee( | ||
| StatsComputationObfuscationConfig::default(), | ||
| )), | ||
|
Eldolfin marked this conversation as resolved.
|
||
| }, | ||
| previous_info_state: arc_swap::ArcSwapOption::new(None), | ||
| info_response_observer, | ||
| #[cfg(feature = "telemetry")] | ||
|
|
@@ -427,6 +438,11 @@ impl TraceExporterBuilder { | |
|
|
||
| #[cfg(target_arch = "wasm32")] | ||
| { | ||
| #[cfg(feature = "stats-obfuscation")] | ||
| use libdd_trace_stats::span_concentrator::StatsComputationObfuscationConfig; | ||
|
|
||
| use crate::trace_exporter::stats::StatsComputationConfig; | ||
|
|
||
| let info_endpoint = Endpoint::from_url(add_path(&agent_url, INFO_ENDPOINT)); | ||
| let (_info_fetcher, info_response_observer) = | ||
| AgentInfoFetcher::<H>::new(info_endpoint, Duration::from_secs(5 * 60)); | ||
|
|
@@ -462,7 +478,13 @@ impl TraceExporterBuilder { | |
| shared_runtime, | ||
| dogstatsd, | ||
| common_stats_tags: vec![libdatadog_version], | ||
| client_side_stats: ArcSwap::new(stats.into()), | ||
| client_side_stats: StatsComputationConfig { | ||
| status: ArcSwap::new(stats.into()), | ||
| #[cfg(feature = "stats-obfuscation")] | ||
| obfuscation_config: Arc::new(ArcSwap::from_pointee( | ||
| StatsComputationObfuscationConfig::default(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this only imported with the stats-obfuscation feature?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, |
||
| )), | ||
| }, | ||
| previous_info_state: arc_swap::ArcSwapOption::new(None), | ||
| info_response_observer, | ||
| health_metrics_enabled: self.health_metrics_enabled, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.