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

feat(normalization): Mark scrubbed transactions as sanitized #1960

Merged
merged 4 commits into from
Mar 23, 2023
Merged
Changes from all 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
128 changes: 69 additions & 59 deletions relay-general/src/store/transactions/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,26 +341,27 @@ impl Processor for TransactionsProcessor<'_> {
.set_value(Some("<unlabeled transaction>".to_owned()))
}

// Apply the rule if any found
self.apply_transaction_rename_rule(
&mut event.transaction,
event.transaction_info.value_mut(),
)?;

// Normalize transaction names for URLs and Sanitized transaction sources.
// This in addition to renaming rules can catch some high cardinality parts.
if matches!(
event.get_transaction_source(),
&TransactionSource::Url | &TransactionSource::Sanitized
) && self.name_config.scrub_identifiers
{
let changed = scrub_identifiers(&mut event.transaction)?;
if changed && self.name_config.mark_scrubbed_as_sanitized {
let source = &mut event
.transaction_info
.get_or_insert_with(Default::default)
.source;
source.set_value(Some(TransactionSource::Sanitized));
if self.name_config.scrub_identifiers {
// Apply the rule if any found
self.apply_transaction_rename_rule(
&mut event.transaction,
event.transaction_info.value_mut(),
)?;

// Normalize transaction names for URLs and Sanitized transaction sources.
// This in addition to renaming rules can catch some high cardinality parts.
if matches!(
event.get_transaction_source(),
&TransactionSource::Url | &TransactionSource::Sanitized
) {
scrub_identifiers(&mut event.transaction)?;
if self.name_config.mark_scrubbed_as_sanitized {
event
.transaction_info
.get_or_insert_with(Default::default)
.source
.set_value(Some(TransactionSource::Sanitized));
}
}
}

Expand Down Expand Up @@ -1720,6 +1721,7 @@ mod tests {
process_value(
&mut event,
&mut TransactionsProcessor::new(TransactionNameConfig {
scrub_identifiers: true,
rules: rules.as_ref(),
..Default::default()
}),
Expand Down Expand Up @@ -1776,6 +1778,7 @@ mod tests {
process_value(
&mut event,
&mut TransactionsProcessor::new(TransactionNameConfig {
scrub_identifiers: true,
rules: rules.as_ref(),
..Default::default()
}),
Expand All @@ -1784,45 +1787,51 @@ mod tests {
.unwrap();

assert_annotated_snapshot!(event, @r###"
{
"type": "transaction",
"transaction": "/foo/*/user/123/0/",
"transaction_info": {
"source": "sanitized"
},
"modules": {
"rack": "1.2.3"
},
"timestamp": 1619420400.0,
"start_timestamp": 1619420341.0,
"contexts": {
"trace": {
"trace_id": "4c79f60c11214eb38604f4ae0781bfb2",
"span_id": "fa90fdead5f74053",
"op": "rails.request",
"status": "ok",
"type": "trace"
}
},
"sdk": {
"name": "sentry.ruby"
},
"spans": [],
"_meta": {
"transaction": {
"": {
"rem": [
[
"/foo/*/**",
"s"
]
],
"val": "/foo/2fd4e1c67a2d28fced849ee1bb76e7391b93eb12/user/123/0/"
}
}
}
}
"###);
{
"type": "transaction",
"transaction": "/foo/*/user/*/0/",
"transaction_info": {
"source": "sanitized"
},
"modules": {
"rack": "1.2.3"
},
"timestamp": 1619420400.0,
"start_timestamp": 1619420341.0,
"contexts": {
"trace": {
"trace_id": "4c79f60c11214eb38604f4ae0781bfb2",
"span_id": "fa90fdead5f74053",
"op": "rails.request",
"status": "ok",
"type": "trace"
}
},
"sdk": {
"name": "sentry.ruby"
},
"spans": [],
"_meta": {
"transaction": {
"": {
"rem": [
[
"/foo/*/**",
"s"
],
[
"int",
"s",
12,
15
]
],
"val": "/foo/*/user/123/0/"
}
}
}
}
"###);
}

#[test]
Expand Down Expand Up @@ -1933,6 +1942,7 @@ mod tests {
process_value(
&mut event,
&mut TransactionsProcessor::new(TransactionNameConfig {
scrub_identifiers: true,
rules: &[rule],
..Default::default()
}),
Expand Down