@@ -15,8 +15,8 @@ use relay_metrics::{AggregatorConfig, Metric, MetricNamespace, MetricValue};
15
15
16
16
use crate :: metrics_extraction:: conditional_tagging:: run_conditional_tagging;
17
17
use crate :: metrics_extraction:: transactions:: types:: {
18
- CommonTag , CommonTags , ExtractMetricsError , TransactionCPRTags , TransactionMeasurementTags ,
19
- TransactionMetric ,
18
+ CommonTag , CommonTags , ExtractMetricsError , TransactionCPRTags , TransactionDurationTags ,
19
+ TransactionMeasurementTags , TransactionMetric ,
20
20
} ;
21
21
use crate :: metrics_extraction:: IntoMetric ;
22
22
use crate :: statsd:: RelayCounters ;
@@ -334,17 +334,21 @@ pub fn extract_transaction_metrics(
334
334
event : & mut Event ,
335
335
transaction_from_dsc : Option < & str > ,
336
336
sampling_result : & SamplingResult ,
337
+ has_profile : bool ,
337
338
project_metrics : & mut Vec < Metric > , // output parameter
338
339
sampling_metrics : & mut Vec < Metric > , // output parameter
339
340
) -> Result < bool , ExtractMetricsError > {
340
341
let before_len = project_metrics. len ( ) ;
341
342
342
343
extract_transaction_metrics_inner (
343
- aggregator_config,
344
- config,
345
- event,
346
- transaction_from_dsc,
347
- sampling_result,
344
+ ExtractInput {
345
+ aggregator_config,
346
+ config,
347
+ event,
348
+ transaction_from_dsc,
349
+ sampling_result,
350
+ has_profile,
351
+ } ,
348
352
project_metrics,
349
353
sampling_metrics,
350
354
) ?;
@@ -358,15 +362,21 @@ pub fn extract_transaction_metrics(
358
362
Ok ( !added_slice. is_empty ( ) )
359
363
}
360
364
365
+ struct ExtractInput < ' a > {
366
+ aggregator_config : & ' a AggregatorConfig ,
367
+ config : & ' a TransactionMetricsConfig ,
368
+ event : & ' a Event ,
369
+ transaction_from_dsc : Option < & ' a str > ,
370
+ sampling_result : & ' a SamplingResult ,
371
+ has_profile : bool ,
372
+ }
373
+
361
374
fn extract_transaction_metrics_inner (
362
- aggregator_config : & AggregatorConfig ,
363
- config : & TransactionMetricsConfig ,
364
- event : & Event ,
365
- transaction_from_dsc : Option < & str > ,
366
- sampling_result : & SamplingResult ,
375
+ input : ExtractInput < ' _ > ,
367
376
metrics : & mut Vec < Metric > , // output parameter
368
377
sampling_metrics : & mut Vec < Metric > , // output parameter
369
378
) -> Result < ( ) , ExtractMetricsError > {
379
+ let event = input. event ;
370
380
if event. ty . value ( ) != Some ( & EventType :: Transaction ) {
371
381
return Ok ( ( ) ) ;
372
382
}
@@ -384,12 +394,16 @@ fn extract_transaction_metrics_inner(
384
394
// Validate the transaction event against the metrics timestamp limits. If the metric is too
385
395
// old or too new, we cannot extract the metric and also need to drop the transaction event
386
396
// for consistency between metrics and events.
387
- if !aggregator_config. timestamp_range ( ) . contains ( & timestamp) {
397
+ if !input
398
+ . aggregator_config
399
+ . timestamp_range ( )
400
+ . contains ( & timestamp)
401
+ {
388
402
relay_log:: debug!( "event timestamp is out of the valid range for metrics" ) ;
389
403
return Err ( ExtractMetricsError :: InvalidTimestamp ) ;
390
404
}
391
405
392
- let tags = extract_universal_tags ( event, config) ;
406
+ let tags = extract_universal_tags ( event, input . config ) ;
393
407
394
408
// Measurements
395
409
if let Some ( measurements) = event. measurements . value ( ) {
@@ -459,20 +473,23 @@ fn extract_transaction_metrics_inner(
459
473
TransactionMetric :: Duration {
460
474
unit : DurationUnit :: MilliSecond ,
461
475
value : relay_common:: chrono_to_positive_millis ( end - start) ,
462
- tags : tags. clone ( ) ,
476
+ tags : TransactionDurationTags {
477
+ has_profile : input. has_profile ,
478
+ universal_tags : tags. clone ( ) ,
479
+ } ,
463
480
}
464
481
. into_metric ( timestamp) ,
465
482
) ;
466
483
467
484
let root_counter_tags = {
468
485
let mut universal_tags = CommonTags ( BTreeMap :: default ( ) ) ;
469
- if let Some ( transaction_from_dsc) = transaction_from_dsc {
486
+ if let Some ( transaction_from_dsc) = input . transaction_from_dsc {
470
487
universal_tags
471
488
. 0
472
489
. insert ( CommonTag :: Transaction , transaction_from_dsc. to_string ( ) ) ;
473
490
}
474
491
TransactionCPRTags {
475
- decision : match sampling_result {
492
+ decision : match input . sampling_result {
476
493
SamplingResult :: Keep => "keep" . to_owned ( ) ,
477
494
SamplingResult :: Drop ( _) => "drop" . to_owned ( ) ,
478
495
} ,
@@ -1079,6 +1096,7 @@ mod tests {
1079
1096
event. value_mut ( ) . as_mut ( ) . unwrap ( ) ,
1080
1097
Some ( "test_transaction" ) ,
1081
1098
& SamplingResult :: Keep ,
1099
+ false ,
1082
1100
& mut metrics,
1083
1101
& mut sampling_metrics,
1084
1102
)
@@ -1813,6 +1831,7 @@ mod tests {
1813
1831
event. value_mut ( ) . as_mut ( ) . unwrap ( ) ,
1814
1832
Some ( "test_transaction" ) ,
1815
1833
& SamplingResult :: Keep ,
1834
+ false ,
1816
1835
& mut metrics,
1817
1836
& mut sampling_metrics,
1818
1837
)
@@ -1906,6 +1925,7 @@ mod tests {
1906
1925
event. value_mut ( ) . as_mut ( ) . unwrap ( ) ,
1907
1926
Some ( "test_transaction" ) ,
1908
1927
& SamplingResult :: Keep ,
1928
+ false ,
1909
1929
& mut metrics,
1910
1930
& mut sampling_metrics,
1911
1931
)
@@ -1986,6 +2006,7 @@ mod tests {
1986
2006
event. value_mut ( ) . as_mut ( ) . unwrap ( ) ,
1987
2007
Some ( "test_transaction" ) ,
1988
2008
& SamplingResult :: Keep ,
2009
+ false ,
1989
2010
& mut metrics,
1990
2011
& mut sampling_metrics,
1991
2012
)
@@ -2062,6 +2083,7 @@ mod tests {
2062
2083
event. value_mut ( ) . as_mut ( ) . unwrap ( ) ,
2063
2084
Some ( "test_transaction" ) ,
2064
2085
& SamplingResult :: Keep ,
2086
+ false ,
2065
2087
& mut metrics,
2066
2088
& mut sampling_metrics,
2067
2089
)
@@ -2173,6 +2195,7 @@ mod tests {
2173
2195
event. value_mut ( ) . as_mut ( ) . unwrap ( ) ,
2174
2196
Some ( "test_transaction" ) ,
2175
2197
& SamplingResult :: Keep ,
2198
+ false ,
2176
2199
& mut metrics,
2177
2200
& mut sampling_metrics,
2178
2201
)
@@ -2261,6 +2284,7 @@ mod tests {
2261
2284
event. value_mut ( ) . as_mut ( ) . unwrap ( ) ,
2262
2285
Some ( "test_transaction" ) ,
2263
2286
& SamplingResult :: Keep ,
2287
+ false ,
2264
2288
& mut metrics,
2265
2289
& mut sampling_metrics,
2266
2290
)
@@ -2311,6 +2335,7 @@ mod tests {
2311
2335
event. value_mut ( ) . as_mut ( ) . unwrap ( ) ,
2312
2336
Some ( "test_transaction" ) ,
2313
2337
& SamplingResult :: Keep ,
2338
+ false ,
2314
2339
& mut metrics,
2315
2340
& mut sampling_metrics,
2316
2341
)
@@ -2351,6 +2376,7 @@ mod tests {
2351
2376
event. value_mut ( ) . as_mut ( ) . unwrap ( ) ,
2352
2377
Some ( "test_transaction" ) ,
2353
2378
& SamplingResult :: Keep ,
2379
+ false ,
2354
2380
& mut metrics,
2355
2381
& mut sampling_metrics,
2356
2382
)
@@ -2400,6 +2426,7 @@ mod tests {
2400
2426
event. value_mut ( ) . as_mut ( ) . unwrap ( ) ,
2401
2427
Some ( "test_transaction" ) ,
2402
2428
& SamplingResult :: Keep ,
2429
+ false ,
2403
2430
& mut metrics,
2404
2431
& mut sampling_metrics,
2405
2432
) ;
@@ -2426,6 +2453,7 @@ mod tests {
2426
2453
event. value_mut ( ) . as_mut ( ) . unwrap ( ) ,
2427
2454
Some ( "test_transaction" ) ,
2428
2455
& SamplingResult :: Keep ,
2456
+ false ,
2429
2457
& mut metrics,
2430
2458
& mut sampling_metrics,
2431
2459
)
@@ -2466,6 +2494,7 @@ mod tests {
2466
2494
event. value_mut ( ) . as_mut ( ) . unwrap ( ) ,
2467
2495
Some ( "root_transaction" ) ,
2468
2496
& SamplingResult :: Keep ,
2497
+ false ,
2469
2498
& mut metrics,
2470
2499
& mut sampling_metrics,
2471
2500
)
@@ -2840,6 +2869,7 @@ mod tests {
2840
2869
event. value_mut ( ) . as_mut ( ) . unwrap ( ) ,
2841
2870
Some ( "test_transaction" ) ,
2842
2871
& SamplingResult :: Keep ,
2872
+ false ,
2843
2873
& mut metrics,
2844
2874
& mut sampling_metrics,
2845
2875
)
0 commit comments