diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d62c35a7f8..3c2836868e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ - Extend GPU context with data for Unreal Engine crash reports. ([#3144](https://github.com/getsentry/relay/pull/3144)) - Parametrize transaction in dynamic sampling context. ([#3141](https://github.com/getsentry/relay/pull/3141)) -- Parse & scrub span description for supabase. ([#3153](https://github.com/getsentry/relay/pull/3153)) +- Parse & scrub span description for supabase. ([#3153](https://github.com/getsentry/relay/pull/3153), [#3156](https://github.com/getsentry/relay/pull/3156)) **Bug Fixes**: diff --git a/relay-event-normalization/src/normalize/span/description/mod.rs b/relay-event-normalization/src/normalize/span/description/mod.rs index da659dc564d..2b6dc3bbf22 100644 --- a/relay-event-normalization/src/normalize/span/description/mod.rs +++ b/relay-event-normalization/src/normalize/span/description/mod.rs @@ -71,7 +71,9 @@ pub(crate) fn scrub_span_description( // The description will only contain the entity queried and // the query type ("User find" for example). Some(description.to_owned()) - } else if span_origin == Some("auto.db.supabase") { + } else if span_origin == Some("auto.db.supabase") + && description.starts_with("from(") + { // The description only contains the table name, e.g. `"from(users)`. // In the future, we might want to parse `data.query` as well. // See https://github.com/supabase-community/sentry-integration-js/blob/master/index.js#L259 @@ -148,10 +150,7 @@ fn scrub_core_data(string: &str) -> Option { } fn scrub_supabase(string: &str) -> Option { - match DB_SUPABASE_REGEX.replace_all(string, "{%s}") { - Cow::Owned(scrubbed) => Some(scrubbed), - Cow::Borrowed(_) => None, - } + Some(DB_SUPABASE_REGEX.replace_all(string, "{%s}").into()) } fn scrub_http(string: &str) -> Option { diff --git a/relay-event-normalization/src/normalize/span/tag_extraction.rs b/relay-event-normalization/src/normalize/span/tag_extraction.rs index 44a78e7325e..577e71c7188 100644 --- a/relay-event-normalization/src/normalize/span/tag_extraction.rs +++ b/relay-event-normalization/src/normalize/span/tag_extraction.rs @@ -366,11 +366,11 @@ pub fn extract_tags( None } } else if span.origin.as_str() == Some("auto.db.supabase") { - scrubbed_description.as_deref().map(|s| { - s.trim_start_matches("from(") - .trim_end_matches(')') - .to_owned() - }) + scrubbed_description + .as_deref() + .and_then(|s| s.strip_prefix("from(")) + .and_then(|s| s.strip_suffix(')')) + .map(String::from) } else if span_op.starts_with("db") { span.description .value() @@ -1435,10 +1435,9 @@ LIMIT 1 ); } - #[test] - fn supabase() { + fn extract_tags_supabase(description: impl Into) -> BTreeMap { let json = r#"{ - "description": "from(my_table00)", + "description": "from(my_table)", "op": "db.select", "origin": "auto.db.supabase", "data": { @@ -1449,12 +1448,13 @@ LIMIT 1 } }"#; - let span = Annotated::::from_json(json) + let mut span = Annotated::::from_json(json) .unwrap() .into_value() .unwrap(); + span.description.set_value(Some(description.into())); - let tags = extract_tags( + extract_tags( &span, &Config { max_tag_value_size: 200, @@ -1463,7 +1463,25 @@ LIMIT 1 None, false, None, + ) + } + + #[test] + fn supabase() { + let tags = extract_tags_supabase("from(mytable)"); + assert_eq!( + tags.get(&SpanTagKey::Description).map(String::as_str), + Some("from(mytable)") ); + assert_eq!( + tags.get(&SpanTagKey::Domain).map(String::as_str), + Some("mytable") + ); + } + + #[test] + fn supabase_with_identifiers() { + let tags = extract_tags_supabase("from(my_table00)"); assert_eq!( tags.get(&SpanTagKey::Description).map(String::as_str), @@ -1474,4 +1492,12 @@ LIMIT 1 Some("my_table{%s}") ); } + + #[test] + fn supabase_unsupported() { + let tags = extract_tags_supabase("something else"); + + assert_eq!(tags.get(&SpanTagKey::Description), None); + assert_eq!(tags.get(&SpanTagKey::Domain), None); + } }