-
Notifications
You must be signed in to change notification settings - Fork 114
ref(errors): Implements a new processor for errors #5633
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
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
4b9cbb4
relaly big wip
Dav1dde 9caae16
wip
Dav1dde c5abd79
very close
Dav1dde 0d3fd0a
begin fixing outcomes
Dav1dde b27bb11
solve debug stack overflow (Items) and run apple/minidump processing …
Dav1dde ed02ff2
some unreal checkpoint
Dav1dde 0e0676f
some progress, rm errorref, size limits, stuck at objectstore
Dav1dde eb6026b
progress, rate limits, outcomes crashes
Dav1dde b36efdc
Merge remote-tracking branch 'origin/master' into dav1d/error-processor
Dav1dde 4c6e63d
rest of the owl
Dav1dde 2043cb2
fixes and cleanup
Dav1dde 6f255b5
ref(server): Remove profile type header in favor of platform header
Dav1dde 0e4069c
some fixes
Dav1dde e3e1ba5
fix stack overflow
Dav1dde 8fe0c1c
non processing gates
Dav1dde 548cf1d
apply rate limit fix
Dav1dde b09638d
attachments fix
Dav1dde 10649da
attachments fix
Dav1dde 0378392
doc string fixes
Dav1dde 7ecc8a1
nswitch test fixes
Dav1dde 46a0e29
more cleanup
Dav1dde 5c4c7d6
more cfg processing
Dav1dde 01a465d
Merge branch 'master' into dav1d/error-processor
Dav1dde ded7297
code review: destructure, better comments
Dav1dde 288d2dd
code review: tuple structs
Dav1dde be4ed1c
Merge remote-tracking branch 'origin/master' into dav1d/error-processor
Dav1dde c34b165
bugbot findings
Dav1dde 764e7f5
bugbot fix
Dav1dde b6e6a86
event bug
Dav1dde 5ccff39
metrics bug and linter problems
Dav1dde 6bd63cc
Merge branch 'master' into dav1d/error-processor
Dav1dde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| use chrono::Utc; | ||
| use relay_event_schema::protocol::{Contexts, TraceContext}; | ||
| use relay_protocol::{Annotated, Empty as _}; | ||
| use relay_sampling::config::RuleType; | ||
| use relay_sampling::evaluation::SamplingEvaluator; | ||
|
|
||
| use crate::managed::Managed; | ||
| use crate::processing::Context; | ||
| use crate::processing::errors::ExpandedError; | ||
| use crate::utils::SamplingResult; | ||
|
|
||
| /// Applies a dynamic sampling decision onto the error. | ||
| /// | ||
| /// The function validates the DSC as well as a tagging the error event with the sampling decision | ||
| /// of the associated trace. | ||
| pub async fn apply(error: &mut Managed<ExpandedError>, ctx: Context<'_>) { | ||
| // Only run in processing to not compute the decision multiple times and it is the most | ||
| // accurate place, as other Relays may have unsupported inbound filter or sampling configs. | ||
| if !ctx.is_processing() { | ||
| return; | ||
| } | ||
|
|
||
| if ctx.sampling_project_info.is_none() { | ||
| // If there is a DSC, the current project does not have access to the sampling project | ||
| // -> remove the DSC. | ||
| error.modify(|error, _| error.headers.remove_dsc()); | ||
| return; | ||
| } | ||
|
|
||
| if let Some(sampled) = is_trace_fully_sampled(error, ctx).await { | ||
| error.modify(|error, _| tag_error_with_sampling_decision(error, sampled)); | ||
| }; | ||
| } | ||
|
Dav1dde marked this conversation as resolved.
|
||
|
|
||
| fn tag_error_with_sampling_decision(error: &mut ExpandedError, sampled: bool) { | ||
| let Some(event) = error.event.value_mut() else { | ||
| return; | ||
| }; | ||
|
|
||
| // We want to get the trace context, in which we will inject the `sampled` field. | ||
| let context = event | ||
| .contexts | ||
| .get_or_insert_with(Contexts::new) | ||
| .get_or_default::<TraceContext>(); | ||
|
|
||
| // We want to update `sampled` only if it was not set, since if we don't check this | ||
| // we will end up overriding the value set by downstream Relays and this will lead | ||
| // to more complex debugging in case of problems. | ||
| if context.sampled.is_empty() { | ||
| relay_log::trace!("tagged error with `sampled = {}` flag", sampled); | ||
| context.sampled = Annotated::new(sampled); | ||
| } | ||
| } | ||
|
|
||
| /// Runs dynamic sampling if the dsc and root project state are not None and returns whether the | ||
| /// transactions received with such dsc and project state would be kept or dropped by dynamic | ||
| /// sampling. | ||
| async fn is_trace_fully_sampled(error: &ExpandedError, ctx: Context<'_>) -> Option<bool> { | ||
| let dsc = error.headers.dsc()?; | ||
|
|
||
| let sampling_config = ctx | ||
| .sampling_project_info | ||
| .and_then(|s| s.config.sampling.as_ref()) | ||
| .and_then(|s| s.as_ref().ok())?; | ||
|
|
||
| if sampling_config.unsupported() { | ||
| if ctx.is_processing() { | ||
| relay_log::error!("found unsupported rules even as processing relay"); | ||
| } | ||
|
|
||
| return None; | ||
| } | ||
|
|
||
| // If the sampled field is not set, we prefer to not tag the error since we have no clue on | ||
| // whether the head of the trace was kept or dropped on the client side. | ||
| // In addition, if the head of the trace was dropped on the client we will immediately mark | ||
| // the trace as not fully sampled. | ||
| if !dsc.sampled? { | ||
| return Some(false); | ||
| } | ||
|
|
||
| let evaluator = SamplingEvaluator::new(Utc::now()); | ||
|
|
||
| let rules = sampling_config.filter_rules(RuleType::Trace); | ||
|
|
||
| let evaluation = evaluator.match_rules(*dsc.trace_id, dsc, rules).await; | ||
| Some(SamplingResult::from(evaluation).decision().is_keep()) | ||
| } | ||
75 changes: 75 additions & 0 deletions
75
relay-server/src/processing/errors/errors/apple_crash_report.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| use relay_quotas::{DataCategory, RateLimits}; | ||
|
|
||
| use crate::envelope::{AttachmentType, Item, ItemType}; | ||
| use crate::managed::{Counted, Quantities, RecordKeeper}; | ||
| use crate::processing::ForwardContext; | ||
| use crate::processing::errors::errors::{Context, Expansion, SentryError, utils}; | ||
| use crate::processing::errors::{Error, Result}; | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct AppleCrashReport(pub Item); | ||
|
|
||
| impl SentryError for AppleCrashReport { | ||
| fn try_expand(items: &mut Vec<Item>, ctx: Context<'_>) -> Result<Option<Expansion<Self>>> { | ||
| let Some(apple_crash_report) = utils::take_item_by(items, |item| { | ||
| item.attachment_type() == Some(AttachmentType::AppleCrashReport) | ||
| }) else { | ||
| return Ok(None); | ||
| }; | ||
|
|
||
| let mut metrics = Default::default(); | ||
| #[cfg_attr(not(feature = "processing"), expect(unused_mut))] | ||
| let mut event = utils::take_event_from_crash_items(items, &mut metrics, ctx)?; | ||
|
|
||
| utils::if_processing!(ctx, { | ||
| crate::utils::process_apple_crash_report( | ||
| event.get_or_insert_with(Default::default), | ||
| &apple_crash_report.payload(), | ||
| ); | ||
| metrics.bytes_ingested_event_applecrashreport = | ||
| (apple_crash_report.len() as u64).into(); | ||
| }); | ||
|
|
||
| Ok(Some(Expansion { | ||
| event: Box::new(event), | ||
| attachments: utils::take_items_of_type(items, ItemType::Attachment), | ||
| user_reports: utils::take_items_of_type(items, ItemType::UserReport), | ||
| error: Self(apple_crash_report), | ||
| metrics, | ||
| fully_normalized: false, | ||
| })) | ||
| } | ||
|
|
||
| fn apply_rate_limit( | ||
| &mut self, | ||
| _category: DataCategory, | ||
| limits: RateLimits, | ||
| records: &mut RecordKeeper<'_>, | ||
| ) -> Result<()> { | ||
| if !self.0.rate_limited() { | ||
| self.0.set_rate_limited(true); | ||
| records.reject_err(Error::RateLimited(limits), &self.0); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn serialize_into(self, items: &mut Vec<Item>, _ctx: ForwardContext<'_>) -> Result<()> { | ||
| items.push(self.0); | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| impl Counted for AppleCrashReport { | ||
| fn quantities(&self) -> Quantities { | ||
| // A rate limited crash report no longer counts as an attachment, but it is still passed | ||
| // along to have its data later extracted into an error (Symbolication). | ||
| // | ||
| // The rate limited information is passed along and will lead to the item later to be | ||
| // dropped. | ||
| match self.0.rate_limited() { | ||
| true => Default::default(), | ||
| false => self.0.quantities(), | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| use crate::envelope::{Item, ItemType}; | ||
| use crate::managed::{Counted, Quantities}; | ||
| use crate::processing::errors::Result; | ||
| use crate::processing::errors::errors::{Context, Expansion, SentryError, utils}; | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct Generic; | ||
|
|
||
| impl SentryError for Generic { | ||
| fn try_expand(items: &mut Vec<Item>, ctx: Context<'_>) -> Result<Option<Expansion<Self>>> { | ||
| let Some(ev) = utils::take_item_of_type(items, ItemType::Event) else { | ||
| return Ok(None); | ||
| }; | ||
|
Dav1dde marked this conversation as resolved.
|
||
|
|
||
| let fully_normalized = ev.fully_normalized(); | ||
| let mut metrics = Default::default(); | ||
|
|
||
| let mut event = utils::event_from_json_payload(ev, None, &mut metrics, ctx)?; | ||
|
|
||
| let skip_normalization = ctx.processing.is_processing() && fully_normalized; | ||
| if !skip_normalization && let Some(event) = event.value_mut() { | ||
| // Event items can never include transactions, so retain the event type and let | ||
| // inference deal with this during normalization. | ||
| event.ty.set_value(None); | ||
| } | ||
|
|
||
| Ok(Some(Expansion { | ||
| event: Box::new(event), | ||
| attachments: utils::take_items_of_type(items, ItemType::Attachment), | ||
| user_reports: utils::take_items_of_type(items, ItemType::UserReport), | ||
| error: Self, | ||
| metrics, | ||
| fully_normalized, | ||
| })) | ||
| } | ||
| } | ||
|
|
||
| impl Counted for Generic { | ||
| fn quantities(&self) -> Quantities { | ||
| Default::default() | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.