From 8806f9cb495d049fc65ef90ef9ef1dd36c3ef03b Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Fri, 12 Jul 2024 09:43:00 -0400 Subject: [PATCH] fix(profiling): Only transfer valid profile ids (#3809) This was transfering the profile id onto the transaction all the time which is not desirable since we need to fully validate the profile first. --- CHANGELOG.md | 1 + relay-server/src/services/processor.rs | 1 + .../src/services/processor/profile.rs | 211 ++++++++++++++++-- 3 files changed, 192 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 404a28170c..5e4371dd23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Fixes metrics dropped due to missing project state. ([#3553](https://github.com/getsentry/relay/issues/3553)) - Incorrect span outcomes when generated from a indexed transaction quota. ([#3793](https://github.com/getsentry/relay/pull/3793)) - Report outcomes for spans when transactions are rate limited. ([#3749](https://github.com/getsentry/relay/pull/3749)) +- Only transfer valid profile ids. ([#3809](https://github.com/getsentry/relay/pull/3809)) **Internal**: diff --git a/relay-server/src/services/processor.rs b/relay-server/src/services/processor.rs index d7dfeeafd0..4b8bba9ca0 100644 --- a/relay-server/src/services/processor.rs +++ b/relay-server/src/services/processor.rs @@ -1699,6 +1699,7 @@ impl EnvelopeProcessorService { if_processing!(self.inner.config, { // Process profiles before extracting metrics, to make sure they are removed if they are invalid. let profile_id = profile::process(state, &self.inner.config); + profile::transfer_id(state, profile_id); // Always extract metrics in processing Relays for sampled items. self.extract_transaction_metrics(state, SamplingDecision::Keep, profile_id)?; diff --git a/relay-server/src/services/processor/profile.rs b/relay-server/src/services/processor/profile.rs index 00b98ddebe..be8e3fb800 100644 --- a/relay-server/src/services/processor/profile.rs +++ b/relay-server/src/services/processor/profile.rs @@ -146,6 +146,7 @@ fn expand_profile(item: &mut Item, event: &Event, config: &Config) -> Result::from_json_bytes(&item.payload()).unwrap(); + let context = transaction + .value() + .unwrap() + .context::() + .unwrap(); + + assert_debug_snapshot!(context, @r###" + ProfileContext { + profile_id: ~, + profiler_id: ~, + } + "###); + } + #[tokio::test] async fn filter_standalone_profile() { relay_log::init_test!(); @@ -311,10 +472,18 @@ mod tests { assert!(envelope_response.envelope.is_none()); } + #[cfg(feature = "processing")] #[tokio::test] async fn test_profile_id_removed_profiler_id_kept() { // Setup - let processor = create_test_processor(Default::default()); + let config = Config::from_json_value(serde_json::json!({ + "processing": { + "enabled": true, + "kafka_config": [] + } + })) + .unwrap(); + let processor = create_test_processor(config); let event_id = EventId::new(); let dsn = "https://e12d836b15bb49d7bbf99e64295d995b:@sentry.io/42" .parse()