Skip to content

[Bug]: Execution OTel view retains the ended attempt spanId in MDC #815

Open

Description

@zhongkechen

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.

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:

  1. Configure the Execution OTel view with MDC enrichment enabled, a recording provider, and an MDC-capable SLF4J binding.
  2. 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.
  3. Complete the user function and inspect MDC.get("spanId") immediately after onUserFunctionEnd returns, before any enclosing logger scope or invocation cleanup runs. Compare it with Span.current().
  4. 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

  1. changed the title [-][Bug]: Execution OTel view retains an ended attempt\x27s spanId in MDC[/-] [+][Bug]: Execution OTel view retains the ended attempt spanId in MDC[/+] on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageIssue needs triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions