Skip to content

fix(otel): name the Workflow and Step operation spans in Execution view log records - #1000

Open
MaxonT wants to merge 1 commit into
aws:mainfrom
MaxonT:contrib/893-auto
Open

MaxonT wants to merge 1 commit into
aws:mainfrom
MaxonT:contrib/893-auto

Conversation

@MaxonT

@MaxonT MaxonT commented Nov 27, 2026

Copy link
Copy Markdown

Hi, I read through the issue and wrote a fix; happy to adjust it.

Fixes #893

Thanks for writing the acceptance criteria as a table of log locations and expected spanId values; it made it easy to check each case one by one.

Description of changes

With ExecutionOtelPlugin and log enrichment on, a top-level handler record carried the Invocation span and a step-body record carried the attempt span. This changes the stamped spanId to the logical span: the Workflow span at the top level, and the Step operation span inside a step body (the same ID for every retry attempt, and a nested step uses its own). Child-context bodies already resolved to the child operation span and are unchanged. InvocationOtelPlugin is untouched.

The attempt span is still the current OTel span, so span parentage, attach/detach scopes and exported spans are not changed. Only ExecutionOtelPlugin.get_current_span_context() changes: when the current span is the enclosing Workflow span it returns the Workflow context, and when it is an attempt span it returns that step's deterministic operation span context, kept in a small map filled in on_user_function_start and cleared in on_user_function_end.

Design

  • Design note (rule 3): not needed, no new option or public API member; the log field values for an existing option change as the issue requests.
  • Simpler options considered (rule 2): reading the attempt span's parent would avoid the map, but the parent is the operation placeholder only when one was registered, so I used the operation's deterministic span ID instead. The now-unneeded Invocation fallback for the top level stays only for the case where no Workflow span exists.
  • Root cause (rule 5): get_current_span_context() deliberately excluded the Workflow span and returned the attempt span as is.
  • Net change: about 40 source lines added, 17 removed; no public API change.

Assumptions

  • The step operation span ID stamped on a record is operation_id_to_span_id(execution_arn, operation_id), the same ID the exported Step operation span uses. The e2e view-registration test checks this against the exported logged-step span through the real handler path.

Decisions not covered by the issue or the design note

  • The README and the OtelContextLogFilter docstring now describe both views, because the mapping now differs between them.

Tests

Edited expectations (rule 5): test_top_level_log_names_invocation_span_not_the_attached_workflow_span is now test_top_level_log_names_the_workflow_span, and test_step_attempt_log_names_the_attempt_span is now test_step_log_names_the_step_operation_span_across_attempts, both because the issue changes the mapping they asserted. In tests/e2e/test_concurrent_log_correlation_int.py the expected span is now read from the Workflow span for the Execution view (Invocation view unchanged). In tests/e2e/test_view_registration.py the recovery check expects the logged-step operation span for the Execution view and the attempt span for the Invocation view.

Added: test_step_log_names_the_step_operation_span_across_attempts (two attempts, same ID, Workflow restored after each) and test_nested_step_log_names_its_own_operation_span_and_restores_child.

Before the fix, 7 tests fail (the 3 unit tests above, the Workflow case of the concurrent-invocation e2e test, and 3 view-registration e2e cases). With the fix, the whole otel package suite passes: 1022 passed (unit and e2e), and ruff check and ruff format --check are clean. I ran this on macOS with Python 3.14 in a throwaway venv (pip install of the core and otel packages, aws-durable-execution-sdk-python-testing, opentelemetry SDK).

Not run: the cloud Lambda reproduction from the issue, hatch environments, mypy, the core and examples package tests. I did not add a dedicated test for a top-level log after a durable wait and resume, or for a compatible Lambda span already being active; the Workflow span ID is derived from the execution ARN, so it is the same across invocations, but that is not asserted end to end.

@MaxonT
MaxonT deployed to ai-pr-review-runtime November 27, 2026 23:33 — with GitHub Actions Active

This branch was successfully deployed

1 active deployment
ai-pr-review-runtime — 3934a171 Deployed Nov 27, 2026 by MaxonT via notify / Generate notification summary #514
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Align Execution view log correlation with Workflow and operation spans

1 participant