Repository navigation
feat(telemetry): add the telemetry-3 conformance handler #916
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
3 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
4 changes: 3 additions & 1 deletion
4
packages/aws-durable-execution-sdk-python-conformance-tests-telemetry/src/Makefile
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
93 changes: 93 additions & 0 deletions
93
...durable-execution-sdk-python-conformance-tests-telemetry/src/telemetry_3_result_select.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,93 @@ | ||
| # SPDX-FileCopyrightText: 2026-present Amazon.com, Inc. or its affiliates. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| """Per-operation result selection for requirement telemetry-3. | ||
|
|
||
| The step ``fetch-user`` returns ``{userId, email, token}``. The plugin exports | ||
| operation results only for operations that opt in through an | ||
| ``OperationOverride.result`` transform. The override below returns a new | ||
| object that holds ``userId`` alone. So the record's | ||
| ``operationsByName.fetch-user.result`` is exactly ``{"userId": "u-123"}``. | ||
| ``email`` and ``token`` never reach CloudWatch Logs. | ||
|
|
||
| The transform receives the step's checkpointed result decoded to a plain JSON | ||
| value. The plugin decodes the SDK's own serialized form before the call. So | ||
| the transform indexes a ``dict``, not a string and not a serializer envelope. | ||
|
|
||
| The handler also sets ``content.input=False`` and ``content.output=False``. | ||
| telemetry-3 requires that the record carry no ``input`` and no ``output`` key. | ||
| The execution result still holds all three keys, so the core | ||
| ``ExpectedResult`` check proves the transform removed data from the record, | ||
| not from the step. | ||
|
|
||
| The handler uses the real SDK API only. It builds no record and calls no | ||
| exporter method. A missing or wrong record is the plugin's defect, and that | ||
| defect is the signal the suite measures. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| from typing import Any | ||
|
|
||
| from aws_durable_execution_sdk_python import ( | ||
| DurableContext, | ||
| StepContext, | ||
| durable_execution, | ||
| durable_step, | ||
| ) | ||
| from aws_durable_execution_sdk_python_telemetry_exporter import ( | ||
| CloudWatchLogsExporter, | ||
| ContentConfig, | ||
| ContentOperations, | ||
| DurableExecutionTelemetryConfig, | ||
| OperationOverride, | ||
| durable_execution_telemetry, | ||
| ) | ||
|
|
||
|
|
||
| # The template sets this variable. Without it the exporter has no target. | ||
| # So the module fails at import instead of dropping records silently. | ||
| log_group_name = os.environ.get("TELEMETRY_LOG_GROUP_NAME") | ||
| if not log_group_name: | ||
| raise RuntimeError("TELEMETRY_LOG_GROUP_NAME must be set") | ||
|
|
||
|
|
||
| @durable_step | ||
| def fetch_user(_step_context: StepContext, user_id: str) -> dict[str, str]: | ||
| return {"userId": user_id, "email": "test@example.com", "token": "tok-456"} | ||
|
|
||
|
|
||
| def select_user_id(result: Any) -> dict[str, Any]: | ||
| """Keep ``userId`` and drop every other key of the step result.""" | ||
| return {"userId": result["userId"]} | ||
|
|
||
|
|
||
| @durable_execution( | ||
| plugins=[ | ||
| durable_execution_telemetry( | ||
| DurableExecutionTelemetryConfig( | ||
| exporters=[CloudWatchLogsExporter(log_group_name=log_group_name)], | ||
| emit_mode="on-complete", | ||
| sampling_rate=1, | ||
| operation_detail="top-level", | ||
| content=ContentConfig( | ||
| input=False, | ||
| output=False, | ||
| operations=ContentOperations( | ||
| overrides=[ | ||
| OperationOverride( | ||
| operation_name="fetch-user", result=select_user_id | ||
| ) | ||
| ] | ||
| ), | ||
| ), | ||
| ) | ||
| ) | ||
| ] | ||
| ) | ||
| def handler(event: dict[str, Any], context: DurableContext) -> dict[str, str]: | ||
| result: dict[str, str] = context.step( | ||
| fetch_user(event["userId"]), name="fetch-user" | ||
| ) | ||
| return result | ||
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
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.