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
4 changes: 2 additions & 2 deletions .github/workflows/telemetry-conformance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +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 #183 on that repository's main branch.
uses: aws/aws-durable-execution-conformance-tests/.github/workflows/telemetry-suite.yml@cf13ef27d6e13a4423f7e0a178f9a3d4bb1099f0
# aws-durable-execution-conformance-tests PR #185 on that repository's main branch.
uses: aws/aws-durable-execution-conformance-tests/.github/workflows/telemetry-suite.yml@b380cbf19bbc4f08a2d7c593d4bf24f585946415
with:
language: python
resource_prefix: python
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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`. |
| `telemetry` | `telemetry-4` | With `operation_detail="full-tree"`, the record holds the map, its two iteration contexts, and the two steps by name. |

## Layout

Expand All @@ -29,6 +30,7 @@ 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
telemetry_3_result_select.py # step "fetch-user"; override transform keeps only userId in the record
telemetry_4_full_tree_map.py # map "process-items" with step "greet-<item>"; full-tree detail records all five operations
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build-Telemetry1Success build-Telemetry2Failure build-Telemetry3ResultSelect build-handlers
.PHONY: build-Telemetry1Success build-Telemetry2Failure build-Telemetry3ResultSelect build-Telemetry4FullTreeMap 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.
Expand All @@ -8,6 +8,8 @@ build-Telemetry2Failure: build-handlers

build-Telemetry3ResultSelect: build-handlers

build-Telemetry4FullTreeMap: 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,79 @@
# SPDX-FileCopyrightText: 2026-present Amazon.com, Inc. or its affiliates.
#
# SPDX-License-Identifier: Apache-2.0
"""Full-tree operation detail for requirement telemetry-4.

The handler maps over the event ``[1, 2]`` with ``maxConcurrency=1``. The item
namer names each iteration ``item-<item>``. Each iteration runs one step named
``greet-<item>``. The plugin runs with ``operation_detail="full-tree"``. So the
record's ``operationsByName`` holds the map context ``process-items``, the two
iteration contexts ``item-1`` and ``item-2``, and the two steps ``greet-1`` and
``greet-2``. Under ``top-level`` detail the record would hold only
``process-items``.

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.config import MapConfig
from aws_durable_execution_sdk_python_telemetry_exporter import (
CloudWatchLogsExporter,
ContentConfig,
DurableExecutionTelemetryConfig,
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 greet(_step_context: StepContext, item: int) -> str:
return f"Hello, {item}!"


def map_fn(ctx: DurableContext, item: int, _index: int, _items: Any) -> str:
result: str = ctx.step(greet(item), name=f"greet-{item}")
return result


@durable_execution(
plugins=[
durable_execution_telemetry(
DurableExecutionTelemetryConfig(
exporters=[CloudWatchLogsExporter(log_group_name=log_group_name)],
emit_mode="on-complete",
sampling_rate=1,
operation_detail="full-tree",
content=ContentConfig(input=True, output=True),
)
)
]
)
def handler(event: list[int], context: DurableContext) -> list[str]:
Comment thread
hln33 marked this conversation as resolved.
Resolved
results: list[str] = context.map(
event,
map_fn,
name="process-items",
config=MapConfig(
max_concurrency=1,
item_namer=lambda item, index: f"item-{item}",
),
).get_results()
return results
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,17 @@ Resources:
Handler: telemetry_3_result_select.handler
FunctionName: !Sub "${AWS::StackName}-telemetry-3"
Role: !Ref LambdaExecutionRoleArn

Telemetry4FullTreeMap:
Type: AWS::Serverless::Function
DependsOn: TelemetryLogGroup
Metadata:
BuildMethod: makefile
TestingMetadata:
TestDescription:
- telemetry-4
Properties:
CodeUri: src/
Handler: telemetry_4_full_tree_map.handler
FunctionName: !Sub "${AWS::StackName}-telemetry-4"
Role: !Ref LambdaExecutionRoleArn
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,20 @@

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_3_result_select"}
{
"telemetry_1_success",
"telemetry_2_failure",
"telemetry_3_result_select",
"telemetry_4_full_tree_map",
}
)
# 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",
"Telemetry4FullTreeMap": "telemetry-4",
}


Expand Down Expand Up @@ -130,6 +136,18 @@ def test_handler_modules_are_exactly_the_expected_set() -> None:
assert {path.stem for path in SRC_DIR.glob("*.py")} == EXPECTED_MODULES


def test_every_handler_module_is_deployed_by_exactly_one_function(
template: dict[str, Any],
) -> None:
"""Two functions on one module would leave one requirement untested."""
deployed_modules = sorted(
resource["Properties"]["Handler"].partition(".")[0]
for resource in functions(template).values()
)

assert deployed_modules == sorted(EXPECTED_MODULES)


def test_requirements_install_both_packages_from_one_commit() -> None:
requirements: str = (SRC_DIR / "requirements.txt").read_text(encoding="utf-8")

Expand Down Expand Up @@ -350,3 +368,53 @@ def test_telemetry_3_handler_exports_only_the_selected_result_key(
assert fetch_user["status"] == "SUCCEEDED"
assert fetch_user["count"] == 1
assert fetch_user["result"] == {"userId": "u-123"}


def test_telemetry_4_handler_records_the_full_operation_tree(
logs_client: FakeLogsClient,
) -> None:
"""telemetry-4 pins five operationsByName keys under full-tree detail."""
module = load_handler_module("telemetry_4_full_tree_map")

with DurableFunctionTestRunner(
handler=module.handler, execution_timeout=15
) as runner:
result = runner.run(input="[1, 2]")

assert result.status is InvocationStatus.SUCCEEDED
assert result.result is not None
assert json.loads(result.result) == ["Hello, 1!", "Hello, 2!"]
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 record["input"] == [1, 2]
assert record["output"] == ["Hello, 1!", "Hello, 2!"]
operations = record["operationsByName"]
assert set(operations) == {
"process-items",
"item-1",
"item-2",
"greet-1",
"greet-2",
}
expected_kinds = {
"process-items": ("CONTEXT", "Map"),
"item-1": ("CONTEXT", "MapIteration"),
"item-2": ("CONTEXT", "MapIteration"),
"greet-1": ("STEP", "Step"),
"greet-2": ("STEP", "Step"),
}
for name, (operation_type, sub_type) in expected_kinds.items():
operation = operations[name]
assert operation["type"] == operation_type
assert operation["subType"] == sub_type
assert operation["status"] == "SUCCEEDED"
assert operation["count"] == 1
assert operation["failedCount"] == 0
assert "result" not in operation
assert "error" not in operation
if operation_type == "CONTEXT":
assert "maxAttempt" not in operation
else:
assert operation["maxAttempt"] == 1
Loading