Skip to content

Commit 4c6a5f4

Browse files
committed
don't use xray_recorder.capture as a decorator
1 parent cff27d6 commit 4c6a5f4

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/unity_initiator/cloud/lambda_handler.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,33 @@
1717

1818

1919
@log_exceptions
20-
@xray_recorder.capture("lambda_handler_base")
2120
def lambda_handler_base(event, context):
2221
"""Base lambda handler that instantiates a router, globally, and executes actions for a single payload."""
2322

2423
logger.info("context: %s", context)
2524

26-
# TODO: Should use AppConfig. For now, either reading router config body in ROUTER_CFG env variable
27-
# or from a url in ROUTER_CFG_URL env variable.
28-
global ROUTER
29-
if ROUTER is None:
30-
router_cfg = os.environ.get("ROUTER_CFG", "").strip()
31-
router_cfg_url = os.environ.get("ROUTER_CFG_URL", "").strip()
32-
if router_cfg == "":
33-
if router_cfg_url != "":
34-
with smart_open.open(router_cfg_url, "r") as f:
35-
router_cfg = f.read()
36-
else:
37-
raise RuntimeError(
38-
"No router configuration specified via ROUTER_CFG or ROUTER_CFG_URL env variables."
39-
)
40-
fd, router_file = mkstemp(prefix="router_", suffix=".yaml", text=True)
41-
with os.fdopen(fd, "w") as f:
42-
f.write(router_cfg)
43-
ROUTER = Router(router_file)
44-
os.unlink(router_file)
45-
xray_recorder.put_annotation("payload", event["payload"])
46-
return ROUTER.execute_actions(event["payload"])
25+
with xray_recorder.capture("lambda_handler_base"):
26+
# TODO: Should use AppConfig. For now, either reading router config body in ROUTER_CFG env variable
27+
# or from a url in ROUTER_CFG_URL env variable.
28+
global ROUTER
29+
if ROUTER is None:
30+
router_cfg = os.environ.get("ROUTER_CFG", "").strip()
31+
router_cfg_url = os.environ.get("ROUTER_CFG_URL", "").strip()
32+
if router_cfg == "":
33+
if router_cfg_url != "":
34+
with smart_open.open(router_cfg_url, "r") as f:
35+
router_cfg = f.read()
36+
else:
37+
raise RuntimeError(
38+
"No router configuration specified via ROUTER_CFG or ROUTER_CFG_URL env variables."
39+
)
40+
fd, router_file = mkstemp(prefix="router_", suffix=".yaml", text=True)
41+
with os.fdopen(fd, "w") as f:
42+
f.write(router_cfg)
43+
ROUTER = Router(router_file)
44+
os.unlink(router_file)
45+
xray_recorder.put_annotation("payload", event["payload"])
46+
return ROUTER.execute_actions(event["payload"])
4747

4848

4949
def lambda_handler_multiple_payloads(event, context):

0 commit comments

Comments
 (0)