Skip to content

Commit 3b107e9

Browse files
committed
fix: SonarQube failed conditions on new code.
- Deleted `src/instana/util/gunicorn.py` since the code is duplicated in `running_in_gunicorn()` function from `src/instana/log.py`. - Adapted code to import `running_in_gunicorn()` from `src/instana/log.py`. - Add tests for `running_in_gunicorn()` to increase the coverage on new code. Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
1 parent 0256e19 commit 3b107e9

5 files changed

Lines changed: 314 additions & 48 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ dev = [
6565
"pytest-mock",
6666
"pre-commit>=3.0.0",
6767
"ruff",
68+
"gunicorn",
6869
]
6970

7071
[project.urls]

src/instana/instrumentation/fastapi.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
from starlette.middleware import Middleware
2121

2222
from instana.instrumentation.asgi import InstanaASGIMiddleware
23-
from instana.log import logger
24-
from instana.util.gunicorn import running_in_gunicorn
23+
from instana.log import logger, running_in_gunicorn
2524
from instana.util.traceutils import get_tracer_tuple
2625

2726
if TYPE_CHECKING:

src/instana/log.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# (c) Copyright IBM Corp. 2021
1+
# (c) Copyright IBM Corp. 2021, 2026
22
# (c) Copyright Instana Inc. 2016
33

44
from __future__ import print_function
@@ -10,7 +10,7 @@
1010
logger = None
1111

1212

13-
def get_standard_logger():
13+
def get_standard_logger() -> logging.Logger:
1414
"""
1515
Retrieves and configures a standard logger for the Instana package
1616
@@ -28,7 +28,7 @@ def get_standard_logger():
2828
return standard_logger
2929

3030

31-
def get_aws_lambda_logger():
31+
def get_aws_lambda_logger() -> logging.Logger:
3232
"""
3333
Retrieves the preferred logger for AWS Lambda
3434
@@ -39,7 +39,7 @@ def get_aws_lambda_logger():
3939
return aws_lambda_logger
4040

4141

42-
def glogging_available():
42+
def glogging_available() -> bool:
4343
"""
4444
Determines if the gunicorn.glogging package is available
4545
@@ -58,7 +58,7 @@ def glogging_available():
5858
return package_check
5959

6060

61-
def running_in_gunicorn():
61+
def running_in_gunicorn() -> bool:
6262
"""
6363
Determines if we are running inside of a gunicorn process.
6464
@@ -85,12 +85,11 @@ def running_in_gunicorn():
8585

8686
return process_check
8787
except Exception:
88-
logger.debug("Instana.log.running_in_gunicorn: ", exc_info=True)
8988
return False
9089

9190

92-
aws_env = os.environ.get("AWS_EXECUTION_ENV", "")
93-
env_is_aws_lambda = "AWS_Lambda_" in aws_env
91+
env_is_aws_lambda = "AWS_Lambda_" in os.environ.get("AWS_EXECUTION_ENV", "")
92+
9493

9594
if running_in_gunicorn() and glogging_available():
9695
logger = logging.getLogger("gunicorn.error")

src/instana/util/gunicorn.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)