Skip to content

Commit fbc02f7

Browse files
committed
hash the normalized db query and store it in a new attribute
1 parent 5942373 commit fbc02f7

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

relay-event-normalization/src/eap/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,11 @@ pub fn normalize_db_attributes(annotated_attributes: &mut Annotated<Attributes>)
387387

388388
if let Some(attributes) = annotated_attributes.value_mut() {
389389
if let Some(normalized_db_query) = normalized_db_query {
390+
let mut normalized_db_query_hash = format!("{:?}", md5::compute(&normalized_db_query));
391+
normalized_db_query_hash.truncate(16);
392+
390393
attributes.insert(NORMALIZED_DB_QUERY, normalized_db_query);
394+
attributes.insert("sentry.normalized_db_query.hash", normalized_db_query_hash);
391395
}
392396
if let Some(db_operation_name) = db_operation {
393397
attributes.insert(DB_OPERATION_NAME, db_operation_name)
@@ -927,6 +931,10 @@ mod tests {
927931
"type": "string",
928932
"value": "SELECT %s"
929933
},
934+
"sentry.normalized_db_query.hash": {
935+
"type": "string",
936+
"value": "3a377dcc490b1690"
937+
},
930938
"sentry.op": {
931939
"type": "string",
932940
"value": "db.query"
@@ -993,6 +1001,10 @@ mod tests {
9931001
"type": "string",
9941002
"value": "{\"find\":\"documents\",\"foo\":\"?\"}"
9951003
},
1004+
"sentry.normalized_db_query.hash": {
1005+
"type": "string",
1006+
"value": "aedc5c7e8cec726b"
1007+
},
9961008
"sentry.op": {
9971009
"type": "string",
9981010
"value": "db"

tests/integration/test_spansv2.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,10 @@ def test_spansv2_attribute_normalization(
967967
"type": "string",
968968
"value": "SELECT id FROM users WHERE id = %s AND name = %s",
969969
},
970+
"sentry.normalized_db_query.hash": {
971+
"type": "string",
972+
"value": "f79af0ba3d26284c",
973+
},
970974
"sentry.observed_timestamp_nanos": {
971975
"type": "string",
972976
"value": time_within(ts, expect_resolution="ns"),

0 commit comments

Comments
 (0)