Skip to content

Commit 5bde5bc

Browse files
jjbayerjan-auer
andauthored
fix(py): Respect the renormalize flag (#1548)
The `normalize` in the python package and C-ABI receives a structure with config arguments for the various normalizers. The `renormalize` flag is more central, as it is supposed to disable most of the normalizers. This is used in Sentry after the event has passed normalization to ensure that it is still structurally valid, but it may contain fields now that are prohibited during ingestion. In #1366 large parts of normalization were split into a dedicated `light_normalize` function which did not honor the renormalize flag. This PR restores correct behavior and disables the entire renormalize call. Co-authored-by: Jan Michael Auer <[email protected]>
1 parent 7fdb037 commit 5bde5bc

File tree

3 files changed

+63
-14
lines changed

3 files changed

+63
-14
lines changed

py/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Restore correct behavior when `is_renormalize` is specified on `normalize_event`. ([#1548](https://github.com/getsentry/relay/pull/1548))
6+
37
## 0.8.14
48

9+
**Warning:** This release contains a regression. Please update to a more recent version.
10+
511
- Add `transaction_info` to event payloads, including the transaction's source and internal original transaction name. ([#1330](https://github.com/getsentry/relay/pull/1330))
612
- Add user-agent parsing to replays processor. ([#1420](https://github.com/getsentry/relay/pull/1420))
713
- `convert_datascrubbing_config` will now return an error string when conversion fails on big regexes. ([#1474](https://github.com/getsentry/relay/pull/1474))

relay-cabi/src/processing.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,17 @@ pub unsafe extern "C" fn relay_store_normalizer_normalize_event(
109109
) -> RelayStr {
110110
let processor = normalizer as *mut StoreProcessor;
111111
let mut event = Annotated::<Event>::from_json((*event).as_str())?;
112+
let config = (*processor).config();
112113
let light_normalization_config = LightNormalizationConfig {
113-
normalize_user_agent: (*processor).config().normalize_user_agent,
114-
is_renormalize: (*processor).config().is_renormalize.unwrap_or(false),
115-
..Default::default()
114+
client_ip: config.client_ip.as_ref(),
115+
user_agent: config.user_agent.as_deref(),
116+
received_at: config.received_at,
117+
max_secs_in_past: config.max_secs_in_past,
118+
max_secs_in_future: config.max_secs_in_future,
119+
measurements_config: None, // only supported in relay
120+
breakdowns_config: None, // only supported in relay
121+
normalize_user_agent: config.normalize_user_agent,
122+
is_renormalize: config.is_renormalize.unwrap_or(false),
116123
};
117124
light_normalize_event(&mut event, &light_normalization_config)?;
118125
process_value(&mut event, &mut *processor, ProcessingState::root())?;

relay-general/src/store/normalize.rs

+47-11
Original file line numberDiff line numberDiff line change
@@ -675,18 +675,17 @@ pub fn light_normalize_event(
675675
event: &mut Annotated<Event>,
676676
config: &LightNormalizationConfig,
677677
) -> ProcessingResult {
678+
if config.is_renormalize {
679+
return Ok(());
680+
}
681+
678682
event.apply(|event, meta| {
679-
if !config.is_renormalize {
680-
// Validate and normalize transaction
681-
// (internally noops for non-transaction events).
682-
// TODO: Parts of this processor should probably be a filter so we
683-
// can revert some changes to ProcessingAction
684-
transactions::TransactionsProcessor.process_event(
685-
event,
686-
meta,
687-
ProcessingState::root(),
688-
)?;
689-
}
683+
// Validate and normalize transaction
684+
// (internally noops for non-transaction events).
685+
// TODO: Parts of this processor should probably be a filter so we
686+
// can revert some changes to ProcessingAction
687+
transactions::TransactionsProcessor.process_event(event, meta, ProcessingState::root())?;
688+
690689
// Check for required and non-empty values
691690
schema::SchemaProcessor.process_event(event, meta, ProcessingState::root())?;
692691

@@ -983,6 +982,7 @@ impl<'a> Processor for NormalizeProcessor<'a> {
983982
#[cfg(test)]
984983
mod tests {
985984
use chrono::TimeZone;
985+
use insta::assert_debug_snapshot;
986986
use serde_json::json;
987987
use similar_asserts::assert_eq;
988988

@@ -2287,4 +2287,40 @@ mod tests {
22872287
assert!(res.is_err(), "{:?}", span);
22882288
}
22892289
}
2290+
2291+
#[test]
2292+
fn test_light_normalization_respects_is_renormalize() {
2293+
let mut event = Annotated::<Event>::from_json(
2294+
r###"
2295+
{
2296+
"type": "default",
2297+
"tags": [["environment", "some_environment"]]
2298+
}
2299+
"###,
2300+
)
2301+
.unwrap();
2302+
2303+
let result = light_normalize_event(
2304+
&mut event,
2305+
&LightNormalizationConfig {
2306+
is_renormalize: true,
2307+
..Default::default()
2308+
},
2309+
);
2310+
2311+
assert!(result.is_ok());
2312+
2313+
assert_debug_snapshot!(event.value().unwrap().tags, @r###"
2314+
Tags(
2315+
PairList(
2316+
[
2317+
TagEntry(
2318+
"environment",
2319+
"some_environment",
2320+
),
2321+
],
2322+
),
2323+
)
2324+
"###);
2325+
}
22902326
}

0 commit comments

Comments
 (0)