Skip to content

Commit 75fc8de

Browse files
authored
fix(metrics): Apply global tags to transaction metrics (#3615)
Prerequisite to getsentry/sentry#71004: Global tag mappings were not yet being applied to transaction metrics. Beside the bug fix, this PR also bumps the metrics extraction version(s), and attempts to simplify the extraction function for transactions.
1 parent 3aa4991 commit 75fc8de

File tree

7 files changed

+977
-104
lines changed

7 files changed

+977
-104
lines changed

CHANGELOG.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,27 @@
22

33
## Unreleased
44

5+
**Bug fixes**:
6+
7+
- Apply globally defined metric tags to legacy transaction metrics. ([#3615](https://github.com/getsentry/relay/pull/3615))
8+
9+
**Features**:
10+
11+
- Apply legacy inbound filters to standalone spans. ([#3552](https://github.com/getsentry/relay/pull/3552))
12+
513
**Internal**:
614

15+
- Send microsecond precision timestamps. ([#3613](https://github.com/getsentry/relay/pull/3613))
716
- Map outcome reasons for dynamic sampling to reduced set of values. ([#3623](https://github.com/getsentry/relay/pull/3623))
17+
- Extract status for spans. ([#3606](https://github.com/getsentry/relay/pull/3606))
818

919
## 24.5.0
1020

1121
**Breaking Changes**:
1222

1323
- Remove the AWS lambda extension. ([#3568](https://github.com/getsentry/relay/pull/3568))
1424

15-
**Bug fixes:**
25+
**Bug fixes**:
1626

1727
- Properly handle AI metrics from the Python SDK's `@ai_track` decorator. ([#3539](https://github.com/getsentry/relay/pull/3539))
1828
- Mitigate occasional slowness and timeouts of the healthcheck endpoint. The endpoint will now respond promptly an unhealthy state. ([#3567](https://github.com/getsentry/relay/pull/3567))
@@ -22,10 +32,6 @@
2232
- Apple trace-based sampling rules to standalone spans. ([#3476](https://github.com/getsentry/relay/pull/3476))
2333
- Localhost inbound filter filters sudomains of localhost. ([#3608](https://github.com/getsentry/relay/pull/3608))
2434

25-
**Features**:
26-
27-
- Apply legacy inbound filters to standalone spans. ([#3552](https://github.com/getsentry/relay/pull/3552))
28-
2935
**Internal**:
3036

3137
- Add metrics extraction config to global config. ([#3490](https://github.com/getsentry/relay/pull/3490), [#3504](https://github.com/getsentry/relay/pull/3504))
@@ -43,18 +49,16 @@
4349
- Add a calculated measurement based on the AI model and the tokens used. ([#3554](https://github.com/getsentry/relay/pull/3554))
4450
- Restrict usage of OTel endpoint. ([#3597](github.com/getsentry/relay/pull/3597))
4551
- Support new cache span ops in metrics and tag extraction. ([#3598](https://github.com/getsentry/relay/pull/3598))
46-
- Send microsecond precision timestamps. ([#3613](https://github.com/getsentry/relay/pull/3613))
4752
- Extract additional user fields for spans. ([#3599](https://github.com/getsentry/relay/pull/3599))
4853
- Disable `db.redis` span metrics extraction. ([#3600](https://github.com/getsentry/relay/pull/3600))
49-
- Extract status for spans. ([#3606](https://github.com/getsentry/relay/pull/3606))
5054

5155
## 24.4.2
5256

5357
**Breaking Changes**:
5458

5559
- Stop supporting dynamic sampling mode `"total"`, which adjusted for the client sample rate. ([#3474](https://github.com/getsentry/relay/pull/3474))
5660

57-
**Bug fixes:**
61+
**Bug fixes**:
5862

5963
- Respect country code TLDs when scrubbing span tags. ([#3458](https://github.com/getsentry/relay/pull/3458))
6064
- Extract HTTP status code from span data when sent as integers. ([#3491](https://github.com/getsentry/relay/pull/3491))

relay-dynamic-config/src/metrics.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ pub struct CustomMeasurementConfig {
115115
/// - Delay metrics extraction for indexed transactions.
116116
/// - 4: Adds support for `RuleConfigs` with string comparisons.
117117
/// - 5: No change, bumped together with [`MetricExtractionConfig::MAX_SUPPORTED_VERSION`].
118-
const TRANSACTION_EXTRACT_MAX_SUPPORTED_VERSION: u16 = 5;
118+
/// - 6: Bugfix to make transaction metrics extraction apply globally defined tag mappings.
119+
const TRANSACTION_EXTRACT_MAX_SUPPORTED_VERSION: u16 = 6;
119120

120121
/// Deprecated. Defines whether URL transactions should be considered low cardinality.
121122
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
@@ -324,7 +325,7 @@ impl MetricExtractionConfig {
324325
/// The latest version for this config struct.
325326
///
326327
/// This is the maximum version supported by this Relay instance.
327-
pub const MAX_SUPPORTED_VERSION: u16 = 3;
328+
pub const MAX_SUPPORTED_VERSION: u16 = 4;
328329

329330
/// Returns an empty `MetricExtractionConfig` with the latest version.
330331
///

relay-server/src/metrics_extraction/transactions/mod.rs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::{BTreeMap, BTreeSet};
22

33
use relay_base_schema::events::EventType;
44
use relay_common::time::UnixTimestamp;
5-
use relay_dynamic_config::{TagMapping, TransactionMetricsConfig};
5+
use relay_dynamic_config::{CombinedMetricExtractionConfig, TransactionMetricsConfig};
66
use relay_event_normalization::utils as normalize_utils;
77
use relay_event_schema::protocol::{
88
AsPair, BrowserContext, Event, OsContext, PerformanceScoreContext, TraceContext,
@@ -247,7 +247,7 @@ impl ExtractedMetrics {
247247
/// A utility that extracts metrics from transactions.
248248
pub struct TransactionExtractor<'a> {
249249
pub config: &'a TransactionMetricsConfig,
250-
pub generic_tags: &'a [TagMapping],
250+
pub generic_config: Option<&'a CombinedMetricExtractionConfig<'a>>,
251251
pub transaction_from_dsc: Option<&'a str>,
252252
pub sampling_result: &'a SamplingResult,
253253
pub has_profile: bool,
@@ -469,8 +469,10 @@ impl TransactionExtractor<'_> {
469469

470470
// Apply shared tags from generic metric extraction. Transaction metrics will adopt generic
471471
// metric extraction, after which this is done automatically.
472-
generic::tmp_apply_tags(&mut metrics.project_metrics, event, self.generic_tags);
473-
generic::tmp_apply_tags(&mut metrics.sampling_metrics, event, self.generic_tags);
472+
if let Some(generic_config) = self.generic_config {
473+
generic::tmp_apply_tags(&mut metrics.project_metrics, event, generic_config.tags());
474+
generic::tmp_apply_tags(&mut metrics.sampling_metrics, event, generic_config.tags());
475+
}
474476

475477
Ok(metrics)
476478
}
@@ -500,7 +502,9 @@ fn get_measurement_rating(name: &str, value: f64) -> Option<String> {
500502

501503
#[cfg(test)]
502504
mod tests {
503-
use relay_dynamic_config::AcceptTransactionNames;
505+
use relay_dynamic_config::{
506+
AcceptTransactionNames, CombinedMetricExtractionConfig, MetricExtractionConfig, TagMapping,
507+
};
504508
use relay_event_normalization::{
505509
normalize_event, set_default_transaction_source, validate_event_timestamps,
506510
validate_transaction, BreakdownsConfig, CombinedMeasurementsConfig, EventValidationConfig,
@@ -620,7 +624,7 @@ mod tests {
620624

621625
let extractor = TransactionExtractor {
622626
config: &config,
623-
generic_tags: &[],
627+
generic_config: None,
624628
transaction_from_dsc: Some("test_transaction"),
625629
sampling_result: &SamplingResult::Pending,
626630
has_profile: false,
@@ -981,7 +985,7 @@ mod tests {
981985
let config = TransactionMetricsConfig::default();
982986
let extractor = TransactionExtractor {
983987
config: &config,
984-
generic_tags: &[],
988+
generic_config: None,
985989
transaction_from_dsc: Some("test_transaction"),
986990
sampling_result: &SamplingResult::Pending,
987991
has_profile: false,
@@ -1150,7 +1154,7 @@ mod tests {
11501154
let config: TransactionMetricsConfig = TransactionMetricsConfig::default();
11511155
let extractor = TransactionExtractor {
11521156
config: &config,
1153-
generic_tags: &[],
1157+
generic_config: None,
11541158
transaction_from_dsc: Some("test_transaction"),
11551159
sampling_result: &SamplingResult::Pending,
11561160
has_profile: false,
@@ -1296,7 +1300,7 @@ mod tests {
12961300
let config = TransactionMetricsConfig::default();
12971301
let extractor = TransactionExtractor {
12981302
config: &config,
1299-
generic_tags: &[],
1303+
generic_config: None,
13001304
transaction_from_dsc: Some("test_transaction"),
13011305
sampling_result: &SamplingResult::Pending,
13021306
has_profile: false,
@@ -1371,7 +1375,7 @@ mod tests {
13711375
let config = TransactionMetricsConfig::default();
13721376
let extractor = TransactionExtractor {
13731377
config: &config,
1374-
generic_tags: &[],
1378+
generic_config: None,
13751379
transaction_from_dsc: Some("test_transaction"),
13761380
sampling_result: &SamplingResult::Pending,
13771381
has_profile: false,
@@ -1530,7 +1534,7 @@ mod tests {
15301534
let config = TransactionMetricsConfig::default();
15311535
let extractor = TransactionExtractor {
15321536
config: &config,
1533-
generic_tags: &[],
1537+
generic_config: None,
15341538
transaction_from_dsc: Some("test_transaction"),
15351539
sampling_result: &SamplingResult::Pending,
15361540
has_profile: false,
@@ -1569,7 +1573,7 @@ mod tests {
15691573
let config = TransactionMetricsConfig::default();
15701574
let extractor = TransactionExtractor {
15711575
config: &config,
1572-
generic_tags: &[],
1576+
generic_config: None,
15731577
transaction_from_dsc: Some("test_transaction"),
15741578
sampling_result: &SamplingResult::Pending,
15751579
has_profile: false,
@@ -1637,7 +1641,7 @@ mod tests {
16371641
let config = TransactionMetricsConfig::default();
16381642
let extractor = TransactionExtractor {
16391643
config: &config,
1640-
generic_tags: &[],
1644+
generic_config: None,
16411645
transaction_from_dsc: Some("test_transaction"),
16421646
sampling_result: &SamplingResult::Pending,
16431647
has_profile: false,
@@ -1740,7 +1744,7 @@ mod tests {
17401744
let config = TransactionMetricsConfig::default();
17411745
let extractor = TransactionExtractor {
17421746
config: &config,
1743-
generic_tags: &[],
1747+
generic_config: None,
17441748
transaction_from_dsc: Some("test_transaction"),
17451749
sampling_result: &SamplingResult::Pending,
17461750
has_profile: false,
@@ -1773,7 +1777,7 @@ mod tests {
17731777
let config = TransactionMetricsConfig::default();
17741778
let extractor = TransactionExtractor {
17751779
config: &config,
1776-
generic_tags: &[],
1780+
generic_config: None,
17771781
transaction_from_dsc: Some("test_transaction"),
17781782
sampling_result: &SamplingResult::Pending,
17791783
has_profile: false,
@@ -1810,7 +1814,7 @@ mod tests {
18101814
let config = TransactionMetricsConfig::default();
18111815
let extractor = TransactionExtractor {
18121816
config: &config,
1813-
generic_tags: &[],
1817+
generic_config: None,
18141818
transaction_from_dsc: Some("root_transaction"),
18151819
sampling_result: &SamplingResult::Pending,
18161820
has_profile: false,
@@ -2078,7 +2082,7 @@ mod tests {
20782082
let config = TransactionMetricsConfig::default();
20792083
let extractor = TransactionExtractor {
20802084
config: &config,
2081-
generic_tags: &[],
2085+
generic_config: None,
20822086
transaction_from_dsc: Some("test_transaction"),
20832087
sampling_result: &SamplingResult::Pending,
20842088
has_profile: false,
@@ -2170,10 +2174,16 @@ mod tests {
21702174
]"#,
21712175
)
21722176
.unwrap();
2177+
let generic_config = MetricExtractionConfig {
2178+
version: 1,
2179+
tags: generic_tags,
2180+
..Default::default()
2181+
};
2182+
let combined_config = CombinedMetricExtractionConfig::from(&generic_config);
21732183

21742184
let extractor = TransactionExtractor {
21752185
config: &config,
2176-
generic_tags: &generic_tags,
2186+
generic_config: Some(&combined_config),
21772187
transaction_from_dsc: Some("test_transaction"),
21782188
sampling_result: &SamplingResult::Pending,
21792189
has_profile: false,

0 commit comments

Comments
 (0)