Skip to content

[otel] End all recording spans on non-terminal invocations #624

Description

@zhongkechen

Summary

The Java OTel plugins intentionally drop references to recording spans without ending them when a durable execution returns a non-terminal status.

Affected behavior:

  • ExecutionOtelPlugin clears open operation and attempt spans during invocation cleanup without ending them.
  • Both ExecutionOtelPlugin and InvocationOtelPlugin drop the execution-scoped Workflow span on PENDING or RETRYING.

OpenTelemetry spans are only complete and eligible for processing/export after Span.end() is called.

Evidence

  • otel-plugin/src/main/java/software/amazon/lambda/durable/otel/ExecutionOtelPlugin.java
    • onInvocationEnd clears operationSpans and attemptSpans without ending the spans.
    • The non-terminal workflow path clears workflowSpan without ending it.
  • otel-plugin/src/main/java/software/amazon/lambda/durable/otel/InvocationOtelPlugin.java
    • The non-terminal workflow path clears workflowSpan without ending it.
  • ExecutionOtelPluginTest.nonTerminalInvocation_doesNotExportWorkflowSpan codifies the unended workflow behavior.
  • ExecutionOtelPluginTest.operationNotCompleted_notEndedAtInvocationEnd explicitly requires an open operation span not to be ended.
  • InvocationOtelPluginTest.workflowSpan_notExportedOnNonTerminal codifies the same workflow behavior.

OpenTelemetry requirement

The Trace API defines End as the operation that completes a span and makes it ready for delivery through the configured span processor:

https://opentelemetry.io/docs/specs/otel/trace/api/#end

Impact

  • Span processors can observe span starts without corresponding ends.
  • Processor state or references may remain live across warm Lambda invocations.
  • Re-created deterministic spans can produce repeated starts for the same logical span ID.
  • The behavior prevents a strict OpenTelemetry compliance claim.

Acceptance criteria

  • Every recording span created by either Java OTel plugin is ended exactly once.
  • Non-terminal workflow and suspended-operation behavior does not rely on abandoning a recording span.
  • Cross-invocation workflow and operation correlation remains intact.
  • Tests retain span references and assert that they are no longer recording after invocation cleanup.
  • Tests cover PENDING, RETRYING, terminal success, and terminal failure for both plugin variants.

Related cross-SDK issue: aws/aws-durable-execution-sdk-python#642

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions