Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(profiling): Remove profile ID from transaction context if no profile is found in the envelope #2523

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

**Bug Fixes**:

- Remove profile_id from context when no profile is in the envelope. ([#2523](https://github.com/getsentry/relay/pull/2523))

**Internal**:

- Exclude more spans fron metrics extraction. ([#2522](https://github.com/getsentry/relay/pull/2522))
Expand Down
40 changes: 17 additions & 23 deletions relay-server/src/actors/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use {
crate::actors::project_cache::UpdateRateLimits,
crate::utils::{EnvelopeLimiter, MetricsLimiter},
relay_event_normalization::{span, StoreConfig, StoreProcessor},
relay_event_schema::protocol::{ProfileContext, Span},
relay_event_schema::protocol::{EventId, ProfileContext, Span},
relay_quotas::{RateLimitingError, RedisRateLimiter},
symbolic_unreal::{Unreal4Error, Unreal4ErrorKind},
};
Expand Down Expand Up @@ -1129,29 +1129,16 @@ impl EnvelopeProcessorService {
/// Process profiles and set the profile ID in the profile context on the transaction if successful
#[cfg(feature = "processing")]
fn process_profiles(&self, state: &mut ProcessEnvelopeState) {
let mut found_profile_id: Option<EventId> = Default::default();
phacops marked this conversation as resolved.
Show resolved Hide resolved
state.managed_envelope.retain_items(|item| match item.ty() {
ItemType::Profile => {
match relay_profiling::expand_profile(&item.payload(), state.event.value()) {
Ok((profile_id, payload)) => {
if payload.len() <= self.inner.config.max_profile_size() {
if let Some(event) = state.event.value_mut() {
if event.ty.value() == Some(&EventType::Transaction) {
let contexts = event.contexts.get_or_insert_with(Contexts::new);
contexts.add(ProfileContext {
profile_id: Annotated::new(profile_id),
});
}
}
found_profile_id = Some(profile_id);
item.set_payload(ContentType::Json, payload);
ItemAction::Keep
} else {
if let Some(event) = state.event.value_mut() {
if event.ty.value() == Some(&EventType::Transaction) {
if let Some(ref mut contexts) = event.contexts.value_mut() {
contexts.remove::<ProfileContext>();
}
}
}
ItemAction::Drop(Outcome::Invalid(DiscardReason::Profiling(
relay_profiling::discard_reason(
relay_profiling::ProfileError::ExceedSizeLimit,
Expand All @@ -1160,13 +1147,6 @@ impl EnvelopeProcessorService {
}
}
Err(err) => {
if let Some(event) = state.event.value_mut() {
if event.ty.value() == Some(&EventType::Transaction) {
let contexts = event.contexts.get_or_insert_with(Contexts::new);
contexts.remove::<ProfileContext>();
}
}

match err {
relay_profiling::ProfileError::InvalidJson(_) => {
relay_log::warn!(error = &err as &dyn Error, "invalid profile");
Expand All @@ -1181,6 +1161,20 @@ impl EnvelopeProcessorService {
}
_ => ItemAction::Keep,
});
if let Some(event) = state.event.value_mut() {
if event.ty.value() == Some(&EventType::Transaction) {
let contexts = event.contexts.get_or_insert_with(Contexts::new);
// If we found a profile, add its ID to the profile context on the transaction.
if let Some(profile_id) = found_profile_id {
contexts.add(ProfileContext {
profile_id: Annotated::new(profile_id),
});
// If not, we delete the profile context.
} else {
contexts.remove::<ProfileContext>();
}
}
}
}

/// Remove replays if the feature flag is not enabled.
Expand Down