|
5 | 5 | from typing import Any |
6 | 6 |
|
7 | 7 | import sentry_sdk |
8 | | -from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration |
9 | 8 |
|
10 | 9 | logger = logging.getLogger("__name__") |
11 | 10 |
|
@@ -62,41 +61,37 @@ def check_required_env_vars(self) -> None: |
62 | 61 | message = f"Missing required environment variables: {', '.join(missing_vars)}" |
63 | 62 | raise OSError(message) |
64 | 63 |
|
65 | | - def configure_logger(self, *, verbose: bool) -> str: |
66 | | - logger = logging.getLogger() |
67 | | - if verbose: |
68 | | - logging.basicConfig( |
69 | | - format=( |
70 | | - "%(asctime)s %(levelname)s %(name)s.%(funcName)s() " |
71 | | - "line %(lineno)d: " |
72 | | - "%(message)s" |
73 | | - ) |
74 | | - ) |
75 | | - logger.setLevel(logging.DEBUG) |
76 | | - else: |
77 | | - logging.basicConfig( |
78 | | - format="%(asctime)s %(levelname)s %(name)s.%(funcName)s(): %(message)s" |
79 | | - ) |
80 | | - logger.setLevel(logging.INFO) |
81 | 64 |
|
82 | | - return ( |
83 | | - f"Logger '{logger.name}' configured with level=" |
84 | | - f"{logging.getLevelName(logger.getEffectiveLevel())}" |
| 65 | +def configure_logger(*, verbose: bool) -> str: |
| 66 | + logger = logging.getLogger() |
| 67 | + if verbose: |
| 68 | + logging.basicConfig( |
| 69 | + format=( |
| 70 | + "%(asctime)s %(levelname)s %(name)s.%(funcName)s() " |
| 71 | + "line %(lineno)d: " |
| 72 | + "%(message)s" |
| 73 | + ) |
85 | 74 | ) |
| 75 | + logger.setLevel(logging.DEBUG) |
| 76 | + else: |
| 77 | + logging.basicConfig( |
| 78 | + format="%(asctime)s %(levelname)s %(name)s.%(funcName)s(): %(message)s" |
| 79 | + ) |
| 80 | + logger.setLevel(logging.INFO) |
86 | 81 |
|
87 | | - def configure_sentry(self) -> None: |
88 | | - if sentry_dsn := self.SENTRY_DSN: |
89 | | - sentry_sdk.init( |
90 | | - dsn=sentry_dsn, |
91 | | - environment=self.WORKSPACE, |
92 | | - integrations=[ |
93 | | - AwsLambdaIntegration(), |
94 | | - ], |
95 | | - traces_sample_rate=1.0, |
96 | | - ) |
97 | | - logger.info( |
98 | | - "Sentry DSN found, exceptions will be sent to Sentry with env=%s", |
99 | | - self.WORKSPACE, |
100 | | - ) |
101 | | - else: |
102 | | - logger.info("No Sentry DSN found, exceptions will not be sent to Sentry") |
| 82 | + return ( |
| 83 | + f"Logger '{logger.name}' configured with level=" |
| 84 | + f"{logging.getLevelName(logger.getEffectiveLevel())}" |
| 85 | + ) |
| 86 | + |
| 87 | + |
| 88 | +def configure_sentry() -> str: |
| 89 | + env = os.getenv("WORKSPACE") |
| 90 | + sentry_dsn = os.getenv("SENTRY_DSN") |
| 91 | + if sentry_dsn and sentry_dsn.lower() != "none": |
| 92 | + sentry_sdk.init( |
| 93 | + sentry_dsn, |
| 94 | + environment=env, |
| 95 | + ) |
| 96 | + return f"Sentry DSN found, exceptions will be sent to Sentry with env={env}" |
| 97 | + return "No Sentry DSN found, exceptions will not be sent to Sentry" |
0 commit comments