Skip to content

Commit a0f6940

Browse files
author
Alex Wang
committed
feat: add otel layers for otel examples
1 parent b79323c commit a0f6940

5 files changed

Lines changed: 54 additions & 11 deletions

File tree

packages/aws-durable-execution-sdk-python-examples/cli.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
try:
2121
import boto3
22+
2223
from aws_durable_execution_sdk_python.lambda_service import LambdaClient
2324
except ImportError:
2425
sys.exit(1)
@@ -326,6 +327,9 @@ def deploy_function(example_name: str, function_name: str | None = None):
326327
f"arn:aws:iam::{config['account_id']}:role/DurableFunctionsIntegrationTestRole"
327328
)
328329

330+
env_vars = {"AWS_ENDPOINT_URL_LAMBDA": config["lambda_endpoint"]}
331+
env_vars.update(example_config.get("environment", {}))
332+
329333
function_config = {
330334
"FunctionName": function_name,
331335
"Runtime": "python3.13",
@@ -334,13 +338,17 @@ def deploy_function(example_name: str, function_name: str | None = None):
334338
"Description": example_config["description"],
335339
"Timeout": 60,
336340
"MemorySize": 128,
337-
"Environment": {
338-
"Variables": {"AWS_ENDPOINT_URL_LAMBDA": config["lambda_endpoint"]}
339-
},
341+
"Environment": {"Variables": env_vars},
340342
"DurableConfig": example_config["durableConfig"],
341343
"LoggingConfig": example_config.get("loggingConfig", {}),
342344
}
343345

346+
if example_config["layers"]:
347+
function_config["Layers"] = example_config["layers"]
348+
349+
if example_config["tracing"]:
350+
function_config["TracingConfig"] = {"Mode": example_config["tracing"]}
351+
344352
if config["kms_key_arn"]:
345353
function_config["KMSKeyArn"] = config["kms_key_arn"]
346354

packages/aws-durable-execution-sdk-python-examples/examples-catalog.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,13 @@
634634
"RetentionPeriodInDays": 7,
635635
"ExecutionTimeout": 300
636636
},
637+
"tracing": "Active",
638+
"layers": [
639+
"arn:aws:lambda:us-west-2:615299751070:layer:AWSOpenTelemetryDistroPython:32"
640+
],
641+
"environment": {
642+
"AWS_LAMBDA_EXEC_WRAPPER": "/opt/otel-instrument"
643+
},
637644
"path": "./src/plugin/execution_with_otel.py"
638645
},
639646
{
@@ -649,6 +656,14 @@
649656
"ApplicationLogLevel": "INFO",
650657
"LogFormat": "JSON"
651658
},
659+
"tracing": "Active",
660+
"layers": [
661+
"arn:aws:lambda:us-west-2:615299751070:layer:AWSOpenTelemetryDistroPython:32"
662+
],
663+
"environment": {
664+
"AWS_LAMBDA_EXEC_WRAPPER": "/opt/otel-instrument",
665+
"OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED": "true"
666+
},
652667
"path": "./src/otel/otel_logger_example.py"
653668
}
654669
]

packages/aws-durable-execution-sdk-python-examples/scripts/generate_sam_template.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import json
44
from pathlib import Path
55

6-
import json
7-
86

97
def load_catalog():
108
"""Load examples catalog."""
@@ -95,6 +93,21 @@ def generate_sam_template():
9593
example["durableConfig"]
9694
)
9795

96+
if "layers" in example:
97+
template["Resources"][function_name]["Properties"]["Layers"] = example[
98+
"layers"
99+
]
100+
101+
if "tracing" in example:
102+
template["Resources"][function_name]["Properties"]["Tracing"] = example[
103+
"tracing"
104+
]
105+
106+
if "environment" in example:
107+
template["Resources"][function_name]["Properties"]["Environment"] = {
108+
"Variables": example["environment"]
109+
}
110+
98111
template_path = Path(__file__).parent.parent / "template.yaml"
99112
with open(template_path, "w") as f:
100113
json.dump(template, f, sort_keys=False, indent=2)

packages/aws-durable-execution-sdk-python-examples/src/otel/otel_logger_example.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@
2828
from aws_durable_execution_sdk_python.execution import durable_execution
2929

3030

31-
tracer_provider = TracerProvider()
32-
trace.set_tracer_provider(tracer_provider)
33-
34-
# enrich_logger defaults to True, so the execution logger is wrapped with OTel
35-
# trace context injection (otel.trace_id, otel.span_id, otel.trace_sampled).
31+
tracer_provider = trace.get_tracer_provider()
3632
otel = DurableExecutionOtelPlugin(tracer_provider)
3733

3834

packages/aws-durable-execution-sdk-python-examples/template.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
]
3939
},
4040
"ManagedPolicyArns": [
41-
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
41+
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
42+
"arn:aws:iam::aws:policy/CloudWatchLambdaApplicationSignalsExecutionRolePolicy"
4243
],
4344
"Policies": [
4445
{
@@ -1044,6 +1045,16 @@
10441045
"Arn"
10451046
]
10461047
},
1048+
"Tracing": "Active",
1049+
"Layers": [
1050+
"arn:aws:lambda:us-west-2:615299751070:layer:AWSOpenTelemetryDistroPython:32" # from https://aws-otel.github.io/docs/getting-started/lambda#adot-lambda-layer-arns
1051+
],
1052+
"Environment": {
1053+
"Variables": {
1054+
"AWS_LAMBDA_EXEC_WRAPPER": "/opt/otel-instrument",
1055+
"OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED": "true"
1056+
}
1057+
},
10471058
"DurableConfig": {
10481059
"RetentionPeriodInDays": 7,
10491060
"ExecutionTimeout": 300

0 commit comments

Comments
 (0)