Skip to content

Commit 24be6da

Browse files
authored
Merge branch 'main' into feat/extras-ai
2 parents deac9e8 + 260e375 commit 24be6da

6 files changed

Lines changed: 169 additions & 4 deletions

File tree

‎.github/workflows/telemetry-conformance-tests.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ jobs:
4242
id-token: write
4343
# The pinned SHA also selects the runner and telemetry-extension revision the shared
4444
# workflow installs, so it must be reachable from a branch. It is the merge commit of
45-
# aws-durable-execution-conformance-tests PR #183 on that repository's main branch.
46-
uses: aws/aws-durable-execution-conformance-tests/.github/workflows/telemetry-suite.yml@cf13ef27d6e13a4423f7e0a178f9a3d4bb1099f0
45+
# aws-durable-execution-conformance-tests PR #185 on that repository's main branch.
46+
uses: aws/aws-durable-execution-conformance-tests/.github/workflows/telemetry-suite.yml@b380cbf19bbc4f08a2d7c593d4bf24f585946415
4747
with:
4848
language: python
4949
resource_prefix: python

‎packages/aws-durable-execution-sdk-python-conformance-tests-telemetry/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This package holds the SDK-specific part: the handler and the SAM template that
2121
| `telemetry` | `telemetry-1` | One successful single-step execution emits one `SUCCEEDED` record with `input`, `output`, ARN-derived identity fields, and `operationsByName`. |
2222
| `telemetry` | `telemetry-2` | One failed execution emits one `FAILED` record with an `error` on the execution and on `operationsByName.charge`. |
2323
| `telemetry` | `telemetry-3` | An `OperationOverride.result` transform exports exactly `{userId}` of a three-key step result; the record has no `input` or `output`. |
24+
| `telemetry` | `telemetry-4` | With `operation_detail="full-tree"`, the record holds the map, its two iteration contexts, and the two steps by name. |
2425

2526
## Layout
2627

@@ -29,6 +30,7 @@ src/
2930
telemetry_1_success.py # single step "increment"; plugin + CloudWatchLogsExporter
3031
telemetry_2_failure.py # step "charge" fails; handler raises "payment failed" from the step error
3132
telemetry_3_result_select.py # step "fetch-user"; override transform keeps only userId in the record
33+
telemetry_4_full_tree_map.py # map "process-items" with step "greet-<item>"; full-tree detail records all five operations
3234
Makefile # one build-<LogicalId> target per function, used by `sam build`
3335
requirements.txt # core SDK + telemetry exporter, pinned to ${PYTHON_SDK_REF}
3436
template.yaml # declares TelemetryLogGroupName and creates the group

‎packages/aws-durable-execution-sdk-python-conformance-tests-telemetry/src/Makefile‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: build-Telemetry1Success build-Telemetry2Failure build-Telemetry3ResultSelect build-handlers
1+
.PHONY: build-Telemetry1Success build-Telemetry2Failure build-Telemetry3ResultSelect build-Telemetry4FullTreeMap build-handlers
22

33
# Every function builds from the same src/ directory with the same recipe.
44
# SAM calls one target per logical ID, so each target points at the shared one.
@@ -8,6 +8,8 @@ build-Telemetry2Failure: build-handlers
88

99
build-Telemetry3ResultSelect: build-handlers
1010

11+
build-Telemetry4FullTreeMap: build-handlers
12+
1113
build-handlers:
1214
python3 -m pip install --upgrade \
1315
--target "$(ARTIFACTS_DIR)" \
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# SPDX-FileCopyrightText: 2026-present Amazon.com, Inc. or its affiliates.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
"""Full-tree operation detail for requirement telemetry-4.
5+
6+
The handler maps over the event ``[1, 2]`` with ``maxConcurrency=1``. The item
7+
namer names each iteration ``item-<item>``. Each iteration runs one step named
8+
``greet-<item>``. The plugin runs with ``operation_detail="full-tree"``. So the
9+
record's ``operationsByName`` holds the map context ``process-items``, the two
10+
iteration contexts ``item-1`` and ``item-2``, and the two steps ``greet-1`` and
11+
``greet-2``. Under ``top-level`` detail the record would hold only
12+
``process-items``.
13+
14+
The handler uses the real SDK API only. It builds no record and calls no
15+
exporter method. A missing or wrong record is the plugin's defect, and that
16+
defect is the signal the suite measures.
17+
"""
18+
19+
from __future__ import annotations
20+
21+
import os
22+
from typing import Any
23+
24+
from aws_durable_execution_sdk_python import (
25+
DurableContext,
26+
StepContext,
27+
durable_execution,
28+
durable_step,
29+
)
30+
from aws_durable_execution_sdk_python.config import MapConfig
31+
from aws_durable_execution_sdk_python_telemetry_exporter import (
32+
CloudWatchLogsExporter,
33+
ContentConfig,
34+
DurableExecutionTelemetryConfig,
35+
durable_execution_telemetry,
36+
)
37+
38+
39+
# The template sets this variable. Without it the exporter has no target.
40+
# So the module fails at import instead of dropping records silently.
41+
log_group_name = os.environ.get("TELEMETRY_LOG_GROUP_NAME")
42+
if not log_group_name:
43+
raise RuntimeError("TELEMETRY_LOG_GROUP_NAME must be set")
44+
45+
46+
@durable_step
47+
def greet(_step_context: StepContext, item: int) -> str:
48+
return f"Hello, {item}!"
49+
50+
51+
def map_fn(ctx: DurableContext, item: int, _index: int, _items: Any) -> str:
52+
result: str = ctx.step(greet(item), name=f"greet-{item}")
53+
return result
54+
55+
56+
@durable_execution(
57+
plugins=[
58+
durable_execution_telemetry(
59+
DurableExecutionTelemetryConfig(
60+
exporters=[CloudWatchLogsExporter(log_group_name=log_group_name)],
61+
emit_mode="on-complete",
62+
sampling_rate=1,
63+
operation_detail="full-tree",
64+
content=ContentConfig(input=True, output=True),
65+
)
66+
)
67+
]
68+
)
69+
def handler(event: list[int], context: DurableContext) -> list[str]:
70+
results: list[str] = context.map(
71+
event,
72+
map_fn,
73+
name="process-items",
74+
config=MapConfig(
75+
max_concurrency=1,
76+
item_namer=lambda item, index: f"item-{item}",
77+
),
78+
).get_results()
79+
return results

‎packages/aws-durable-execution-sdk-python-conformance-tests-telemetry/template.yaml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,17 @@ Resources:
7474
Handler: telemetry_3_result_select.handler
7575
FunctionName: !Sub "${AWS::StackName}-telemetry-3"
7676
Role: !Ref LambdaExecutionRoleArn
77+
78+
Telemetry4FullTreeMap:
79+
Type: AWS::Serverless::Function
80+
DependsOn: TelemetryLogGroup
81+
Metadata:
82+
BuildMethod: makefile
83+
TestingMetadata:
84+
TestDescription:
85+
- telemetry-4
86+
Properties:
87+
CodeUri: src/
88+
Handler: telemetry_4_full_tree_map.handler
89+
FunctionName: !Sub "${AWS::StackName}-telemetry-4"
90+
Role: !Ref LambdaExecutionRoleArn

‎packages/aws-durable-execution-sdk-python-conformance-tests-telemetry/tests/test_telemetry_examples.py‎

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,20 @@
3434

3535
SDK_REPOSITORY_URL = "git+https://github.com/aws/aws-durable-execution-sdk-python.git"
3636
EXPECTED_MODULES: frozenset[str] = frozenset(
37-
{"telemetry_1_success", "telemetry_2_failure", "telemetry_3_result_select"}
37+
{
38+
"telemetry_1_success",
39+
"telemetry_2_failure",
40+
"telemetry_3_result_select",
41+
"telemetry_4_full_tree_map",
42+
}
3843
)
3944
# Logical ID -> requirement ID. The function name suffix must equal the
4045
# requirement ID, so the runner can match the deployed function to its test.
4146
EXPECTED_FUNCTIONS: dict[str, str] = {
4247
"Telemetry1Success": "telemetry-1",
4348
"Telemetry2Failure": "telemetry-2",
4449
"Telemetry3ResultSelect": "telemetry-3",
50+
"Telemetry4FullTreeMap": "telemetry-4",
4551
}
4652

4753

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

132138

139+
def test_every_handler_module_is_deployed_by_exactly_one_function(
140+
template: dict[str, Any],
141+
) -> None:
142+
"""Two functions on one module would leave one requirement untested."""
143+
deployed_modules = sorted(
144+
resource["Properties"]["Handler"].partition(".")[0]
145+
for resource in functions(template).values()
146+
)
147+
148+
assert deployed_modules == sorted(EXPECTED_MODULES)
149+
150+
133151
def test_requirements_install_both_packages_from_one_commit() -> None:
134152
requirements: str = (SRC_DIR / "requirements.txt").read_text(encoding="utf-8")
135153

@@ -350,3 +368,53 @@ def test_telemetry_3_handler_exports_only_the_selected_result_key(
350368
assert fetch_user["status"] == "SUCCEEDED"
351369
assert fetch_user["count"] == 1
352370
assert fetch_user["result"] == {"userId": "u-123"}
371+
372+
373+
def test_telemetry_4_handler_records_the_full_operation_tree(
374+
logs_client: FakeLogsClient,
375+
) -> None:
376+
"""telemetry-4 pins five operationsByName keys under full-tree detail."""
377+
module = load_handler_module("telemetry_4_full_tree_map")
378+
379+
with DurableFunctionTestRunner(
380+
handler=module.handler, execution_timeout=15
381+
) as runner:
382+
result = runner.run(input="[1, 2]")
383+
384+
assert result.status is InvocationStatus.SUCCEEDED
385+
assert result.result is not None
386+
assert json.loads(result.result) == ["Hello, 1!", "Hello, 2!"]
387+
assert len(logs_client.put_log_events_calls) == 1
388+
assert logs_client.put_log_events_calls[0]["logGroupName"] == LOG_GROUP_NAME
389+
record = logs_client.records()[0]
390+
assert record["status"] == "SUCCEEDED"
391+
assert record["input"] == [1, 2]
392+
assert record["output"] == ["Hello, 1!", "Hello, 2!"]
393+
operations = record["operationsByName"]
394+
assert set(operations) == {
395+
"process-items",
396+
"item-1",
397+
"item-2",
398+
"greet-1",
399+
"greet-2",
400+
}
401+
expected_kinds = {
402+
"process-items": ("CONTEXT", "Map"),
403+
"item-1": ("CONTEXT", "MapIteration"),
404+
"item-2": ("CONTEXT", "MapIteration"),
405+
"greet-1": ("STEP", "Step"),
406+
"greet-2": ("STEP", "Step"),
407+
}
408+
for name, (operation_type, sub_type) in expected_kinds.items():
409+
operation = operations[name]
410+
assert operation["type"] == operation_type
411+
assert operation["subType"] == sub_type
412+
assert operation["status"] == "SUCCEEDED"
413+
assert operation["count"] == 1
414+
assert operation["failedCount"] == 0
415+
assert "result" not in operation
416+
assert "error" not in operation
417+
if operation_type == "CONTEXT":
418+
assert "maxAttempt" not in operation
419+
else:
420+
assert operation["maxAttempt"] == 1

0 commit comments

Comments
 (0)