fix(otel): end spans on non-terminal invocations - #850
Draft
ayushiahjolia wants to merge 1 commit into
Draft
Conversation
Both OTel plugins created a recording Workflow span at invocation start and dropped it un-ended on non-terminal (PENDING/RETRYING) invocations. An un-ended span is never delivered to span processors, so it leaked across warm Lambda invocations and was never exported. In-flight attempt spans (and, in ExecutionOtelPlugin, suspended operation spans) were also left un-ended. Carry the Workflow span identity as a non-recording span context while the execution is in flight, and create the single recording Workflow span once, at the terminal invocation, backdated to the execution start. End in-flight attempt and suspended operation spans at invocation cleanup; a later invocation that resumes an operation exports it under its own ID rather than reusing the deterministic one, so no two exported spans share a (traceId, spanId). Resolve the non-recording context's sampling decision from the provider's own sampler (resolveWorkflowRoot) so operations are sampled consistently with the eventual root and enrichLogContext() reports the true sampling flag. Also fixes a latent bug in ExecutionOtelPlugin where onOperationStart firing twice for one operation (internal retry) overwrote the span map and orphaned the first span. Fixes #831 sim: #831
ayushiahjolia
requested a deployment
to
ai-pr-review
August 21, 2026 18:02 — with
GitHub Actions
Waiting
This was referenced Aug 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
#831
Description of changes:
Both OTel plugins created a recording Workflow span at invocation start and dropped it un-ended on non-terminal (PENDING/RETRYING) invocations. An un-ended span is never delivered to span processors, so it leaked across warm Lambda invocations and was never exported. In-flight attempt spans (and, in ExecutionOtelPlugin, suspended operation spans) were also left un-ended.
Carry the Workflow span identity as a non-recording span context while the execution is in flight, and create the single recording Workflow span once, at the terminal invocation, backdated to the execution start. End in-flight attempt and suspended operation spans at invocation cleanup; a later invocation that resumes an operation exports it under its own ID rather than reusing the deterministic one, so no two exported spans share a (traceId, spanId). Resolve the non-recording context's sampling decision from the provider's own sampler (resolveWorkflowRoot) so operations are sampled consistently with the eventual root and enrichLogContext() reports the true sampling flag.
Also fixes a latent bug in ExecutionOtelPlugin where onOperationStart firing twice for one operation (internal retry) overwrote the span map and orphaned the first span.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.