HhH666-ux opened a new pull request, #40097:
URL: https://github.com/apache/shardingsphere/pull/40097

   Fixes #39765.
   
   ## Problem
   
   Two overlapping `execute` invocations on the same `JDBCExecutorCallback` 
export only one completed span: the second invocation's span is ended by the 
first invocation's completion hook, the first span is never ended, and the 
second invocation's exception outcome is lost.
   
   ## Root cause
   
   `OpenTelemetryJDBCExecutorCallbackAdvice` stored the started span in the 
single attachment slot of the target `JDBCExecutorCallback` 
(`target.setAttachment(...)`). That target instance is shared across concurrent 
and nested executions, so an overlapping invocation overwrote the slot before 
the first invocation reached its completion hook.
   
   ## Fix
   
   Track active spans in a per-thread stack (`ThreadLocal<Deque<Span>>`):
   
   - `recordExecuteInfo` pushes the started span;
   - `afterMethod` / `onThrowing` pop the matching span and finish it.
   
   This is correct for nested invocations on one thread (LIFO pairing) and for 
overlapping invocations on several threads sharing one callback instance 
(per-thread stacks).
   
   The attachment slot is no longer used by this advice; no other code reads it 
for this target type.
   
   ## Tests
   
   Added 
`OpenTelemetryJDBCExecutorCallbackAdviceTest#assertConcurrentInvocations`, 
following the deterministic two-thread scenario from the issue: invocation A 
starts, invocation B starts, A completes successfully, B completes with an 
exception. Asserts two exported spans, each preserving its own SQL attribute 
and status (`OK` for A, `ERROR` for B) and parent span id. This test fails on 
unchanged master with `Expected: is <2> but: was <1>`, matching the 
reproduction in the issue.
   


-- 
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