oscerd opened a new pull request, #26885:
URL: https://github.com/apache/camel/pull/26885

   # CAMEL-25020: observability must not report the `CamelSqlQuery` header when 
`useMessageBodyForSql` wins
   
   Follow-up to CAMEL-24718 (#26689).
   
   ## The gap
   
   CAMEL-24718 made the three observability call sites consult the endpoint's 
`allowQueryFromHeader` option before reporting the `CamelSqlQuery` header, so 
telemetry stops attributing a statement the endpoint never executed.
   
   That gate is incomplete. `SqlProducer.process()` short-circuits on 
`useMessageBodyForSql` **before** it ever looks at `allowQueryFromHeader`:
   
   ```java
   if (useMessageBodyForSql) {
       sql = exchange.getIn().getBody(String.class);   // header never consulted
   } else {
       String queryHeader = getEndpoint().isAllowQueryFromHeader()
               ? exchange.getIn().getHeader(SqlConstants.SQL_QUERY, 
String.class) : null;
       ...
   }
   ```
   
   So an endpoint configured with **both** `allowQueryFromHeader=true` and 
`useMessageBodyForSql=true` executes the message body, while the shared 
`isQueryHeaderHonoured()` helper still returned `true` — leaving the 
`db.statement` span tag and the `sql-trace` dev console reporting the *header*. 
That is the same defect CAMEL-24718 fixed, in a narrower corner explicitly left 
out of scope at the time.
   
   ## The change
   
   Mirror the producer's precedence in all three call sites — 
`useMessageBodyForSql=true` short-circuits the helper to `false`:
   
   - `components/camel-telemetry/.../decorators/SqlQueryHeaderHelper.java`
   - `components/camel-tracing/.../decorators/SqlQueryHeaderHelper.java` 
(deprecated module, kept in sync)
   - `core/camel-console/.../SqlTraceDevConsole.java`
   
   The options are still read through the endpoint's generated 
`PropertyConfigurer`, so none of these modules gains a dependency on camel-sql.
   
   ## Tests
   
   One new case per call site, extending the existing CAMEL-24718 tests (JUnit 
style, matching the surrounding modules):
   
   | Test class | Tests |
   |---|---|
   | `camel-telemetry` `SqlSpanDecoratorTest` | 4 → 5 |
   | `camel-tracing` `SqlSpanDecoratorTest` | 4 → 5 |
   | `camel-console` `SqlTraceDevConsoleQueryHeaderTest` | 2 → 3 |
   
   The new cases were verified to discriminate: with the guard removed, 
`testHeaderQueryIsIgnoredWhenUseMessageBodyForSqlWins` fails with `expected: 
<select * from projects> but was: <select * from secrets>` — i.e. the console 
reports the sender-controlled header — while the pre-existing cases still pass.
   
   ## Docs
   
   The 4.23.0 upgrade guide entry for the CAMEL-24718 gate is extended to state 
the precedence and to mention the `sql-trace` console. 4.23.0 is unreleased, so 
this refines the existing note rather than adding a new one.
   
   ## Out of scope
   
   When `useMessageBodyForSql=true` the console still falls back to the query 
parsed out of the endpoint URI, which is also not the statement that ran. That 
inaccuracy predates CAMEL-24718 and is noted on the Jira issue rather than 
addressed here.
   
   ## Backport
   
   Not needed. `allowQueryFromHeader` and the CAMEL-24718 gate both ship first 
in 4.23.0, which is unreleased, so no maintenance branch carries the incomplete 
gate.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to