Skip to main content

relay_dynamic_config/
metrics.rs

1//! Dynamic configuration for metrics extraction from sessions.
2
3use serde::{Deserialize, Serialize};
4
5/// Current version of metrics extraction.
6const SESSION_EXTRACT_VERSION: u16 = 3;
7const EXTRACT_ABNORMAL_MECHANISM_VERSION: u16 = 2;
8
9/// Configuration for metric extraction from sessions.
10#[derive(Debug, Clone, Copy, Default, Deserialize, Serialize)]
11#[serde(default, rename_all = "camelCase")]
12pub struct SessionMetricsConfig {
13    /// The revision of the extraction algorithm.
14    ///
15    /// Provided the revision is lower than or equal to the revision supported by this Relay,
16    /// metrics are extracted. If the revision is higher than what this Relay supports, it does not
17    /// extract metrics from sessions, and instead forwards them to the upstream.
18    ///
19    /// Version `0` (default) disables extraction.
20    version: u16,
21}
22
23impl SessionMetricsConfig {
24    /// Returns `true` if session metrics is enabled and compatible.
25    pub fn is_enabled(&self) -> bool {
26        self.version > 0 && self.version <= SESSION_EXTRACT_VERSION
27    }
28
29    /// Returns `true` if Relay should not extract metrics from sessions.
30    pub fn is_disabled(&self) -> bool {
31        !self.is_enabled()
32    }
33
34    /// Whether or not the abnormal mechanism should be extracted as a tag.
35    pub fn should_extract_abnormal_mechanism(&self) -> bool {
36        self.version >= EXTRACT_ABNORMAL_MECHANISM_VERSION
37    }
38}
39
40/// Configuration for extracting custom measurements from transaction payloads.
41#[derive(Default, Debug, Clone, Serialize, Deserialize)]
42#[serde(default, rename_all = "camelCase")]
43pub struct CustomMeasurementConfig {
44    /// The maximum number of custom measurements to extract. Defaults to zero.
45    limit: usize,
46}