Skip to content

Commit b8d15c3

Browse files
authored
improv: disable tracer when using the Chalice CLI (#172)
1 parent 52314e6 commit b8d15c3

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

aws_lambda_powertools/tracing/tracer.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -622,14 +622,15 @@ def _is_tracer_disabled() -> bool:
622622
"""
623623
logger.debug("Verifying whether Tracing has been disabled")
624624
is_lambda_sam_cli = os.getenv("AWS_SAM_LOCAL")
625+
is_chalice_cli = os.getenv("AWS_CHALICE_CLI_MODE")
625626
env_option = str(os.getenv("POWERTOOLS_TRACE_DISABLED", "false"))
626627
disabled_env = strtobool(env_option)
627628

628629
if disabled_env:
629630
logger.debug("Tracing has been disabled via env var POWERTOOLS_TRACE_DISABLED")
630631
return disabled_env
631632

632-
if is_lambda_sam_cli:
633+
if is_lambda_sam_cli or is_chalice_cli:
633634
logger.debug("Running under SAM CLI env or not in Lambda env; disabling Tracing")
634635
return True
635636

tests/functional/test_tracing.py

+14
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ def handler(event, context):
6161
handler({}, {})
6262

6363

64+
def test_tracer_chalice_cli_mode(monkeypatch, dummy_response):
65+
# GIVEN tracer runs locally
66+
monkeypatch.setenv("AWS_CHALICE_CLI_MODE", "true")
67+
tracer = Tracer()
68+
69+
# WHEN a lambda function is run through the Chalice CLI.
70+
@tracer.capture_lambda_handler
71+
def handler(event, context):
72+
return dummy_response
73+
74+
# THEN tracer should run in disabled mode, and not raise an Exception
75+
handler({}, {})
76+
77+
6478
def test_tracer_metadata_disabled(dummy_response):
6579
# GIVEN tracer is disabled, and annotations/metadata are used
6680
tracer = Tracer(disabled=True)

0 commit comments

Comments
 (0)