Repository navigation
[Bug]: Execution OTel view retains the ended attempt spanId in MDC #815
Description
Expected Behavior
After ExecutionOtelPlugin.onUserFunctionEnd closes a completed attempt's OTel scope, MDC should no longer identify that ended attempt as the current span. Cleanup should happen before the hook returns, while preserving valid surrounding trace context.
Actual Behavior
Public main at 1c4922293d01bbd3a18082f0d9ea819a361a2227 injects the attempt span into MDC at user-function start, but the Execution-view End hook closes the OTel scope without removing its spanId from MDC. The Invocation-view End hook explicitly removes that key.
- Execution-view start hook: makes the attempt span current and injects MDC.
- Execution-view End hook: closes
attemptScopes, handles early returns, and ends the attempt span without removing the MDC span ID. - Invocation-view End hook: calls
MDC.remove(MdcSpanEnricher.MDC_SPAN_ID)when MDC enrichment is enabled, before early returns. - Execution-view invocation cleanup: clears MDC at invocation end.
This creates a potential post-attempt correlation window in which a log can retain the ended attempt's span ID until later cleanup. The scope of this report is the missing cleanup at the End-hook boundary, not a claim of permanent or cross-invocation leakage.
Steps to Reproduce
This report is based on public source inspection. The following runtime validation recipe has not been executed for this report:
- Configure the Execution OTel view with MDC enrichment enabled, a recording provider, and an MDC-capable SLF4J binding.
- In a focused lifecycle test, begin an invocation, an operation, and its user-function attempt on the owning thread. Record the attempt's span ID from MDC.
- Complete the user function and inspect
MDC.get("spanId")immediately afteronUserFunctionEndreturns, before any enclosing logger scope or invocation cleanup runs. Compare it withSpan.current(). - Repeat with the Invocation view configured separately as a control.
Expected: MDC no longer reports the ended attempt's span ID. The source shows that only the Invocation-view End hook explicitly removes it.
SDK Version
Java SDK otel-plugin, public main at 1c4922293d01bbd3a18082f0d9ea819a361a2227.
Java Version
Not applicable to source inspection; no runtime reproduction was run for this report.
Is this a regression?
Unknown; no last working version has been established.
Acceptance Criteria
- Remove or correctly restore the completed attempt's MDC span context before the Execution-view End hook returns; retain appropriate trace-level correlation.
- Add a focused assertion immediately after the hook, before enclosing logger-scope cleanup can mask the defect. Cover normal completion, failure, and relevant early-return paths with MDC enabled.
- Verify nested context restoration and suspension/resume, with the Invocation view as a control and MDC-disabled configurations unaffected.
Activity
[-][Bug]: Execution OTel view retains an ended attempt\x27s spanId in MDC[/-][+][Bug]: Execution OTel view retains the ended attempt spanId in MDC[/+]