Add support for db.query.summary in SqlClientAttributesExtractor#15971
Add support for db.query.summary in SqlClientAttributesExtractor#15971trask merged 19 commits intoopen-telemetry:mainfrom
db.query.summary in SqlClientAttributesExtractor#15971Conversation
Example: SELECT * FROM t1 LEFT JOIN t2 ON t1.id = t2.id JOIN t3 ON t2.x = t3.x Summary was: SELECT t1 t2 Summary now: SELECT t1 t2 t3
Example: select col from (select * from anotherTable) Summary was: SELECT SELECT Summary now: SELECT SELECT anotherTable
Example: INSERT INTO t1 SELECT * FROM t2 Summary was: INSERT t1 Summary now: INSERT t1 SELECT t2
Example: SELECT * FROM (SELECT * FROM inner1 JOIN inner2 ON inner1.id = inner2.id) AS sub Summary was: SELECT SELECT inner1 inner2 AS Summary now: SELECT SELECT inner1 inner2
Example: SELECT * FROM (VALUES (1,2), (3,4)) AS t(a, b) Summary was: SELECT AS Summary now: SELECT
Example: SELECT * FROM t1 CROSS APPLY t2 Summary was: SELECT t1 Summary now: SELECT t1 t2
Example: SELECT * FROM t1; INSERT INTO t2 VALUES (1) Summary was: SELECT t1 INSERT t2 Summary now: SELECT t1; INSERT t2
Example: VALUES (1, 'a'), (2, 'b') Summary was: null Summary now: VALUES
Example: EXEC my_procedure @param=1 Summary was: null Summary now: EXEC my_procedure
Example: SELECT * FROM [my table] Summary was: SELECT Summary now: SELECT [my table]
Example: SELECT * FROM `my``table` Summary was: SELECT `my` Summary now: SELECT `my``table`
| HEX_NUM = "0x" ([a-f] | [A-F] | [0-9])+ | ||
| QUOTED_STR = "'" ("''" | [^'])* "'" | ||
| DOUBLE_QUOTED_STR = "\"" ("\"\"" | [^\"])* "\"" | ||
| DOLLAR_QUOTED_STR = "$$" [^$]* "$$" |
There was a problem hiding this comment.
FYI it is also possible to use$tag$<string_constant>$tag$ instead of just $$ https://neon.com/postgresql/postgresql-plpgsql/dollar-quoted-string-constants
There was a problem hiding this comment.
I'll follow up on it after this PR (even if only to document current state via tests)
| String doubleQuote = quote + quote; | ||
| String withoutEscapedQuotes = s.replace(doubleQuote, ""); | ||
| if (!withoutEscapedQuotes.contains(quote)) { | ||
| return s; |
There was a problem hiding this comment.
should is return s.replace(doubleQuote, quote);?
There was a problem hiding this comment.
oops, didn't intend to update this file, reverted in aca9248
| if (!identifierCaptured) { | ||
| appendTargetToSummary(); | ||
| identifierCaptured = true; | ||
| // Only set storedProcedureName if this is a real procedure call (not "call next value for sequence") |
There was a problem hiding this comment.
Perhaps we should add a comment that hibernate uses this query on hsqldb (we have a test that has this query there). Looking at hibernate sources it seems the same query is also used on h2, most of the other databases use a select for this.
Looks like it might be possible for it to also use call current value for sequence. Idk whether or when it is used. I think we can deal with this in complaint driven way if this really is an issue for someone.
| assertThat(result.getQuerySummary()).isEqualTo(expected.getQuerySummary()); | ||
| } else { | ||
| assertThat(result.getOperationName()).isEqualTo(expected.getOperationName()); | ||
| assertThat(result.getCollectionName()).isEqualToIgnoringCase(expected.getCollectionName()); |
There was a problem hiding this comment.
A bit surprised to see case insensitive comparison for collection name and proc name. Since we should preserve the case for these would have expected just isEqualTo here.
|
|
||
| // MySQL escaped backticks | ||
| Arguments.of( | ||
| "SELECT * FROM `my``table`", expect("SELECT", "my``table", "SELECT `my``table`")), |
There was a problem hiding this comment.
"my``table" should probably be "my`table"
There was a problem hiding this comment.
collection name got changed back now to just my (which of course is even more wrong) when I reverted the inadvertent changes to the old jflex
not planning to fix the old jflex, but this points out a likely problem in new jflex with stored procedure name capture, will follow-up on that after this PR
I've carefully broken out the commits to try to make review easier. I'm also happy to split the commits out into separate PRs.
db.query.summaryand removesdb.operation.nameanddb.collection.namewhere it was previously extracted fromdb.query.textto align with stable semconv. Hides this behavior behind marker interface so we can roll it out afterwards per instrumentation in smaller PRs.SELECT * FROM t1 LEFT JOIN t2 ON t1.id = t2.id JOIN t3 ON t2.x = t3.xSELECT t1 t2SELECT t1 t2 t3select col from (select * from anotherTable)SELECT SELECTSELECT SELECT anotherTableINSERT INTO t1 SELECT * FROM t2INSERT t1INSERT t1 SELECT t2SELECT * FROM (SELECT * FROM inner1 JOIN inner2 ON inner1.id = inner2.id) AS subSELECT SELECT inner1 inner2 ASSELECT SELECT inner1 inner2SELECT * FROM (VALUES (1,2), (3,4)) AS t(a, b)SELECT ASSELECTSELECT * FROM t1 CROSS APPLY t2SELECT t1SELECT t1 t2SELECT * FROM t1; INSERT INTO t2 VALUES (1)SELECT t1 INSERT t2SELECT t1; INSERT t2VALUES (1, 'a'), (2, 'b')nullVALUESEXEC my_procedure @param=1nullEXEC my_procedureSELECT * FROM [my table]SELECTSELECT [my table]SELECT * FROM `my``table`SELECT `my`SELECT `my``table`