From b8432d33c277f5dd1b8c50128b2b9e313d934e5f Mon Sep 17 00:00:00 2001 From: Ahmed Mohamed Date: Wed, 3 Dec 2025 11:18:16 -0500 Subject: [PATCH 1/3] hash the normalized db query and store it in a new attribute --- relay-conventions/sentry-conventions | 2 +- relay-event-normalization/src/eap/mod.rs | 12 ++++++++++++ tests/integration/test_spansv2.py | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/relay-conventions/sentry-conventions b/relay-conventions/sentry-conventions index 8d771c22d3..41c0567274 160000 --- a/relay-conventions/sentry-conventions +++ b/relay-conventions/sentry-conventions @@ -1 +1 @@ -Subproject commit 8d771c22d32f058e33c32245dc538f654623b6a7 +Subproject commit 41c05672741a578e2f3ce1ae9cb4985d182f9693 diff --git a/relay-event-normalization/src/eap/mod.rs b/relay-event-normalization/src/eap/mod.rs index f300062ca8..18f894ef53 100644 --- a/relay-event-normalization/src/eap/mod.rs +++ b/relay-event-normalization/src/eap/mod.rs @@ -387,7 +387,11 @@ pub fn normalize_db_attributes(annotated_attributes: &mut Annotated) if let Some(attributes) = annotated_attributes.value_mut() { if let Some(normalized_db_query) = normalized_db_query { + let mut normalized_db_query_hash = format!("{:?}", md5::compute(&normalized_db_query)); + normalized_db_query_hash.truncate(16); + attributes.insert(NORMALIZED_DB_QUERY, normalized_db_query); + attributes.insert("sentry.normalized_db_query.hash", normalized_db_query_hash); } if let Some(db_operation_name) = db_operation { attributes.insert(DB_OPERATION_NAME, db_operation_name) @@ -927,6 +931,10 @@ mod tests { "type": "string", "value": "SELECT %s" }, + "sentry.normalized_db_query.hash": { + "type": "string", + "value": "3a377dcc490b1690" + }, "sentry.op": { "type": "string", "value": "db.query" @@ -993,6 +1001,10 @@ mod tests { "type": "string", "value": "{\"find\":\"documents\",\"foo\":\"?\"}" }, + "sentry.normalized_db_query.hash": { + "type": "string", + "value": "aedc5c7e8cec726b" + }, "sentry.op": { "type": "string", "value": "db" diff --git a/tests/integration/test_spansv2.py b/tests/integration/test_spansv2.py index 333caedcae..7c9494f802 100644 --- a/tests/integration/test_spansv2.py +++ b/tests/integration/test_spansv2.py @@ -967,6 +967,10 @@ def test_spansv2_attribute_normalization( "type": "string", "value": "SELECT id FROM users WHERE id = %s AND name = %s", }, + "sentry.normalized_db_query.hash": { + "type": "string", + "value": "f79af0ba3d26284c", + }, "sentry.observed_timestamp_nanos": { "type": "string", "value": time_within(ts, expect_resolution="ns"), From 5160ce2a764bbc46c2661b8df4c2c9be1d9dd9aa Mon Sep 17 00:00:00 2001 From: Ahmed Mohamed Date: Wed, 3 Dec 2025 12:59:03 -0500 Subject: [PATCH 2/3] add normalized db query hash attribute to relay conventions consts --- relay-conventions/src/consts.rs | 1 + relay-event-normalization/src/eap/mod.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/relay-conventions/src/consts.rs b/relay-conventions/src/consts.rs index c4a437b690..1fb941fa13 100644 --- a/relay-conventions/src/consts.rs +++ b/relay-conventions/src/consts.rs @@ -54,6 +54,7 @@ convention_attributes!( IS_REMOTE => "sentry.is_remote", MESSAGING_SYSTEM => "messaging.system", NORMALIZED_DB_QUERY => "sentry.normalized_db_query", + NORMALIZED_DB_QUERY_HASH => "sentry.normalized_db_query.hash", OBSERVED_TIMESTAMP_NANOS => "sentry.observed_timestamp_nanos", OP => "sentry.op", ORIGIN => "sentry.origin", diff --git a/relay-event-normalization/src/eap/mod.rs b/relay-event-normalization/src/eap/mod.rs index 18f894ef53..4826a37178 100644 --- a/relay-event-normalization/src/eap/mod.rs +++ b/relay-event-normalization/src/eap/mod.rs @@ -391,7 +391,7 @@ pub fn normalize_db_attributes(annotated_attributes: &mut Annotated) normalized_db_query_hash.truncate(16); attributes.insert(NORMALIZED_DB_QUERY, normalized_db_query); - attributes.insert("sentry.normalized_db_query.hash", normalized_db_query_hash); + attributes.insert(NORMALIZED_DB_QUERY_HASH, normalized_db_query_hash); } if let Some(db_operation_name) = db_operation { attributes.insert(DB_OPERATION_NAME, db_operation_name) From 531c130475e3978c845e4d261e6d8fc3220c89b4 Mon Sep 17 00:00:00 2001 From: Ahmed Mohamed Date: Thu, 4 Dec 2025 11:28:01 -0500 Subject: [PATCH 3/3] use lowercase hex instead of debug representation for md5 hash --- relay-event-normalization/src/eap/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relay-event-normalization/src/eap/mod.rs b/relay-event-normalization/src/eap/mod.rs index 4826a37178..38408a234c 100644 --- a/relay-event-normalization/src/eap/mod.rs +++ b/relay-event-normalization/src/eap/mod.rs @@ -387,7 +387,7 @@ pub fn normalize_db_attributes(annotated_attributes: &mut Annotated) if let Some(attributes) = annotated_attributes.value_mut() { if let Some(normalized_db_query) = normalized_db_query { - let mut normalized_db_query_hash = format!("{:?}", md5::compute(&normalized_db_query)); + let mut normalized_db_query_hash = format!("{:x}", md5::compute(&normalized_db_query)); normalized_db_query_hash.truncate(16); attributes.insert(NORMALIZED_DB_QUERY, normalized_db_query);