Skip to content

Commit 2aa9083

Browse files
committed
preserve quotes
1 parent e0217ea commit 2aa9083

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

instrumentation-api-incubator/src/main/jflex/SqlSanitizer.jflex

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ WHITESPACE = [ \t\r\n]+
238238
boolean handleIdentifier() {
239239
if (shouldHandleIdentifier()) {
240240
mainIdentifier = readIdentifierName();
241-
appendTargetToSummary(mainIdentifier);
241+
// Use yytext() to preserve quotes in query summary per semantic conventions
242+
appendTargetToSummary(yytext());
242243
}
243244
return true;
244245
}
@@ -303,8 +304,8 @@ WHITESPACE = [ \t\r\n]+
303304
++identifiersAfterComma;
304305
// First identifier after comma is the table name - add it to summary
305306
if (identifiersAfterComma == 1) {
306-
String tableName = readIdentifierName();
307-
appendTargetToSummary(tableName);
307+
// Use yytext() to preserve quotes in query summary per semantic conventions
308+
appendTargetToSummary(yytext());
308309
}
309310
return false;
310311
}
@@ -326,7 +327,8 @@ WHITESPACE = [ \t\r\n]+
326327
}
327328

328329
mainIdentifier = readIdentifierName();
329-
appendTargetToSummary(mainIdentifier);
330+
// Use yytext() to preserve quotes in query summary per semantic conventions
331+
appendTargetToSummary(yytext());
330332
mainTableSetAlready = true;
331333
expectingTableName = false;
332334
// start counting identifiers after encountering main from clause
@@ -370,7 +372,8 @@ WHITESPACE = [ \t\r\n]+
370372
}
371373

372374
mainIdentifier = readIdentifierName();
373-
appendTargetToSummary(mainIdentifier);
375+
// Use yytext() to preserve quotes in query summary per semantic conventions
376+
appendTargetToSummary(yytext());
374377
return true;
375378
}
376379
}
@@ -389,23 +392,26 @@ WHITESPACE = [ \t\r\n]+
389392
}
390393

391394
mainIdentifier = readIdentifierName();
392-
appendTargetToSummary(mainIdentifier);
395+
// Use yytext() to preserve quotes in query summary per semantic conventions
396+
appendTargetToSummary(yytext());
393397
return true;
394398
}
395399
}
396400

397401
private class Update extends Operation {
398402
boolean handleIdentifier() {
399403
mainIdentifier = readIdentifierName();
400-
appendTargetToSummary(mainIdentifier);
404+
// Use yytext() to preserve quotes in query summary per semantic conventions
405+
appendTargetToSummary(yytext());
401406
return true;
402407
}
403408
}
404409

405410
private class Call extends Operation {
406411
boolean handleIdentifier() {
407412
mainIdentifier = readIdentifierName();
408-
appendTargetToSummary(mainIdentifier);
413+
// Use yytext() to preserve quotes in query summary per semantic conventions
414+
appendTargetToSummary(yytext());
409415
return true;
410416
}
411417

@@ -418,7 +424,8 @@ WHITESPACE = [ \t\r\n]+
418424
private class Merge extends Operation {
419425
boolean handleIdentifier() {
420426
mainIdentifier = readIdentifierName();
421-
appendTargetToSummary(mainIdentifier);
427+
// Use yytext() to preserve quotes in query summary per semantic conventions
428+
appendTargetToSummary(yytext());
422429
return true;
423430
}
424431
}

instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlStatementSanitizerTest.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,13 @@ private static Stream<Arguments> simplifyArgs() {
306306
expect("SELECT", "schema.table", "SELECT schema.table")),
307307
Arguments.of(
308308
"SELECT x, y, z FROM `schema table`",
309-
expect("SELECT", "schema table", "SELECT schema table")),
309+
expect("SELECT", "schema table", "SELECT `schema table`")),
310310
Arguments.of(
311311
"SELECT x, y, z FROM `schema`.`table`",
312312
expect("SELECT", "`schema`.`table`", "SELECT `schema`.`table`")),
313313
Arguments.of(
314314
"SELECT x, y, z FROM \"schema table\"",
315-
expect("SELECT", "schema table", "SELECT schema table")),
315+
expect("SELECT", "schema table", "SELECT \"schema table\"")),
316316
Arguments.of(
317317
"SELECT x, y, z FROM \"schema\".\"table\"",
318318
expect("SELECT", "\"schema\".\"table\"", "SELECT \"schema\".\"table\"")),
@@ -391,10 +391,11 @@ private static Stream<Arguments> simplifyArgs() {
391391
Arguments.of(
392392
"insert into db.table where lalala", expect("INSERT", "db.table", "INSERT db.table")),
393393
Arguments.of(
394-
"insert into `db table` where lalala", expect("INSERT", "db table", "INSERT db table")),
394+
"insert into `db table` where lalala",
395+
expect("INSERT", "db table", "INSERT `db table`")),
395396
Arguments.of(
396397
"insert into \"db table\" where lalala",
397-
expect("INSERT", "db table", "INSERT db table")),
398+
expect("INSERT", "db table", "INSERT \"db table\"")),
398399
Arguments.of("insert without i-n-t-o", expect("INSERT", null, "INSERT")),
399400

400401
// Delete
@@ -403,10 +404,10 @@ private static Stream<Arguments> simplifyArgs() {
403404
expect("DELETE", "table", "DELETE table")),
404405
Arguments.of(
405406
"delete from `my table` where something something",
406-
expect("DELETE", "my table", "DELETE my table")),
407+
expect("DELETE", "my table", "DELETE `my table`")),
407408
Arguments.of(
408409
"delete from \"my table\" where something something",
409-
expect("DELETE", "my table", "DELETE my table")),
410+
expect("DELETE", "my table", "DELETE \"my table\"")),
410411
Arguments.of(
411412
"delete from foo where x IN (1,2,3)",
412413
expect("delete from foo where x IN (?)", "DELETE", "foo", "DELETE foo")),
@@ -419,17 +420,18 @@ private static Stream<Arguments> simplifyArgs() {
419420
expect("update table set answer=?", "UPDATE", "table", "UPDATE table")),
420421
Arguments.of(
421422
"update `my table` set answer=42",
422-
expect("update `my table` set answer=?", "UPDATE", "my table", "UPDATE my table")),
423+
expect("update `my table` set answer=?", "UPDATE", "my table", "UPDATE `my table`")),
423424
Arguments.of(
424425
"update `my table` set answer=42 where x IN('a', 'b') AND y In ('a', 'b')",
425426
expect(
426427
"update `my table` set answer=? where x IN(?) AND y In (?)",
427428
"UPDATE",
428429
"my table",
429-
"UPDATE my table")),
430+
"UPDATE `my table`")),
430431
Arguments.of(
431432
"update \"my table\" set answer=42",
432-
expect("update \"my table\" set answer=?", "UPDATE", "my table", "UPDATE my table")),
433+
expect(
434+
"update \"my table\" set answer=?", "UPDATE", "my table", "UPDATE \"my table\"")),
433435
Arguments.of("update /*table", expect("UPDATE", null, "UPDATE")),
434436

435437
// Call
@@ -440,8 +442,8 @@ private static Stream<Arguments> simplifyArgs() {
440442

441443
// Merge
442444
Arguments.of("merge into table", expect("MERGE", "table", "MERGE table")),
443-
Arguments.of("merge into `my table`", expect("MERGE", "my table", "MERGE my table")),
444-
Arguments.of("merge into \"my table\"", expect("MERGE", "my table", "MERGE my table")),
445+
Arguments.of("merge into `my table`", expect("MERGE", "my table", "MERGE `my table`")),
446+
Arguments.of("merge into \"my table\"", expect("MERGE", "my table", "MERGE \"my table\"")),
445447
Arguments.of(
446448
"merge table (into is optional in some dbs)", expect("MERGE", "table", "MERGE table")),
447449
Arguments.of("merge (into )))", expect("MERGE", null, "MERGE")),
@@ -454,11 +456,12 @@ private static Stream<Arguments> simplifyArgs() {
454456

455457
private static Stream<Arguments> ddlArgs() {
456458
return Stream.of(
457-
Arguments.of("CREATE TABLE `table`", expect("CREATE TABLE", "table", "CREATE TABLE table")),
459+
Arguments.of(
460+
"CREATE TABLE `table`", expect("CREATE TABLE", "table", "CREATE TABLE `table`")),
458461
Arguments.of(
459462
"CREATE TABLE IF NOT EXISTS table",
460463
expect("CREATE TABLE", "table", "CREATE TABLE table")),
461-
Arguments.of("DROP TABLE `if`", expect("DROP TABLE", "if", "DROP TABLE if")),
464+
Arguments.of("DROP TABLE `if`", expect("DROP TABLE", "if", "DROP TABLE `if`")),
462465
Arguments.of(
463466
"ALTER TABLE table ADD CONSTRAINT c FOREIGN KEY (foreign_id) REFERENCES ref (id)",
464467
expect("ALTER TABLE", "table", "ALTER TABLE table")),

0 commit comments

Comments
 (0)