Skip to content

fix(otel): close spans child first at invocation end - #603

Draft
zhongkechen wants to merge 1 commit into
mainfrom
agent/fix-otel-span-close-order
Draft

fix(otel): close spans child first at invocation end#603
zhongkechen wants to merge 1 commit into
mainfrom
agent/fix-otel-span-close-order

Conversation

@zhongkechen

Copy link
Copy Markdown
Contributor

Summary

  • close still-open attempt spans before their operation spans
  • record operation start order and drain it in reverse during invocation shutdown
  • add a regression test covering attempt, child operation, and parent operation timestamp containment

Root cause

InvocationOtelPlugin.onInvocationEnd() previously ended open operation spans by iterating a ConcurrentHashMap. Its iteration order is unspecified, so a parent operation could be ended before a still-open child. This produced child end timestamps a few microseconds later than the parent and failed OTel conformance validation.

The plugin now keeps keyed span access in the concurrent map and records start order in a ConcurrentLinkedDeque. Invocation shutdown closes attempts first, then polls operation IDs from the deque tail so descendants close before ancestors. IDs for operations already completed are skipped when their span is absent from the map.

Impact

Interrupted invocations now export properly nested span timestamps while preserving concurrent keyed access for normal operation lifecycle events.

Validation

  • mvn -pl otel-plugin spotless:apply
  • mvn -pl otel-plugin test (123 tests passed)
  • focused nested-span regression test passed

@zhongkechen
zhongkechen deployed to ai-pr-review August 7, 2026 02:57 — with GitHub Actions Active
@zhongkechen
zhongkechen requested a deployment to ai-pr-review-runtime August 7, 2026 02:57 — with GitHub Actions Waiting
@zhongkechen
zhongkechen requested a deployment to ai-pr-review-runtime August 7, 2026 02:57 — with GitHub Actions Waiting
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.

1 participant