Repository navigation
fix: correct terminal telemetry status and timing #865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zhongkechen
wants to merge
7
commits into
main
Choose a base branch
from
codex/fix-853-otel-terminal-status
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
26536b6
test: cover terminal OTel status and event times
zhongkechen 82fc876
fix: align terminal OTel status and event times
zhongkechen 20cd59b
Merge branch 'main' into codex/fix-853-otel-terminal-status
zhongkechen 3d77e65
Merge branch 'main' into codex/fix-853-otel-terminal-status
zhongkechen 352a137
Merge branch 'main' into codex/fix-853-otel-terminal-status
zhongkechen 28338a6
refactor: simplify terminal span completion
zhongkechen ef406b5
test: verify durable end timestamp selection
zhongkechen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
134 changes: 134 additions & 0 deletions
134
packages/aws-durable-execution-sdk-python-otel/tests/e2e/test_terminal_failure_bounds_int.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| """Caught operation failures preserve telemetry through real suspension/replay.""" | ||
|
|
||
| import json | ||
| from typing import Any | ||
|
|
||
| import pytest | ||
| from aws_durable_execution_sdk_python import DurableContext, durable_execution | ||
| from aws_durable_execution_sdk_python.config import ChildConfig, Duration | ||
| from aws_durable_execution_sdk_python.exceptions import ChildContextError, InvokeError | ||
| from aws_durable_execution_sdk_python.plugin import ( | ||
| DurableInstrumentationPlugin, | ||
| InvocationStartInfo, | ||
| OperationEndInfo, | ||
| ) | ||
| from aws_durable_execution_sdk_python_testing.runner import DurableFunctionTestRunner | ||
| from opentelemetry.sdk.trace import TracerProvider | ||
| from opentelemetry.sdk.trace.export import SimpleSpanProcessor | ||
| from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter | ||
| from opentelemetry.trace import StatusCode | ||
|
|
||
| from aws_durable_execution_sdk_python_otel import ( | ||
| ExecutionOtelPluginFactory, | ||
| InvocationOtelPluginFactory, | ||
| OtelPluginConfig, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "view", [ExecutionOtelPluginFactory, InvocationOtelPluginFactory] | ||
| ) | ||
| @pytest.mark.parametrize("failure_kind", ["child", "virtual", "invoke"]) | ||
| @pytest.mark.parametrize("resume", [False, True]) | ||
| def test_caught_failure_keeps_events_bounded_and_workflow_successful( | ||
| view: type[ExecutionOtelPluginFactory] | type[InvocationOtelPluginFactory], | ||
| failure_kind: str, | ||
| resume: bool, | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| ) -> None: | ||
| monkeypatch.delenv("DURABLE_EXECUTION_PLUGINS", raising=False) | ||
| provider = TracerProvider() | ||
| exporter = InMemorySpanExporter() | ||
| provider.add_span_processor(SimpleSpanProcessor(exporter)) | ||
| factory = view( | ||
| OtelPluginConfig( | ||
| tracer_provider=provider, | ||
| enrich_logger=False, | ||
| context_extractor=lambda _: None, | ||
| ) | ||
| ) | ||
| saved_calls: list[str] = [] | ||
| failure_calls: list[str] = [] | ||
| observations: list[OperationEndInfo] = [] | ||
|
|
||
| class Observe(DurableInstrumentationPlugin): | ||
| def on_operation_end(self, info: OperationEndInfo) -> None: | ||
| if info.name == "caught-failure": | ||
| observations.append(info) | ||
|
|
||
| class ObserveFactory: | ||
| def create_plugin(self, _info: InvocationStartInfo) -> Observe: | ||
| return Observe() | ||
|
|
||
| def saved_step(_context: Any) -> str: | ||
| saved_calls.append("saved") | ||
| return "saved" | ||
|
|
||
| def failing_child(_context: DurableContext) -> str: | ||
| failure_calls.append("failed") | ||
| raise ValueError("actual child failure") | ||
|
|
||
| def failing_function(_event: Any, _context: Any) -> None: | ||
| failure_calls.append("failed") | ||
| raise ValueError("actual invoke failure") | ||
|
|
||
| def body(_event: Any, context: DurableContext) -> str: | ||
| saved = context.step(saved_step, name="saved-step") | ||
| try: | ||
| if failure_kind == "invoke": | ||
| context.invoke("failing-target", {}, name="caught-failure") | ||
| else: | ||
| context.run_in_child_context( | ||
| failing_child, | ||
| name="caught-failure", | ||
| config=ChildConfig(is_virtual=failure_kind == "virtual"), | ||
| ) | ||
| except (ChildContextError, InvokeError): | ||
| if resume: | ||
| context.wait(Duration.from_seconds(1), name="replay-wait") | ||
| return saved | ||
| raise AssertionError("Expected the original operation failure") | ||
|
|
||
| try: | ||
| with DurableFunctionTestRunner( | ||
| handler=durable_execution(body, plugins=[factory, ObserveFactory()]), | ||
| poll_interval=0.01, | ||
| ) as runner: | ||
| runner.register_function("failing-target", failing_function) | ||
| result = runner.run(input="{}", execution_timeout=15) | ||
| assert result.status.value == "SUCCEEDED" | ||
| assert result.result is not None and json.loads(result.result) == "saved" | ||
| assert saved_calls == ["saved"] | ||
| # Virtual contexts intentionally execute on replay; checkpointed child | ||
| # failures and invoke outcomes must return their stored failure instead. | ||
| assert len(failure_calls) == (2 if resume and failure_kind == "virtual" else 1) | ||
| assert observations | ||
| if failure_kind == "virtual": | ||
| assert all(info.start_time is None for info in observations) | ||
| spans = exporter.get_finished_spans() | ||
| failed = [ | ||
| span | ||
| for span in spans | ||
| if span.name == "caught-failure" | ||
| and span.attributes is not None | ||
| and span.attributes.get("durable.operation.status") == "FAILED" | ||
| ] | ||
| assert failed | ||
| for span in failed: | ||
| assert span.status.status_code is StatusCode.ERROR | ||
| (event,) = span.events | ||
| assert span.start_time is not None and span.end_time is not None | ||
| assert span.start_time <= event.timestamp == span.end_time | ||
| assert event.attributes is not None | ||
| assert event.attributes["exception.message"] in { | ||
| "actual child failure", | ||
| "actual invoke failure", | ||
| } | ||
| invocations = [span for span in spans if span.name == "Invocation"] | ||
| # An invoke can add its own suspension before the explicit replay wait. | ||
| assert len(invocations) >= (2 if resume else 1) | ||
| assert all(span.status.status_code is StatusCode.OK for span in invocations) | ||
| (workflow,) = [span for span in spans if span.name == "Workflow"] | ||
| assert workflow.status.status_code is StatusCode.OK | ||
| finally: | ||
| provider.shutdown() |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.