Repository navigation
fix(otel): correct exported status mappings #752
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
172 changes: 172 additions & 0 deletions
172
packages/aws-durable-execution-sdk-python-otel/tests/test_status_mapping.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,172 @@ | ||
| """Shared status regressions through both public plugin lifecycles.""" | ||
|
|
||
| from collections.abc import Iterator | ||
| from datetime import UTC, datetime, timedelta | ||
| from typing import Any | ||
|
|
||
| import pytest | ||
| from aws_durable_execution_sdk_python.lambda_service import ( | ||
| ErrorObject, | ||
| OperationStatus, | ||
| OperationSubType, | ||
| ) | ||
| from aws_durable_execution_sdk_python.plugin import ( | ||
| InvocationEndInfo, | ||
| InvocationStartInfo, | ||
| InvocationStatus, | ||
| OperationEndInfo, | ||
| OperationStartInfo, | ||
| OperationType, | ||
| ) | ||
| from opentelemetry import context | ||
| 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 ( | ||
| ExecutionOtelPlugin, | ||
| InvocationOtelPlugin, | ||
| OtelPluginConfig, | ||
| ) | ||
|
|
||
|
|
||
| START = datetime(2026, 10, 1, tzinfo=UTC) | ||
| END = START + timedelta(seconds=1) | ||
| ARN = ( | ||
| "arn:aws:lambda:us-west-2:123456789012:function:status:1/durable-execution/test/id" | ||
| ) | ||
|
|
||
|
|
||
| InstrumentedView = tuple[ | ||
| ExecutionOtelPlugin | InvocationOtelPlugin, InMemorySpanExporter | ||
| ] | ||
|
|
||
|
|
||
| @pytest.fixture(params=[ExecutionOtelPlugin, InvocationOtelPlugin]) | ||
| def instrumented_view(request: pytest.FixtureRequest) -> Iterator[InstrumentedView]: | ||
| exporter = InMemorySpanExporter() | ||
| provider = TracerProvider() | ||
| provider.add_span_processor(SimpleSpanProcessor(exporter)) | ||
| plugin = request.param( | ||
| OtelPluginConfig( | ||
| tracer_provider=provider, | ||
| context_extractor=lambda _: None, | ||
| enrich_logger=False, | ||
| ) | ||
| ) | ||
| original = context.get_current() | ||
| yield plugin, exporter | ||
| assert context.get_current() == original | ||
| provider.shutdown() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "status", | ||
| [ | ||
| OperationStatus.SUCCEEDED, | ||
| OperationStatus.FAILED, | ||
| OperationStatus.CANCELLED, | ||
| OperationStatus.TIMED_OUT, | ||
| OperationStatus.STOPPED, | ||
| ], | ||
| ) | ||
| @pytest.mark.parametrize("with_error", [False, True]) | ||
| @pytest.mark.parametrize("started_here", [False, True]) | ||
| def test_operation_status_and_exception( | ||
| instrumented_view: InstrumentedView, | ||
| status: OperationStatus, | ||
| with_error: bool, | ||
| started_here: bool, | ||
| ) -> None: | ||
| """A delivered terminal hook must not label an unsuccessful operation OK.""" | ||
| plugin, exporter = instrumented_view | ||
| invocation: dict[str, Any] = dict( | ||
| request_id="first", | ||
| execution_arn=ARN, | ||
| execution_start_time=START, | ||
| is_first_invocation=True, | ||
| ) | ||
| plugin.on_invocation_start(InvocationStartInfo(**invocation)) | ||
| operation: dict[str, Any] = dict( | ||
| operation_id="wait", | ||
| name="wait", | ||
| parent_id=None, | ||
| operation_type=OperationType.WAIT, | ||
| sub_type=OperationSubType.WAIT, | ||
| start_time=START, | ||
| is_replayed=False, | ||
| ) | ||
| if started_here: | ||
| plugin.on_operation_start( | ||
| OperationStartInfo(**operation, status=OperationStatus.STARTED) | ||
| ) | ||
| error = ( | ||
| ErrorObject( | ||
| message="deadline exceeded", | ||
| type="TimeoutError", | ||
| data=None, | ||
| stack_trace=None, | ||
| ) | ||
| if with_error | ||
| else None | ||
| ) | ||
| plugin.on_operation_end( | ||
| OperationEndInfo(**operation, end_time=END, status=status, error=error) | ||
| ) | ||
| plugin.on_invocation_end( | ||
| InvocationEndInfo(**invocation, status=InvocationStatus.SUCCEEDED) | ||
| ) | ||
| span = next(s for s in exporter.get_finished_spans() if s.name == "wait") | ||
| assert span.attributes is not None | ||
| assert span.attributes["durable.operation.status"] == status.value | ||
| expected = ( | ||
| StatusCode.ERROR | ||
| if with_error | ||
| else ( | ||
| StatusCode.OK if status is OperationStatus.SUCCEEDED else StatusCode.UNSET | ||
| ) | ||
| ) | ||
| assert span.status.status_code is expected | ||
| if with_error: | ||
| assert span.status.description == "deadline exceeded" | ||
| assert len(span.events) == 1 | ||
| assert span.events[0].name == "exception" | ||
| assert span.events[0].attributes is not None | ||
| assert span.events[0].attributes["exception.message"] == "deadline exceeded" | ||
| else: | ||
| assert not span.events | ||
|
|
||
|
|
||
| def test_retry_then_resume_exports_retrying( | ||
| instrumented_view: InstrumentedView, | ||
| ) -> None: | ||
| """Telemetry normalizes RETRY without changing the core enum or next invocation.""" | ||
| plugin, exporter = instrumented_view | ||
| original = context.get_current() | ||
| for index, status in enumerate( | ||
| [InvocationStatus.RETRY, InvocationStatus.SUCCEEDED] | ||
| ): | ||
| invocation: dict[str, Any] = dict( | ||
| request_id=f"request-{index}", | ||
| execution_arn=ARN, | ||
| execution_start_time=START, | ||
| is_first_invocation=index == 0, | ||
| ) | ||
| plugin.on_invocation_start(InvocationStartInfo(**invocation)) | ||
| plugin.on_invocation_end(InvocationEndInfo(**invocation, status=status)) | ||
| assert context.get_current() == original | ||
| spans = [s for s in exporter.get_finished_spans() if s.name == "Invocation"] | ||
| assert [ | ||
| s.attributes["durable.invocation.status"] | ||
| for s in spans | ||
| if s.attributes is not None | ||
| ] == [ | ||
| "RETRYING", | ||
| "SUCCEEDED", | ||
| ] | ||
| assert [s.status.status_code for s in spans] == [StatusCode.UNSET, StatusCode.OK] | ||
| assert InvocationStatus.RETRY.value == "RETRY" | ||
| assert spans[0].context is not None | ||
| assert spans[1].context is not None | ||
| assert spans[0].context.trace_id == spans[1].context.trace_id |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why can't we instead remove
InvocationStatus.RETRYand addInvocationStatus.RETRYINGinstead of doing these checks throughout the plugin code?This seems better to me as then we avoid having to do these tiny conditional checks here and there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InvocationStatusis part of the core instrumentation-plugin API, andRETRYis already a public member used by existing plugins. Removing it would break those consumers and require the OTel package to depend on a newer core. The service outcome is alsoRETRY; the core currently converts that value into the plugin enum without changing it.This fix only normalizes the exported
durable.invocation.statusattribute to the cross-SDK valueRETRYING, while preserving the core API and retry behavior. The two checks are the export sites for the two OTel views. We can remove that duplication with a shared telemetry-formatting helper; renaming the public core enum would instead need an API compatibility/migration decision and is unnecessary for this telemetry correction.