Skip to content

Commit e0217ea

Browse files
committed
multiple tables per operation
1 parent 2b193cd commit e0217ea

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ WHITESPACE = [ \t\r\n]+
270270
boolean expectingTableName = false;
271271
boolean mainTableSetAlready = false;
272272
int identifiersAfterMainFromClause = 0;
273+
// Tracks whether we're in a comma-separated table list (implicit join)
274+
boolean inImplicitJoin = false;
275+
// Counter for identifiers after each comma in implicit join
276+
int identifiersAfterComma = 0;
273277

274278
boolean handleFrom() {
275279
if (parenLevel == 0) {
@@ -294,6 +298,17 @@ WHITESPACE = [ \t\r\n]+
294298
++identifiersAfterMainFromClause;
295299
}
296300

301+
// Handle identifiers in implicit join (comma-separated tables)
302+
if (inImplicitJoin) {
303+
++identifiersAfterComma;
304+
// First identifier after comma is the table name - add it to summary
305+
if (identifiersAfterComma == 1) {
306+
String tableName = readIdentifierName();
307+
appendTargetToSummary(tableName);
308+
}
309+
return false;
310+
}
311+
297312
if (!expectingTableName) {
298313
return false;
299314
}
@@ -328,7 +343,14 @@ WHITESPACE = [ \t\r\n]+
328343
if (identifiersAfterMainFromClause > 0
329344
&& identifiersAfterMainFromClause <= FROM_TABLE_REF_MAX_IDENTIFIERS) {
330345
mainIdentifier = null;
331-
return true;
346+
inImplicitJoin = true;
347+
identifiersAfterComma = 0;
348+
// Don't return true - continue processing to capture more table names for summary
349+
return false;
350+
}
351+
// Reset counter for next table in implicit join
352+
if (inImplicitJoin) {
353+
identifiersAfterComma = 0;
332354
}
333355
return false;
334356
}

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ void querySummaryIsTruncated() {
173173
String result = SqlStatementSanitizer.create(true).sanitize(sql.toString()).getQuerySummary();
174174
assertThat(result).isNotNull();
175175
assertThat(result.length()).isLessThanOrEqualTo(255);
176-
// For implicit join (comma-separated tables), mainIdentifier is null so only first table is in
177-
// summary
178-
assertThat(result).isEqualTo("SELECT very_long_table_name_0");
176+
// Implicit join (comma-separated tables) should include all table names in the summary
177+
// but truncated at 255 characters
178+
assertThat(result).startsWith("SELECT very_long_table_name_0 very_long_table_name_1");
179179
}
180180

181181
private static Stream<Arguments> sqlArgs() {
@@ -341,11 +341,21 @@ private static Stream<Arguments> simplifyArgs() {
341341
Arguments.of(
342342
"select col from table where col in (select * from anotherTable)",
343343
expect("SELECT", null, "SELECT table SELECT anotherTable")),
344-
Arguments.of("select col from table1, table2", expect("SELECT", null, "SELECT table1")),
345344
Arguments.of(
346-
"select col from table1 t1, table2 t2", expect("SELECT", null, "SELECT table1")),
345+
"select col from table1, table2", expect("SELECT", null, "SELECT table1 table2")),
347346
Arguments.of(
348-
"select col from table1 as t1, table2 as t2", expect("SELECT", null, "SELECT table1")),
347+
"select col from table1 t1, table2 t2", expect("SELECT", null, "SELECT table1 table2")),
348+
Arguments.of(
349+
"select col from table1 as t1, table2 as t2",
350+
expect("SELECT", null, "SELECT table1 table2")),
351+
// Example from semantic conventions: multiple tables in FROM clause
352+
Arguments.of(
353+
"SELECT * FROM songs, artists WHERE songs.artist_id = artists.id",
354+
expect(
355+
"SELECT * FROM songs, artists WHERE songs.artist_id = artists.id",
356+
"SELECT",
357+
null,
358+
"SELECT songs artists")),
349359
Arguments.of(
350360
"select col from table where col in (1, 2, 3)",
351361
expect("select col from table where col in (?)", "SELECT", "table", "SELECT table")),

0 commit comments

Comments
 (0)