agent_data_plane_config/domains/
traces.rs

1//! Traces domain: APM trace processing, including environment, sampling, and obfuscation.
2
3use serde::Serialize;
4
5use crate::defaults::{
6    DEFAULT_ERROR_SAMPLING_ENABLED, DEFAULT_RARE_SAMPLER_CARDINALITY, DEFAULT_RARE_SAMPLER_COOLDOWN_SECS,
7    DEFAULT_RARE_SAMPLER_TPS, DEFAULT_TRACE_ENV,
8};
9
10/// Resolved traces configuration.
11#[derive(Clone, Debug, PartialEq, Serialize)]
12pub struct Domain {
13    /// Environment tag applied to traces.
14    pub env: String,
15
16    /// Environment used for traces that carry no explicit environment. (not in Datadog Agent config
17    /// schema)
18    pub default_env: String,
19
20    /// Whether trace stats are computed separately per span kind.
21    pub compute_stats_by_span_kind: bool,
22
23    /// Span tags promoted to peer tags for peer-service aggregation.
24    pub peer_tags: Vec<String>,
25
26    /// Whether stats are aggregated by peer tags.
27    pub peer_tags_aggregation: bool,
28
29    /// Whether error spans are sampled independently of the base sampler. (not in Datadog Agent
30    /// config schema)
31    pub error_sampling_enabled: bool,
32
33    /// Whether error tracking runs standalone, without full trace ingestion.
34    pub error_tracking_standalone_enabled: bool,
35
36    /// Target number of error traces sampled per second.
37    pub errors_per_second: f64,
38
39    /// Target number of traces sampled per second.
40    pub target_traces_per_second: f64,
41
42    /// Whether the rare-span sampler is enabled.
43    pub enable_rare_sampler: bool,
44
45    /// Rare-span sampler settings.
46    pub rare_sampler: RareSampler,
47
48    /// Probabilistic sampler settings.
49    pub probabilistic_sampler: ProbabilisticSampler,
50
51    /// Per-subsystem trace obfuscation settings.
52    pub obfuscation: Obfuscation,
53
54    /// OTTL span-drop filter settings.
55    pub ottl_filter: OttlFilter,
56
57    /// OTTL span-transform settings.
58    pub ottl_transform: OttlTransform,
59}
60
61impl Default for Domain {
62    fn default() -> Self {
63        Self {
64            // Witnessed fields start as placeholders and are overwritten by Datadog `drive`.
65            env: String::new(),
66            compute_stats_by_span_kind: false,
67            peer_tags: Vec::new(),
68            peer_tags_aggregation: false,
69            error_tracking_standalone_enabled: false,
70            errors_per_second: 0.0,
71            target_traces_per_second: 0.0,
72            enable_rare_sampler: false,
73            probabilistic_sampler: ProbabilisticSampler::default(),
74            obfuscation: Obfuscation::default(),
75            // Saluki-only fields own their absent-key behavior here.
76            default_env: DEFAULT_TRACE_ENV.to_owned(),
77            error_sampling_enabled: DEFAULT_ERROR_SAMPLING_ENABLED,
78            rare_sampler: RareSampler::default(),
79            ottl_filter: OttlFilter::default(),
80            ottl_transform: OttlTransform::default(),
81        }
82    }
83}
84
85/// Rare-span sampler.
86#[derive(Clone, Debug, PartialEq, Serialize)]
87pub struct RareSampler {
88    /// Maximum number of distinct span signatures tracked. (not in Datadog Agent config schema)
89    pub cardinality: usize,
90
91    /// Cooldown, in seconds, before a signature may be sampled again. (not in Datadog Agent config
92    /// schema)
93    pub cooldown: f64,
94
95    /// Target rare-span traces sampled per second. (not in Datadog Agent config schema)
96    pub tps: f64,
97}
98
99impl Default for RareSampler {
100    fn default() -> Self {
101        Self {
102            cardinality: DEFAULT_RARE_SAMPLER_CARDINALITY,
103            cooldown: DEFAULT_RARE_SAMPLER_COOLDOWN_SECS,
104            tps: DEFAULT_RARE_SAMPLER_TPS,
105        }
106    }
107}
108
109/// APM probabilistic sampler.
110#[derive(Clone, Debug, Default, PartialEq, Serialize)]
111pub struct ProbabilisticSampler {
112    /// Whether the probabilistic sampler is enabled.
113    pub enabled: bool,
114
115    /// Percentage of traces the probabilistic sampler keeps.
116    pub sampling_percentage: f64,
117}
118
119/// Trace obfuscation, one group per supported subsystem.
120#[derive(Clone, Debug, Default, PartialEq, Serialize)]
121pub struct Obfuscation {
122    /// Credit-card obfuscation in span metadata.
123    pub credit_cards: CreditCardObfuscation,
124
125    /// Elasticsearch query obfuscation.
126    pub elasticsearch: JsonQueryObfuscation,
127
128    /// HTTP path and query obfuscation.
129    pub http: HttpObfuscation,
130
131    /// Memcached command obfuscation.
132    pub memcached: MemcachedObfuscation,
133
134    /// MongoDB query obfuscation.
135    pub mongodb: JsonQueryObfuscation,
136
137    /// OpenSearch query obfuscation.
138    pub opensearch: JsonQueryObfuscation,
139
140    /// Redis command obfuscation.
141    pub redis: CacheObfuscation,
142
143    /// Valkey command obfuscation.
144    pub valkey: CacheObfuscation,
145
146    /// SQL query obfuscation. (not in Datadog Agent config schema)
147    pub sql: SqlObfuscation,
148}
149
150/// Credit-card obfuscation.
151#[derive(Clone, Debug, Default, PartialEq, Serialize)]
152pub struct CreditCardObfuscation {
153    /// Whether credit-card numbers are obfuscated.
154    pub enabled: bool,
155
156    /// Tag or field names whose values are not obfuscated.
157    pub keep_values: Vec<String>,
158
159    /// Whether a Luhn check is applied before a value is treated as a card number.
160    pub luhn: bool,
161}
162
163/// Obfuscation shape shared by the JSON-query engines (Elasticsearch, MongoDB, OpenSearch).
164#[derive(Clone, Debug, Default, PartialEq, Serialize)]
165pub struct JsonQueryObfuscation {
166    /// Whether queries are obfuscated.
167    pub enabled: bool,
168
169    /// JSON keys whose values are not obfuscated.
170    pub keep_values: Vec<String>,
171
172    /// JSON keys whose values are obfuscated as embedded SQL.
173    pub obfuscate_sql_values: Vec<String>,
174}
175
176/// HTTP path/query obfuscation.
177#[derive(Clone, Debug, Default, PartialEq, Serialize)]
178pub struct HttpObfuscation {
179    /// Whether path segments containing digits are removed.
180    pub remove_paths_with_digits: bool,
181
182    /// Whether the query string is removed.
183    pub remove_query_string: bool,
184}
185
186/// Memcached command obfuscation.
187#[derive(Clone, Debug, Default, PartialEq, Serialize)]
188pub struct MemcachedObfuscation {
189    /// Whether Memcached commands are obfuscated.
190    pub enabled: bool,
191
192    /// Whether the command verb is preserved.
193    pub keep_command: bool,
194}
195
196/// Obfuscation shape shared by the key/value caches (redis, valkey).
197#[derive(Clone, Debug, Default, PartialEq, Serialize)]
198pub struct CacheObfuscation {
199    /// Whether cache commands are obfuscated.
200    pub enabled: bool,
201
202    /// Whether all command arguments are removed.
203    pub remove_all_args: bool,
204}
205
206/// SQL obfuscation.
207#[derive(Clone, Debug, Default, PartialEq, Serialize)]
208pub struct SqlObfuscation {
209    /// SQL dialect the obfuscator parses against.
210    pub dbms: String,
211
212    /// Whether dollar-quoted function bodies are preserved.
213    pub dollar_quoted_func: bool,
214
215    /// Whether column and table aliases are preserved.
216    pub keep_sql_alias: bool,
217
218    /// Whether digits in identifiers are replaced with a placeholder.
219    pub replace_digits: bool,
220
221    /// Whether table names are collected as metadata.
222    pub table_names: bool,
223}
224
225/// Error-handling mode for OTTL condition/statement evaluation, shared by the OTTL filter and
226/// transform processors.
227#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize)]
228pub enum OttlErrorMode {
229    /// Log evaluation errors and continue.
230    Ignore,
231    /// Swallow evaluation errors silently and continue.
232    Silent,
233    /// Propagate the error up the pipeline; the payload is dropped.
234    #[default]
235    Propagate,
236}
237
238/// OTTL filter processor: span-drop conditions applied during trace enrichment.
239#[derive(Clone, Debug, Default, PartialEq, Serialize)]
240pub struct OttlFilter {
241    /// How evaluation errors in the filter conditions are handled. (not in Datadog Agent config
242    /// schema)
243    pub error_mode: OttlErrorMode,
244
245    /// OTTL conditions; a span matching any of them is dropped. (not in Datadog Agent config
246    /// schema)
247    pub span_conditions: Vec<String>,
248}
249
250/// OTTL transform processor: span-mutating statements applied during trace enrichment.
251#[derive(Clone, Debug, Default, PartialEq, Serialize)]
252pub struct OttlTransform {
253    /// How evaluation errors in the transform statements are handled. (not in Datadog Agent config
254    /// schema)
255    pub error_mode: OttlErrorMode,
256
257    /// OTTL statements applied to each span. (not in Datadog Agent config schema)
258    pub trace_statements: Vec<String>,
259}