@@ -12,6 +12,21 @@ const fn default_target_traces_per_second() -> f64 {
1212const fn default_errors_per_second ( ) -> f64 {
1313 10.0
1414}
15+ const fn default_sampling_percentage ( ) -> f64 {
16+ 100.0
17+ }
18+
19+ const fn default_error_sampling_enabled ( ) -> bool {
20+ true
21+ }
22+
23+ const fn default_error_tracking_standalone_enabled ( ) -> bool {
24+ false
25+ }
26+
27+ const fn default_probabilistic_sampling_enabled ( ) -> bool {
28+ false
29+ }
1530const fn default_peer_tags_aggregation ( ) -> bool {
1631 true
1732}
@@ -33,6 +48,56 @@ struct ApmConfiguration {
3348 apm_config : ApmConfig ,
3449}
3550
51+ #[ derive( Clone , Debug , Deserialize ) ]
52+ struct ProbabilisticSamplerConfig {
53+ /// Enables probabilistic sampling.
54+ ///
55+ /// When enabled, the trace sampler keeps approximately `sampling_percentage` of traces using a
56+ /// deterministic hash of the trace ID.
57+ ///
58+ /// Defaults to `false`.
59+ #[ serde( default = "default_probabilistic_sampling_enabled" ) ]
60+ enabled : bool ,
61+
62+ /// Sampling percentage (0-100).
63+ ///
64+ /// Determines the percentage of traces to keep. A value of 100 keeps all traces,
65+ /// while 50 keeps approximately half. Values outside 0-100 are treated as 100.
66+ ///
67+ /// Defaults to 100.0 (keep all traces).
68+ #[ serde( default = "default_sampling_percentage" ) ]
69+ sampling_percentage : f64 ,
70+ }
71+
72+ impl Default for ProbabilisticSamplerConfig {
73+ fn default ( ) -> Self {
74+ Self {
75+ enabled : default_probabilistic_sampling_enabled ( ) ,
76+ sampling_percentage : default_sampling_percentage ( ) ,
77+ }
78+ }
79+ }
80+
81+ #[ derive( Clone , Debug , Deserialize ) ]
82+ struct ErrorTrackingStandaloneConfig {
83+ /// Enables Error Tracking Standalone mode.
84+ ///
85+ /// When enabled, error tracking standalone mode suppresses single-span sampling and analytics
86+ /// events for dropped traces.
87+ ///
88+ /// Defaults to `false`.
89+ #[ serde( default = "default_error_tracking_standalone_enabled" ) ]
90+ enabled : bool ,
91+ }
92+
93+ impl Default for ErrorTrackingStandaloneConfig {
94+ fn default ( ) -> Self {
95+ Self {
96+ enabled : default_error_tracking_standalone_enabled ( ) ,
97+ }
98+ }
99+ }
100+
36101#[ derive( Clone , Debug , Deserialize ) ]
37102pub struct ApmConfig {
38103 /// Target traces per second for priority sampling.
@@ -47,6 +112,27 @@ pub struct ApmConfig {
47112 #[ serde( default = "default_errors_per_second" ) ]
48113 errors_per_second : f64 ,
49114
115+ /// Probabilistic sampler configuration.
116+ ///
117+ /// Defaults to enabled with `sampling_percentage` set to 100.0 (keep all traces).
118+ #[ serde( default ) ]
119+ probabilistic_sampler : ProbabilisticSamplerConfig ,
120+
121+ /// Enable error sampling in the trace sampler.
122+ ///
123+ /// When enabled, traces containing errors will be kept even if they would be dropped by
124+ /// probabilistic sampling. This ensures error visibility at low sampling rates.
125+ ///
126+ /// Defaults to `true`.
127+ #[ serde( default = "default_error_sampling_enabled" ) ]
128+ error_sampling_enabled : bool ,
129+
130+ /// Error Tracking Standalone configuration.
131+ ///
132+ /// Defaults to disabled.
133+ #[ serde( default ) ]
134+ error_tracking_standalone : ErrorTrackingStandaloneConfig ,
135+
50136 /// Enables an additional stats computation check on spans to see if they have an eligible `span.kind` (server, consumer, client, producer).
51137 /// If enabled, a span with an eligible `span.kind` will have stats computed. If disabled, only top-level and measured spans will have stats computed.
52138 ///
@@ -100,6 +186,26 @@ impl ApmConfig {
100186 self . errors_per_second
101187 }
102188
189+ /// Returns if probabilistic sampling is enabled.
190+ pub const fn probabilistic_sampler_enabled ( & self ) -> bool {
191+ self . probabilistic_sampler . enabled
192+ }
193+
194+ /// Returns the probabilistic sampler sampling percentage.
195+ pub const fn probabilistic_sampler_sampling_percentage ( & self ) -> f64 {
196+ self . probabilistic_sampler . sampling_percentage
197+ }
198+
199+ /// Returns if error sampling is enabled.
200+ pub const fn error_sampling_enabled ( & self ) -> bool {
201+ self . error_sampling_enabled
202+ }
203+
204+ /// Returns if error tracking standalone mode is enabled.
205+ pub const fn error_tracking_standalone_enabled ( & self ) -> bool {
206+ self . error_tracking_standalone . enabled
207+ }
208+
103209 /// Returns if stats computation by span kind is enabled.
104210 pub const fn compute_stats_by_span_kind ( & self ) -> bool {
105211 self . compute_stats_by_span_kind
@@ -143,6 +249,9 @@ impl Default for ApmConfig {
143249 Self {
144250 target_traces_per_second : default_target_traces_per_second ( ) ,
145251 errors_per_second : default_errors_per_second ( ) ,
252+ probabilistic_sampler : ProbabilisticSamplerConfig :: default ( ) ,
253+ error_sampling_enabled : default_error_sampling_enabled ( ) ,
254+ error_tracking_standalone : ErrorTrackingStandaloneConfig :: default ( ) ,
146255 compute_stats_by_span_kind : default_compute_stats_by_span_kind ( ) ,
147256 peer_tags_aggregation : default_peer_tags_aggregation ( ) ,
148257 peer_tags : Vec :: new ( ) ,
0 commit comments