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(txnames): Use txNameReady flag #2139

Merged
merged 4 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

**Internal**:

- Add `txNameReady` flag to project config. ([#2128](https://github.com/getsentry/relay/pull/2128))
- Mark all URL transactions as `sanitized` when `txNameReady` flag is set. ([#2128](https://github.com/getsentry/relay/pull/2128), [#2139](https://github.com/getsentry/relay/pull/2139))
- Tag incoming errors with the new `sampled` field in case their DSC is sampled. ([#2026](https://github.com/getsentry/relay/pull/2026))

## 23.5.0
Expand Down
89 changes: 82 additions & 7 deletions relay-general/src/store/transactions/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use crate::types::{
pub struct TransactionNameConfig<'r> {
/// Rules for identifier replacement that were discovered by Sentry's transaction clusterer.
pub rules: &'r [TransactionNameRule],
/// True if URL transactions should be marked as sanitized, even if there are no rules.
pub ready: bool,
}

/// Rejects transactions based on required fields.
Expand Down Expand Up @@ -371,16 +373,17 @@ impl Processor for TransactionsProcessor<'_> {
.set_value(Some("<unlabeled transaction>".to_owned()))
}

// Normalize transaction names for URLs and Sanitized transaction sources.
// This in addition to renaming rules can catch some high cardinality parts.
let mut sanitized = false;
// If the project is marked as 'ready', always set the transaction source to sanitized.
let mut mark_as_sanitized = self.name_config.ready;

if matches!(
event.get_transaction_source(),
&TransactionSource::Url | &TransactionSource::Sanitized
) {
// Normalize transaction names for URLs and Sanitized transaction sources.
// This in addition to renaming rules can catch some high cardinality parts.
scrub_identifiers(&mut event.transaction)?.then(|| {
sanitized = true;
mark_as_sanitized = true;
});
}

Expand All @@ -390,10 +393,10 @@ impl Processor for TransactionsProcessor<'_> {
event.transaction_info.value_mut(),
)?;

sanitized = true;
mark_as_sanitized = true;
}

if sanitized && matches!(event.get_transaction_source(), &TransactionSource::Url) {
if mark_as_sanitized && matches!(event.get_transaction_source(), &TransactionSource::Url) {
event
.transaction_info
.get_or_insert_with(Default::default)
Expand Down Expand Up @@ -1677,6 +1680,67 @@ mod tests {
"###);
}

#[test]
/// When the `ready` flag is set, mark a transaction as `sanitized` even if there are no rules.
fn test_transaction_name_normalize_mark_as_sanitized_when_ready() {
let json = r#"
{
"type": "transaction",
"transaction": "/foo/bar/user/john/0",
"transaction_info": {
"source": "url"
},
"timestamp": "2021-04-26T08:00:00+0100",
"start_timestamp": "2021-04-26T07:59:01+0100",
"contexts": {
"trace": {
"trace_id": "4c79f60c11214eb38604f4ae0781bfb2",
"span_id": "fa90fdead5f74053",
"op": "rails.request",
"status": "ok"
}
}

}
"#;
let mut event = Annotated::<Event>::from_json(json).unwrap();

process_value(
&mut event,
&mut TransactionsProcessor::new(
TransactionNameConfig {
rules: &[],
ready: true,
},
false,
),
ProcessingState::root(),
)
.unwrap();

assert_annotated_snapshot!(event, @r###"
{
"type": "transaction",
"transaction": "/foo/bar/user/john/0",
"transaction_info": {
"source": "sanitized"
},
"timestamp": 1619420400.0,
"start_timestamp": 1619420341.0,
"contexts": {
"trace": {
"trace_id": "4c79f60c11214eb38604f4ae0781bfb2",
"span_id": "fa90fdead5f74053",
"op": "rails.request",
"status": "ok",
"type": "trace"
}
},
"spans": []
}
"###);
}

#[test]
fn test_transaction_name_rename_with_rules() {
let json = r#"
Expand Down Expand Up @@ -1730,6 +1794,7 @@ mod tests {
&mut TransactionsProcessor::new(
TransactionNameConfig {
rules: rules.as_ref(),
ready: false,
},
false,
),
Expand Down Expand Up @@ -1794,6 +1859,7 @@ mod tests {
&mut TransactionsProcessor::new(
TransactionNameConfig {
rules: rules.as_ref(),
ready: false,
},
false,
),
Expand Down Expand Up @@ -1892,6 +1958,7 @@ mod tests {
&mut TransactionsProcessor::new(
TransactionNameConfig {
rules: rules.as_ref(),
ready: false,
},
false,
),
Expand Down Expand Up @@ -1958,7 +2025,13 @@ mod tests {

process_value(
&mut event,
&mut TransactionsProcessor::new(TransactionNameConfig { rules: &[rule] }, false),
&mut TransactionsProcessor::new(
TransactionNameConfig {
rules: &[rule],
ready: false,
},
false,
),
ProcessingState::root(),
)
.unwrap();
Expand Down Expand Up @@ -2185,6 +2258,7 @@ mod tests {
scope: RuleScope::default(),
redaction: RedactionRule::default(),
}],
ready: false,
},
false,
),
Expand Down Expand Up @@ -2231,6 +2305,7 @@ mod tests {
scope: RuleScope::default(),
redaction: RedactionRule::default(),
}],
ready: false,
},
false,
),
Expand Down
2 changes: 2 additions & 0 deletions relay-server/src/actors/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2378,6 +2378,7 @@ impl EnvelopeProcessorService {
normalize_user_agent: Some(true),
transaction_name_config: TransactionNameConfig {
rules: &state.project_state.config.tx_name_rules,
ready: state.project_state.config.tx_name_ready,
},
device_class_synthesis_config: state
.project_state
Expand Down Expand Up @@ -3736,6 +3737,7 @@ mod tests {
substitution: "*".to_owned(),
},
}],
ready: false,
},
..Default::default()
};
Expand Down
Loading