4
4
import inspect
5
5
import logging
6
6
import os
7
- from distutils .util import strtobool
8
7
from typing import Any , Callable , Dict , List , Optional , Tuple
9
8
10
9
import aws_xray_sdk
11
10
import aws_xray_sdk .core
12
11
13
- from aws_lambda_powertools . shared . constants import TRACER_CAPTURE_ERROR_ENV , TRACER_CAPTURE_RESPONSE_ENV
14
- from aws_lambda_powertools . shared .functions import resolve_env_var_choice
12
+ from .. shared import constants
13
+ from .. shared .functions import resolve_truthy_env_var_choice
15
14
16
15
is_cold_start = True
17
16
logger = logging .getLogger (__name__ )
@@ -283,9 +282,12 @@ def handler(event, context):
283
282
)
284
283
285
284
lambda_handler_name = lambda_handler .__name__
286
-
287
- capture_response = resolve_env_var_choice (env = TRACER_CAPTURE_RESPONSE_ENV , choice = capture_response )
288
- capture_error = resolve_env_var_choice (env = TRACER_CAPTURE_ERROR_ENV , choice = capture_error )
285
+ capture_response = resolve_truthy_env_var_choice (
286
+ env = os .getenv (constants .TRACER_CAPTURE_RESPONSE_ENV , "true" ), choice = capture_response
287
+ )
288
+ capture_error = resolve_truthy_env_var_choice (
289
+ env = os .getenv (constants .TRACER_CAPTURE_ERROR_ENV , "true" ), choice = capture_error
290
+ )
289
291
290
292
@functools .wraps (lambda_handler )
291
293
def decorate (event , context ):
@@ -478,8 +480,12 @@ async def async_tasks():
478
480
479
481
method_name = f"{ method .__name__ } "
480
482
481
- capture_response = resolve_env_var_choice (env = TRACER_CAPTURE_RESPONSE_ENV , choice = capture_response )
482
- capture_error = resolve_env_var_choice (env = TRACER_CAPTURE_ERROR_ENV , choice = capture_error )
483
+ capture_response = resolve_truthy_env_var_choice (
484
+ env = os .getenv (constants .TRACER_CAPTURE_RESPONSE_ENV , "true" ), choice = capture_response
485
+ )
486
+ capture_error = resolve_truthy_env_var_choice (
487
+ env = os .getenv (constants .TRACER_CAPTURE_ERROR_ENV , "true" ), choice = capture_error
488
+ )
483
489
484
490
if inspect .iscoroutinefunction (method ):
485
491
return self ._decorate_async_function (
@@ -681,14 +687,13 @@ def _is_tracer_disabled() -> bool:
681
687
bool
682
688
"""
683
689
logger .debug ("Verifying whether Tracing has been disabled" )
684
- is_lambda_sam_cli = os .getenv ("AWS_SAM_LOCAL" )
685
- is_chalice_cli = os .getenv ("AWS_CHALICE_CLI_MODE" )
686
- env_option = str (os .getenv ("POWERTOOLS_TRACE_DISABLED" , "false" ))
687
- disabled_env = strtobool (env_option )
690
+ is_lambda_sam_cli = os .getenv (constants .SAM_LOCAL_ENV )
691
+ is_chalice_cli = os .getenv (constants .CHALICE_LOCAL_ENV )
692
+ is_disabled = resolve_truthy_env_var_choice (env = os .getenv (constants .TRACER_DISABLED_ENV , "false" ))
688
693
689
- if disabled_env :
694
+ if is_disabled :
690
695
logger .debug ("Tracing has been disabled via env var POWERTOOLS_TRACE_DISABLED" )
691
- return disabled_env
696
+ return is_disabled
692
697
693
698
if is_lambda_sam_cli or is_chalice_cli :
694
699
logger .debug ("Running under SAM CLI env or not in Lambda env; disabling Tracing" )
@@ -706,7 +711,7 @@ def __build_config(
706
711
):
707
712
""" Populates Tracer config for new and existing initializations """
708
713
is_disabled = disabled if disabled is not None else self ._is_tracer_disabled ()
709
- is_service = service if service is not None else os .getenv ("POWERTOOLS_SERVICE_NAME" )
714
+ is_service = service if service is not None else os .getenv (constants . SERVICE_NAME_ENV )
710
715
711
716
self ._config ["provider" ] = provider if provider is not None else self ._config ["provider" ]
712
717
self ._config ["auto_patch" ] = auto_patch if auto_patch is not None else self ._config ["auto_patch" ]
0 commit comments