Skip to content

Commit

Permalink
fix: Normalize the Request interface in light normalization (#2819)
Browse files Browse the repository at this point in the history
Moves request normalization into light normalization. This is
particularly required so that metric extraction can operate on a
normalized URL field. Additionally, in a follow-up, we will also add
normalization for the `Referer` field.

Fixes #2786
  • Loading branch information
jan-auer authored Dec 5, 2023
1 parent 19ab9c3 commit 6ac4abb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@
- Add Mixed JS/Android Profiles events processing. ([#2706](https://github.com/getsentry/relay/pull/2706))
- Allow to ingest measurements on a span. ([#2792](https://github.com/getsentry/relay/pull/2792))
- Extract size metrics for all resource spans when permitted. ([#2805](https://github.com/getsentry/relay/pull/2805))
- Add size limits on metric related envelope items. ([#2800](https://github.com/getsentry/relay/pull/2800))
- Include the size offending item in the size limit error message. ([#2801](https://github.com/getsentry/relay/pull/2801))

**Bug Fixes**:

- In on-demand metric extraction, use the normalized URL instead of raw URLs sent by SDKs. This bug prevented metrics for certain dashboard queries from being extracted. ([#2819](https://github.com/getsentry/relay/pull/2819))
- Ignore whitespaces when parsing user reports. ([#2798](https://github.com/getsentry/relay/pull/2798))

**Internal**:

- Support source context in metric code locations metadata entries. ([#2781](https://github.com/getsentry/relay/pull/2781))
- Temporarily add metric summaries on spans and top-level transaction events to link DDM with performance monitoring. ([#2757](https://github.com/getsentry/relay/pull/2757))
- Ignore whitespaces when parsing user reports. ([#2798](https://github.com/getsentry/relay/pull/2798))
- Add size limits on metric related envelope items. ([#2800](https://github.com/getsentry/relay/pull/2800))
- Include the size offending item in the size limit error message. ([#2801](https://github.com/getsentry/relay/pull/2801))

## 23.11.2

Expand Down
12 changes: 8 additions & 4 deletions relay-event-normalization/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ use relay_event_schema::protocol::{
use relay_protocol::{Annotated, Empty, Error, ErrorKind, Meta, Object, Value};
use smallvec::SmallVec;

use crate::normalize::request;
use crate::span::tag_extraction::{self, extract_span_tags};
use crate::timestamp::TimestampProcessor;
use crate::utils::{self, MAX_DURATION_MOBILE_MS};
use crate::{
breakdowns, schema, span, transactions, trimming, user_agent, BreakdownsConfig,
ClockDriftProcessor, DynamicMeasurementsConfig, GeoIpLookup, PerformanceScoreConfig,
RawUserAgentInfo, SpanDescriptionRule, TransactionNameConfig,
breakdowns, mechanism, schema, span, stacktrace, transactions, trimming, user_agent,
BreakdownsConfig, ClockDriftProcessor, DynamicMeasurementsConfig, GeoIpLookup,
PerformanceScoreConfig, RawUserAgentInfo, SpanDescriptionRule, TransactionNameConfig,
};
use crate::{mechanism, stacktrace};

/// Configuration for [`normalize_event`].
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -269,6 +269,10 @@ fn normalize(event: &mut Event, meta: &mut Meta, config: &NormalizationConfig) -
normalize_performance_score(event, config.performance_score);
normalize_breakdowns(event, config.breakdowns_config); // Breakdowns are part of the metric extraction too

processor::apply(&mut event.request, |request, _| {
request::normalize_request(request)
})?;

// Some contexts need to be normalized before metrics extraction takes place.
processor::apply(&mut event.contexts, normalize_contexts)?;

Expand Down
15 changes: 1 addition & 14 deletions relay-event-normalization/src/normalize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ use crate::{GeoIpLookup, StoreConfig};

pub mod breakdowns;
pub mod nel;
pub mod request;
pub mod span;
pub mod user_agent;
pub mod utils;

mod contexts;
mod request;

/// Defines a builtin measurement.
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Hash, Eq)]
Expand Down Expand Up @@ -463,19 +463,6 @@ impl<'a> Processor for StoreNormalizeProcessor<'a> {
Ok(())
}

fn process_request(
&mut self,
request: &mut Request,
_meta: &mut Meta,
state: &ProcessingState<'_>,
) -> ProcessingResult {
request.process_child_values(self, state)?;

request::normalize_request(request)?;

Ok(())
}

fn process_user(
&mut self,
user: &mut User,
Expand Down
13 changes: 13 additions & 0 deletions relay-event-normalization/src/normalize/request.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! Normalization of the [`Request`] interface.
//!
//! See [`normalize_request`] for more information.
use once_cell::sync::OnceCell;
use regex::Regex;
use relay_event_schema::processor::{self, ProcessingAction, ProcessingResult};
Expand Down Expand Up @@ -179,6 +183,15 @@ fn normalize_cookies(request: &mut Request) {
}
}

/// Normalizes the [`Request`] interface.
///
/// This function applies the following normalization rules:
/// - The URL is truncated to 2048 characters.
/// - The query string and fragment are extracted into dedicated fields.
/// - The method is normalized to uppercase.
/// - The data is parsed as JSON or urlencoded and put into the `data` field.
/// - The `Content-Type` header is parsed and put into the `inferred_content_type` field.
/// - The `Cookie` header is parsed and put into the `cookies` field.
pub fn normalize_request(request: &mut Request) -> ProcessingResult {
processor::apply(&mut request.method, normalize_method)?;
normalize_url(request);
Expand Down
10 changes: 5 additions & 5 deletions relay-server/src/metrics_extraction/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ mod tests {
"environment": "fake_environment",
"fOO": "bar",
"geo.country_code": "US",
"http.method": "post",
"http.method": "POST",
"os.name": "Windows",
"platform": "javascript",
"release": "1.2.3",
Expand All @@ -619,7 +619,7 @@ mod tests {
"environment": "fake_environment",
"fOO": "bar",
"geo.country_code": "US",
"http.method": "post",
"http.method": "POST",
"measurement_rating": "meh",
"os.name": "Windows",
"platform": "javascript",
Expand All @@ -644,7 +644,7 @@ mod tests {
"environment": "fake_environment",
"fOO": "bar",
"geo.country_code": "US",
"http.method": "post",
"http.method": "POST",
"os.name": "Windows",
"platform": "javascript",
"release": "1.2.3",
Expand Down Expand Up @@ -677,7 +677,7 @@ mod tests {
"environment": "fake_environment",
"fOO": "bar",
"geo.country_code": "US",
"http.method": "post",
"http.method": "POST",
"os.name": "Windows",
"platform": "javascript",
"release": "1.2.3",
Expand Down Expand Up @@ -714,7 +714,7 @@ mod tests {
"environment": "fake_environment",
"fOO": "bar",
"geo.country_code": "US",
"http.method": "post",
"http.method": "POST",
"os.name": "Windows",
"platform": "javascript",
"release": "1.2.3",
Expand Down

0 comments on commit 6ac4abb

Please sign in to comment.