@@ -776,13 +776,6 @@ struct ProcessEnvelopeState<Group> {
776
776
/// This is the config used for trace-based dynamic sampling.
777
777
sampling_project_info : Option < Arc < ProjectInfo > > ,
778
778
779
- /// The id of the project that this envelope is ingested into.
780
- ///
781
- /// This identifier can differ from the one stated in the Envelope's DSN if the key was moved to
782
- /// a new project or on the legacy endpoint. In that case, normalization will update the project
783
- /// ID.
784
- project_id : ProjectId ,
785
-
786
779
/// The managed envelope before processing.
787
780
managed_envelope : TypedEnvelope < Group > ,
788
781
}
@@ -1230,13 +1223,17 @@ impl EnvelopeProcessorService {
1230
1223
1231
1224
/// Normalize monitor check-ins and remove invalid ones.
1232
1225
#[ cfg( feature = "processing" ) ]
1233
- fn process_check_ins ( & self , state : & mut ProcessEnvelopeState < CheckInGroup > ) {
1226
+ fn process_check_ins (
1227
+ & self ,
1228
+ state : & mut ProcessEnvelopeState < CheckInGroup > ,
1229
+ project_id : ProjectId ,
1230
+ ) {
1234
1231
state. managed_envelope . retain_items ( |item| {
1235
1232
if item. ty ( ) != & ItemType :: CheckIn {
1236
1233
return ItemAction :: Keep ;
1237
1234
}
1238
1235
1239
- match relay_monitors:: process_check_in ( & item. payload ( ) , state . project_id ) {
1236
+ match relay_monitors:: process_check_in ( & item. payload ( ) , project_id) {
1240
1237
Ok ( result) => {
1241
1238
item. set_routing_hint ( result. routing_hint ) ;
1242
1239
item. set_payload ( ContentType :: Json , result. payload ) ;
@@ -1254,50 +1251,6 @@ impl EnvelopeProcessorService {
1254
1251
} )
1255
1252
}
1256
1253
1257
- /// Creates and initializes the processing state.
1258
- ///
1259
- /// This applies defaults to the envelope and initializes empty rate limits.
1260
- #[ allow( clippy:: too_many_arguments) ]
1261
- fn prepare_state < G > (
1262
- & self ,
1263
- config : Arc < Config > ,
1264
- mut managed_envelope : TypedEnvelope < G > ,
1265
- project_id : ProjectId ,
1266
- project_info : Arc < ProjectInfo > ,
1267
- rate_limits : Arc < RateLimits > ,
1268
- sampling_project_info : Option < Arc < ProjectInfo > > ,
1269
- ) -> ProcessEnvelopeState < G > {
1270
- let envelope = managed_envelope. envelope_mut ( ) ;
1271
-
1272
- // Set the event retention. Effectively, this value will only be available in processing
1273
- // mode when the full project config is queried from the upstream.
1274
- if let Some ( retention) = project_info. config . event_retention {
1275
- envelope. set_retention ( retention) ;
1276
- }
1277
-
1278
- // Ensure the project ID is updated to the stored instance for this project cache. This can
1279
- // differ in two cases:
1280
- // 1. The envelope was sent to the legacy `/store/` endpoint without a project ID.
1281
- // 2. The DSN was moved and the envelope sent to the old project ID.
1282
- envelope. meta_mut ( ) . set_project_id ( project_id) ;
1283
-
1284
- let extracted_metrics = ProcessingExtractedMetrics :: new ( ) ;
1285
-
1286
- ProcessEnvelopeState {
1287
- event : Annotated :: empty ( ) ,
1288
- event_metrics_extracted : false ,
1289
- spans_extracted : false ,
1290
- metrics : Metrics :: default ( ) ,
1291
- extracted_metrics,
1292
- project_info,
1293
- rate_limits,
1294
- config,
1295
- sampling_project_info,
1296
- project_id,
1297
- managed_envelope,
1298
- }
1299
- }
1300
-
1301
1254
#[ cfg( feature = "processing" ) ]
1302
1255
fn enforce_quotas < G > (
1303
1256
& self ,
@@ -1332,6 +1285,7 @@ impl EnvelopeProcessorService {
1332
1285
fn extract_transaction_metrics (
1333
1286
& self ,
1334
1287
state : & mut ProcessEnvelopeState < TransactionGroup > ,
1288
+ project_id : ProjectId ,
1335
1289
sampling_decision : SamplingDecision ,
1336
1290
) -> Result < ( ) , ProcessingError > {
1337
1291
if state. event_metrics_extracted {
@@ -1406,7 +1360,7 @@ impl EnvelopeProcessorService {
1406
1360
event,
1407
1361
combined_config,
1408
1362
sampling_decision,
1409
- state . project_id ,
1363
+ project_id,
1410
1364
self . inner
1411
1365
. config
1412
1366
. aggregator_config_for ( MetricNamespace :: Spans )
@@ -1431,7 +1385,7 @@ impl EnvelopeProcessorService {
1431
1385
generic_config : Some ( combined_config) ,
1432
1386
transaction_from_dsc,
1433
1387
sampling_decision,
1434
- target_project_id : state . project_id ,
1388
+ target_project_id : project_id,
1435
1389
} ;
1436
1390
1437
1391
state
@@ -1447,6 +1401,7 @@ impl EnvelopeProcessorService {
1447
1401
fn normalize_event < G : EventProcessing > (
1448
1402
& self ,
1449
1403
state : & mut ProcessEnvelopeState < G > ,
1404
+ project_id : ProjectId ,
1450
1405
mut event_fully_normalized : EventFullyNormalized ,
1451
1406
) -> Result < Option < EventFullyNormalized > , ProcessingError > {
1452
1407
if !state. has_event ( ) {
@@ -1510,7 +1465,7 @@ impl EnvelopeProcessorService {
1510
1465
}
1511
1466
1512
1467
let normalization_config = NormalizationConfig {
1513
- project_id : Some ( state . project_id . value ( ) ) ,
1468
+ project_id : Some ( project_id. value ( ) ) ,
1514
1469
client : request_meta. client ( ) . map ( str:: to_owned) ,
1515
1470
key_id,
1516
1471
protocol_version : Some ( request_meta. version ( ) . to_string ( ) ) ,
@@ -1593,6 +1548,7 @@ impl EnvelopeProcessorService {
1593
1548
fn process_errors (
1594
1549
& self ,
1595
1550
state : & mut ProcessEnvelopeState < ErrorGroup > ,
1551
+ project_id : ProjectId ,
1596
1552
) -> Result < ( ) , ProcessingError > {
1597
1553
let mut event_fully_normalized = EventFullyNormalized :: new ( state. envelope ( ) ) ;
1598
1554
@@ -1616,7 +1572,7 @@ impl EnvelopeProcessorService {
1616
1572
1617
1573
event:: finalize ( state, & self . inner . config ) ?;
1618
1574
if let Some ( inner_event_fully_normalized) =
1619
- self . normalize_event ( state, event_fully_normalized) ?
1575
+ self . normalize_event ( state, project_id , event_fully_normalized) ?
1620
1576
{
1621
1577
event_fully_normalized = inner_event_fully_normalized;
1622
1578
} ;
@@ -1640,7 +1596,7 @@ impl EnvelopeProcessorService {
1640
1596
1641
1597
if self . inner . config . processing_enabled ( ) && !event_fully_normalized. 0 {
1642
1598
relay_log:: error!(
1643
- tags. project = %state . project_id,
1599
+ tags. project = %project_id,
1644
1600
tags. ty = state. event_type( ) . map( |e| e. to_string( ) ) . unwrap_or( "none" . to_owned( ) ) ,
1645
1601
"ingested event without normalizing"
1646
1602
) ;
@@ -1653,6 +1609,7 @@ impl EnvelopeProcessorService {
1653
1609
fn process_transactions (
1654
1610
& self ,
1655
1611
state : & mut ProcessEnvelopeState < TransactionGroup > ,
1612
+ project_id : ProjectId ,
1656
1613
reservoir_counters : ReservoirCounters ,
1657
1614
) -> Result < ( ) , ProcessingError > {
1658
1615
let mut event_fully_normalized = EventFullyNormalized :: new ( state. envelope ( ) ) ;
@@ -1661,12 +1618,12 @@ impl EnvelopeProcessorService {
1661
1618
1662
1619
event:: extract ( state, event_fully_normalized, & self . inner . config ) ?;
1663
1620
1664
- let profile_id = profile:: filter ( state) ;
1621
+ let profile_id = profile:: filter ( state, project_id ) ;
1665
1622
profile:: transfer_id ( state, profile_id) ;
1666
1623
1667
1624
event:: finalize ( state, & self . inner . config ) ?;
1668
1625
if let Some ( inner_event_fully_normalized) =
1669
- self . normalize_event ( state, event_fully_normalized) ?
1626
+ self . normalize_event ( state, project_id , event_fully_normalized) ?
1670
1627
{
1671
1628
event_fully_normalized = inner_event_fully_normalized;
1672
1629
}
@@ -1701,7 +1658,7 @@ impl EnvelopeProcessorService {
1701
1658
// Before metric extraction to make sure the profile count is reflected correctly.
1702
1659
profile:: process ( state, & global_config) ;
1703
1660
// Extract metrics here, we're about to drop the event/transaction.
1704
- self . extract_transaction_metrics ( state, SamplingDecision :: Drop ) ?;
1661
+ self . extract_transaction_metrics ( state, project_id , SamplingDecision :: Drop ) ?;
1705
1662
1706
1663
dynamic_sampling:: drop_unsampled_items ( state, outcome) ;
1707
1664
@@ -1728,7 +1685,7 @@ impl EnvelopeProcessorService {
1728
1685
profile:: transfer_id( state, profile_id) ;
1729
1686
1730
1687
// Always extract metrics in processing Relays for sampled items.
1731
- self . extract_transaction_metrics( state, SamplingDecision :: Keep ) ?;
1688
+ self . extract_transaction_metrics( state, project_id , SamplingDecision :: Keep ) ?;
1732
1689
1733
1690
if state
1734
1691
. project_info
@@ -1749,7 +1706,7 @@ impl EnvelopeProcessorService {
1749
1706
1750
1707
if self . inner . config . processing_enabled ( ) && !event_fully_normalized. 0 {
1751
1708
relay_log:: error!(
1752
- tags. project = %state . project_id,
1709
+ tags. project = %project_id,
1753
1710
tags. ty = state. event_type( ) . map( |e| e. to_string( ) ) . unwrap_or( "none" . to_owned( ) ) ,
1754
1711
"ingested event without normalizing"
1755
1712
) ;
@@ -1777,8 +1734,9 @@ impl EnvelopeProcessorService {
1777
1734
fn process_standalone (
1778
1735
& self ,
1779
1736
state : & mut ProcessEnvelopeState < StandaloneGroup > ,
1737
+ project_id : ProjectId ,
1780
1738
) -> Result < ( ) , ProcessingError > {
1781
- profile:: filter ( state) ;
1739
+ profile:: filter ( state, project_id ) ;
1782
1740
1783
1741
if_processing ! ( self . inner. config, {
1784
1742
self . enforce_quotas( state) ?;
@@ -1834,11 +1792,12 @@ impl EnvelopeProcessorService {
1834
1792
/// Processes cron check-ins.
1835
1793
fn process_checkins (
1836
1794
& self ,
1837
- _state : & mut ProcessEnvelopeState < CheckInGroup > ,
1795
+ #[ allow( unused_variables) ] state : & mut ProcessEnvelopeState < CheckInGroup > ,
1796
+ #[ allow( unused_variables) ] project_id : ProjectId ,
1838
1797
) -> Result < ( ) , ProcessingError > {
1839
1798
if_processing ! ( self . inner. config, {
1840
- self . enforce_quotas( _state ) ?;
1841
- self . process_check_ins( _state ) ;
1799
+ self . enforce_quotas( state ) ?;
1800
+ self . process_check_ins( state , project_id ) ;
1842
1801
} ) ;
1843
1802
Ok ( ( ) )
1844
1803
}
@@ -1849,6 +1808,7 @@ impl EnvelopeProcessorService {
1849
1808
fn process_standalone_spans (
1850
1809
& self ,
1851
1810
state : & mut ProcessEnvelopeState < SpanGroup > ,
1811
+ #[ allow( unused_variables) ] project_id : ProjectId ,
1852
1812
#[ allow( unused_variables) ] reservoir_counters : ReservoirCounters ,
1853
1813
) -> Result < ( ) , ProcessingError > {
1854
1814
span:: filter ( state) ;
@@ -1863,6 +1823,7 @@ impl EnvelopeProcessorService {
1863
1823
1864
1824
span:: process(
1865
1825
state,
1826
+ project_id,
1866
1827
& global_config,
1867
1828
self . inner. geoip_lookup. as_ref( ) ,
1868
1829
& reservoir,
@@ -1895,17 +1856,37 @@ impl EnvelopeProcessorService {
1895
1856
. parametrize_dsc_transaction ( & sampling_state. config . tx_name_rules ) ;
1896
1857
}
1897
1858
1859
+ // Set the event retention. Effectively, this value will only be available in processing
1860
+ // mode when the full project config is queried from the upstream.
1861
+ if let Some ( retention) = project_info. config . event_retention {
1862
+ managed_envelope. envelope_mut ( ) . set_retention ( retention) ;
1863
+ }
1864
+
1865
+ // Ensure the project ID is updated to the stored instance for this project cache. This can
1866
+ // differ in two cases:
1867
+ // 1. The envelope was sent to the legacy `/store/` endpoint without a project ID.
1868
+ // 2. The DSN was moved and the envelope sent to the old project ID.
1869
+ managed_envelope
1870
+ . envelope_mut ( )
1871
+ . meta_mut ( )
1872
+ . set_project_id ( project_id) ;
1873
+
1898
1874
macro_rules! run {
1899
1875
( $fn_name: ident $( , $args: expr) * ) => { {
1900
1876
let managed_envelope = managed_envelope. try_into( ) ?;
1901
- let mut state = self . prepare_state(
1902
- self . inner. config. clone( ) ,
1903
- managed_envelope,
1904
- project_id,
1877
+ let mut state = ProcessEnvelopeState {
1878
+ event: Annotated :: empty( ) ,
1879
+ event_metrics_extracted: false ,
1880
+ spans_extracted: false ,
1881
+ metrics: Metrics :: default ( ) ,
1882
+ extracted_metrics: ProcessingExtractedMetrics :: new( ) ,
1883
+ config: self . inner. config. clone( ) ,
1905
1884
project_info,
1906
1885
rate_limits,
1907
1886
sampling_project_info,
1908
- ) ;
1887
+ managed_envelope,
1888
+ } ;
1889
+
1909
1890
// The state is temporarily supplied, until it will be removed.
1910
1891
match self . $fn_name( & mut state, $( $args) ,* ) {
1911
1892
Ok ( ( ) ) => Ok ( ProcessingStateResult {
@@ -1926,14 +1907,16 @@ impl EnvelopeProcessorService {
1926
1907
relay_log:: trace!( "Processing {group} group" , group = group. variant( ) ) ;
1927
1908
1928
1909
match group {
1929
- ProcessingGroup :: Error => run ! ( process_errors) ,
1930
- ProcessingGroup :: Transaction => run ! ( process_transactions, reservoir_counters) ,
1910
+ ProcessingGroup :: Error => run ! ( process_errors, project_id) ,
1911
+ ProcessingGroup :: Transaction => {
1912
+ run ! ( process_transactions, project_id, reservoir_counters)
1913
+ }
1931
1914
ProcessingGroup :: Session => run ! ( process_sessions) ,
1932
- ProcessingGroup :: Standalone => run ! ( process_standalone) ,
1915
+ ProcessingGroup :: Standalone => run ! ( process_standalone, project_id ) ,
1933
1916
ProcessingGroup :: ClientReport => run ! ( process_client_reports) ,
1934
1917
ProcessingGroup :: Replay => run ! ( process_replays) ,
1935
- ProcessingGroup :: CheckIn => run ! ( process_checkins) ,
1936
- ProcessingGroup :: Span => run ! ( process_standalone_spans, reservoir_counters) ,
1918
+ ProcessingGroup :: CheckIn => run ! ( process_checkins, project_id ) ,
1919
+ ProcessingGroup :: Span => run ! ( process_standalone_spans, project_id , reservoir_counters) ,
1937
1920
ProcessingGroup :: ProfileChunk => run ! ( process_profile_chunks) ,
1938
1921
// Currently is not used.
1939
1922
ProcessingGroup :: Metrics => {
0 commit comments