Skip to content

Preserve SQL query summary operation case#18930

Merged
laurit merged 17 commits into
open-telemetry:mainfrom
trask:fix-stable-sql-summary-case
Jun 9, 2026
Merged

Preserve SQL query summary operation case#18930
laurit merged 17 commits into
open-telemetry:mainfrom
trask:fix-stable-sql-summary-case

Conversation

@trask

@trask trask commented Jun 7, 2026

Copy link
Copy Markdown
Member

Preserve the original case of SQL operation keywords when building stable query summaries. This switches matched operation tokens to use the lexer text consistently, including nested SELECTs and top-level VALUES, and adds coverage across supported summary operations.

@trask
trask requested a review from a team as a code owner June 7, 2026 05:33
Copilot AI review requested due to automatic review settings June 7, 2026 05:33
@trask
trask marked this pull request as draft June 7, 2026 05:34

Copilot AI left a comment

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.

Pull request overview

This PR updates the SQL query summary lexer to preserve the original case of operation keywords (e.g., select vs SELECT) when building stable query summaries, and expands test coverage to validate case preservation across supported summary operations and nested SELECT scenarios.

Changes:

  • Switched query-summary operation tokens to use the lexer’s matched text (yytext()) instead of hard-coded uppercase keywords.
  • Updated nested/embedded SELECT handling to propagate the matched operation text through handleSelect(...).
  • Added/updated tests to assert query summaries preserve the input operation keyword case across many operations (including nested SELECTs and top-level VALUES).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
instrumentation-api-incubator/src/main/jflex/SqlSanitizerWithSummary.jflex Uses matched lexer text for operation keywords and threads original SELECT token text through operation handling to preserve case in summaries.
instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlQueryAnalyzerTest.java Adds a parameterized test for operation-case preservation and updates existing summary expectations to reflect case-preserving behavior.

@trask
trask force-pushed the fix-stable-sql-summary-case branch from d549bc9 to 61a9870 Compare June 8, 2026 02:50
@trask
trask requested a review from Copilot June 8, 2026 03:02

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

@trask
trask force-pushed the fix-stable-sql-summary-case branch from 5dc9919 to d857c00 Compare June 8, 2026 03:24
@trask
trask requested a review from Copilot June 8, 2026 03:25

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

trask added 3 commits June 7, 2026 21:30
SQL query summaries now preserve the operation casing from the original statement.
Stable database semconv tests were still expecting canonical uppercase summaries
and span names for lowercase generated SQL, causing the CI failures. Update the
affected Camel, Hibernate, and Vert.x expectations to match the preserved case
while leaving uppercase native SQL expectations unchanged.

Validation: .\gradlew.bat :instrumentation-api-incubator:test --tests io.opentelemetry.instrumentation.api.incubator.semconv.db.SqlQueryAnalyzerTest --tests io.opentelemetry.instrumentation.api.incubator.semconv.db.SqlQuerySummaryEdgeCasesTest; .\gradlew.bat :instrumentation:hibernate:hibernate-6.0:javaagent:hibernate6TestStableSemconv; .\gradlew.bat :instrumentation:camel-2.20:javaagent-unit-tests:testStableSemconv :instrumentation:camel-2.20:javaagent:testStableSemconv :instrumentation:hibernate:hibernate-6.0:javaagent:hibernate6TestStableSemconv :instrumentation:hibernate:hibernate-6.0:spring-testing:testStableSemconv :instrumentation:hibernate:hibernate-reactive-1.0:javaagent:hibernateReactive1TestStableSemconv :instrumentation:vertx:vertx-sql-client:vertx-sql-client-4.0:javaagent:testStableSemconv; .\gradlew.bat spotlessCheck

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated no new comments.

trask added 2 commits June 8, 2026 10:11
Stable database semantic convention query summaries are emitted with lowercase
SQL operation names by the updated SQL analyzer. Several Hibernate, ClickHouse,
and Spring Data tests still expected uppercase stable span names or
db.query.summary values, causing the CI testStableSemconv jobs to fail. Update
the affected expectations to match the emitted stable semconv values while
preserving legacy-mode expectations.

Validation:
./gradlew.bat :instrumentation:hibernate:hibernate-6.0:javaagent:test --tests io.opentelemetry.javaagent.instrumentation.hibernate.v6_0.CriteriaTest --tests io.opentelemetry.javaagent.instrumentation.hibernate.v6_0.EntityManagerTest.testNoResultExceptionIgnored
./gradlew.bat :instrumentation:hibernate:hibernate-6.0:javaagent:testStableSemconv --tests io.opentelemetry.javaagent.instrumentation.hibernate.v6_0.CriteriaTest --tests io.opentelemetry.javaagent.instrumentation.hibernate.v6_0.EntityManagerTest.testNoResultExceptionIgnored
./gradlew.bat :instrumentation:hibernate:hibernate-6.0:spring-testing:test --tests spring.jpa.SpringJpaTest
./gradlew.bat :instrumentation:hibernate:hibernate-4.0:javaagent:testStableSemconv --tests io.opentelemetry.javaagent.instrumentation.hibernate.v4_0.CriteriaTest --tests io.opentelemetry.javaagent.instrumentation.hibernate.v4_0.EntityManagerTest.testNoResultExceptionIgnored --tests io.opentelemetry.javaagent.instrumentation.hibernate.v4_0.QueryTest.testHibernateQuerySingleCall
./gradlew.bat :instrumentation:hibernate:hibernate-3.3:javaagent:testStableSemconv --tests io.opentelemetry.javaagent.instrumentation.hibernate.v3_3.QueryTest
./gradlew.bat :instrumentation:clickhouse:clickhouse-client-v2-0.8:javaagent:testStableSemconv --tests io.opentelemetry.javaagent.instrumentation.clickhouse.clientv2.v0_8.ClickHouseClientV2Test
./gradlew.bat :instrumentation:spring:spring-data:spring-data-1.8:javaagent:testStableSemconv
Stable database semconv lowercases generated HQL/ORM query summaries and
span names, while native SQL keeps its SQL operation casing. The Hibernate
tests mixed those expectations, causing stable-semconv and latest-deps CI
failures after the PR changed the expected assertions. Update the affected
Hibernate 4 and 6 tests to expect lowercase generated query names and preserve
uppercase native SQL names, and run Spotless for the logged formatting issue.

Validation:
.\gradlew.bat :instrumentation:hibernate:hibernate-4.0:javaagent:testStableSemconv :instrumentation:hibernate:hibernate-6.0:javaagent:testStableSemconv
.\gradlew.bat :instrumentation:hibernate:hibernate-4.0:javaagent:testStableSemconv :instrumentation:hibernate:hibernate-6.0:javaagent:testStableSemconv -PtestLatestDeps=true
.\gradlew.bat :instrumentation:hibernate:hibernate-3.3:javaagent:spotlessCheck :instrumentation:hibernate:hibernate-4.0:javaagent:spotlessCheck :instrumentation:hibernate:hibernate-6.0:javaagent:spotlessCheck
trask and others added 2 commits June 8, 2026 12:28
The Hibernate 6 and 7 SessionTest query-state assertions always expected
stable-semconv lowercase HQL span names, but the failing CI jobs run legacy
database semconv mode where the instrumentation emits uppercase SELECT names.
The tests now derive the expected query span name from the active semconv mode.

Validation:
.\gradlew.bat :instrumentation:hibernate:hibernate-6.0:javaagent:hibernate6Test :instrumentation:hibernate:hibernate-6.0:javaagent:hibernate7Test --tests *SessionTest
.\gradlew.bat :instrumentation:hibernate:hibernate-6.0:javaagent:hibernate7Test --tests *SessionTest -PtestLatestDeps=true

Co-authored-by: Copilot <[email protected]>

// hibernate/jpa query language
Arguments.of("FROM TABLE WHERE FIELD=1234", "FROM TABLE WHERE FIELD=?", "SELECT TABLE"));
Arguments.of("from TABLE WHERE FIELD=1234", "from TABLE WHERE FIELD=?", "select 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.

changing FROM to from isn't relevant, but it does match what's seen from hibernate, so seems more realistic example data

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 30 out of 30 changed files in this pull request and generated 1 comment.

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 30 out of 30 changed files in this pull request and generated no new comments.

@trask
trask marked this pull request as ready for review June 9, 2026 02:51
@laurit
laurit merged commit ad5dcc3 into open-telemetry:main Jun 9, 2026
95 checks passed
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.

3 participants