Skip to content

Add support for db.query.summary in SqlClientAttributesExtractor#15971

Merged
trask merged 19 commits intoopen-telemetry:mainfrom
trask:sql-summary
Jan 23, 2026
Merged

Add support for db.query.summary in SqlClientAttributesExtractor#15971
trask merged 19 commits intoopen-telemetry:mainfrom
trask:sql-summary

Conversation

@trask
Copy link
Copy Markdown
Member

@trask trask commented Jan 23, 2026

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.

trask added 12 commits January 22, 2026 20:15
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`
@trask trask marked this pull request as ready for review January 23, 2026 05:47
@trask trask requested a review from a team as a code owner January 23, 2026 05:47
HEX_NUM = "0x" ([a-f] | [A-F] | [0-9])+
QUOTED_STR = "'" ("''" | [^'])* "'"
DOUBLE_QUOTED_STR = "\"" ("\"\"" | [^\"])* "\""
DOLLAR_QUOTED_STR = "$$" [^$]* "$$"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should is return s.replace(doubleQuote, quote);?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertThat(result.getQuerySummary()).isEqualTo(expected.getQuerySummary());
} else {
assertThat(result.getOperationName()).isEqualTo(expected.getOperationName());
assertThat(result.getCollectionName()).isEqualToIgnoringCase(expected.getCollectionName());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// MySQL escaped backticks
Arguments.of(
"SELECT * FROM `my``table`", expect("SELECT", "my``table", "SELECT `my``table`")),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"my``table" should probably be "my`table"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@trask trask merged commit 7b5426f into open-telemetry:main Jan 23, 2026
85 checks passed
@trask trask deleted the sql-summary branch January 23, 2026 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants