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

fix(spans): Use db.system for SQL parsing #2536

Merged
merged 2 commits into from
Sep 26, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Remove profile_id from context when no profile is in the envelope. ([#2523](https://github.com/getsentry/relay/pull/2523))
- Fix reporting of Relay's crashes to Sentry. The `crash-handler` feature did not enable the crash reporter and uploads of crashes were broken. ([#2532](https://github.com/getsentry/relay/pull/2532))
- Use correct field to pick SQL parser for span normalization. ([#2536](https://github.com/getsentry/relay/pull/2536))

**Internal**:

Expand Down
29 changes: 27 additions & 2 deletions relay-event-normalization/src/normalize/span/description/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(crate) fn scrub_span_description(span: &mut Span, rules: &Vec<SpanDescriptio
("db", _) => sql::scrub_queries(
span.data
.value()
.and_then(|d| d.get("system"))
.and_then(|d| d.get("db.system"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.and_then(|v| v.as_str()),
description,
),
Expand Down Expand Up @@ -217,7 +217,6 @@ fn apply_span_rename_rules(span: &mut Span, rules: &Vec<SpanDescriptionRule>) ->

#[cfg(test)]
mod tests {

use similar_asserts::assert_eq;

use super::*;
Expand Down Expand Up @@ -428,4 +427,30 @@ mod tests {
"resource.css",
""
);

#[test]
fn informed_sql_parser() {
let json = r#"
{
"description": "SELECT \"not an identifier\"",
"span_id": "bd2eb23da2beb459",
"start_timestamp": 1597976393.4619668,
"timestamp": 1597976393.4718769,
"trace_id": "ff62a8b040f340bda5d830223def1d81",
"op": "db",
"data": {"db.system": "mysql"}
}
"#;

let mut span = Annotated::<Span>::from_json(json).unwrap();
let span = span.value_mut().as_mut().unwrap();
scrub_span_description(span, &vec![]);
let scrubbed = span
.data
.value()
.and_then(|d| d.get("description.scrubbed"))
.and_then(|v| v.value())
.and_then(|v| v.as_str());
assert_eq!(scrubbed, Some("SELECT %s"));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix, this would be SELECT not an identifier, because the default parser would assume that double quotes delimit an identifier.

}
}