Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/telemetry-conformance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ jobs:
id-token: write
# The pinned SHA also selects the runner and telemetry-extension revision the shared
# workflow installs, so it must be reachable from a branch. It is the merge commit of
# aws-durable-execution-conformance-tests PR #179 on that repository's main branch. That
# commit exports PYTHON_SDK_REF and installs pip for the SAM makefile build.
uses: aws/aws-durable-execution-conformance-tests/.github/workflows/telemetry-suite.yml@ca2cd02e1fb0dce34c9d81e361c1556a7e3707ee
# aws-durable-execution-conformance-tests PR #183 on that repository's main branch.
uses: aws/aws-durable-execution-conformance-tests/.github/workflows/telemetry-suite.yml@cf13ef27d6e13a4423f7e0a178f9a3d4bb1099f0
with:
language: python
resource_prefix: python
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ This package holds the SDK-specific part: the handler and the SAM template that
| ----------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `telemetry` | `telemetry-1` | One successful single-step execution emits one `SUCCEEDED` record with `input`, `output`, ARN-derived identity fields, and `operationsByName`. |
| `telemetry` | `telemetry-2` | One failed execution emits one `FAILED` record with an `error` on the execution and on `operationsByName.charge`. |
| `telemetry` | `telemetry-3` | An `OperationOverride.result` transform exports exactly `{userId}` of a three-key step result; the record has no `input` or `output`. |

## Layout

```
src/
telemetry_1_success.py # single step "increment"; plugin + CloudWatchLogsExporter
telemetry_2_failure.py # step "charge" fails; handler raises "payment failed" from the step error
Makefile # one build-<LogicalId> target per function, used by `sam build`
requirements.txt # core SDK + telemetry exporter, pinned to ${PYTHON_SDK_REF}
template.yaml # declares TelemetryLogGroupName and creates the group
telemetry_1_success.py # single step "increment"; plugin + CloudWatchLogsExporter
telemetry_2_failure.py # step "charge" fails; handler raises "payment failed" from the step error
telemetry_3_result_select.py # step "fetch-user"; override transform keeps only userId in the record
Makefile # one build-<LogicalId> target per function, used by `sam build`
requirements.txt # core SDK + telemetry exporter, pinned to ${PYTHON_SDK_REF}
template.yaml # declares TelemetryLogGroupName and creates the group
tests/
test_telemetry_examples.py # guards template -> handler wiring; runs each handler locally
test_telemetry_examples.py # guards template -> handler wiring; runs each handler locally
```

The handler uses the real SDK API only.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
.PHONY: build-Telemetry1Success build-Telemetry2Failure build-handlers
.PHONY: build-Telemetry1Success build-Telemetry2Failure build-Telemetry3ResultSelect build-handlers

# Every function builds from the same src/ directory with the same recipe.
# SAM calls one target per logical ID, so each target points at the shared one.
build-Telemetry1Success: build-handlers

build-Telemetry2Failure: build-handlers

build-Telemetry3ResultSelect: build-handlers

build-handlers:
python3 -m pip install --upgrade \
--target "$(ARTIFACTS_DIR)" \
Expand Down
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(
Comment thread
hln33 marked this conversation as resolved.
Resolved
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,17 @@ Resources:
Handler: telemetry_2_failure.handler
FunctionName: !Sub "${AWS::StackName}-telemetry-2"
Role: !Ref LambdaExecutionRoleArn

Telemetry3ResultSelect:
Type: AWS::Serverless::Function
DependsOn: TelemetryLogGroup
Metadata:
BuildMethod: makefile
TestingMetadata:
TestDescription:
- telemetry-3
Properties:
CodeUri: src/
Handler: telemetry_3_result_select.handler
FunctionName: !Sub "${AWS::StackName}-telemetry-3"
Role: !Ref LambdaExecutionRoleArn
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
``TestingMetadata.TestDescription``. SAM builds each function through
``src/Makefile``. A renamed handler or a missing build target fails only when a
cloud deployment runs. So these tests pin that wiring locally.
The module also runs both handlers through ``DurableFunctionTestRunner`` and checks
The module also runs each handler through ``DurableFunctionTestRunner`` and checks
the exported record.
"""

Expand All @@ -34,13 +34,14 @@

SDK_REPOSITORY_URL = "git+https://github.com/aws/aws-durable-execution-sdk-python.git"
EXPECTED_MODULES: frozenset[str] = frozenset(
{"telemetry_1_success", "telemetry_2_failure"}
{"telemetry_1_success", "telemetry_2_failure", "telemetry_3_result_select"}
)
# Logical ID -> requirement ID. The function name suffix must equal the
# requirement ID, so the runner can match the deployed function to its test.
EXPECTED_FUNCTIONS: dict[str, str] = {
"Telemetry1Success": "telemetry-1",
"Telemetry2Failure": "telemetry-2",
"Telemetry3ResultSelect": "telemetry-3",
}


Expand Down Expand Up @@ -318,3 +319,34 @@ def test_telemetry_2_handler_fails_with_payment_failed_after_one_attempt(
assert charge["failedCount"] == 1
assert charge["maxAttempt"] == 1
assert charge["error"]["message"] == "card declined"


def test_telemetry_3_handler_exports_only_the_selected_result_key(
logs_client: FakeLogsClient,
) -> None:
"""telemetry-3 pins the three-key execution result and the one-key record result."""
module = load_handler_module("telemetry_3_result_select")

with DurableFunctionTestRunner(
handler=module.handler, execution_timeout=15
) as runner:
result = runner.run(input='{"userId": "u-123"}')

assert result.status is InvocationStatus.SUCCEEDED
assert result.result is not None
assert json.loads(result.result) == {
"userId": "u-123",
"email": "test@example.com",
"token": "tok-456",
}
assert len(logs_client.put_log_events_calls) == 1
assert logs_client.put_log_events_calls[0]["logGroupName"] == LOG_GROUP_NAME
record = logs_client.records()[0]
assert record["status"] == "SUCCEEDED"
assert "input" not in record
assert "output" not in record
fetch_user = record["operationsByName"]["fetch-user"]
assert fetch_user["type"] == "STEP"
assert fetch_user["status"] == "SUCCEEDED"
assert fetch_user["count"] == 1
assert fetch_user["result"] == {"userId": "u-123"}
Loading