Skip to content

Commit

Permalink
Reformat if statement
Browse files Browse the repository at this point in the history
  • Loading branch information
harrryr committed Jul 5, 2024
1 parent 7bc9d6d commit 8c72858
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import sys
from logging import Logger, getLogger

from amazon.opentelemetry.distro.patches._instrumentation_patch import (
AWS_GEVENT_PATCH_MODULES,
apply_instrumentation_patches,
)
from amazon.opentelemetry.distro.patches._instrumentation_patch import apply_instrumentation_patches
from opentelemetry.distro import OpenTelemetryDistro
from opentelemetry.environment_variables import OTEL_PROPAGATORS, OTEL_PYTHON_ID_GENERATOR
from opentelemetry.sdk.environment_variables import (
Expand Down Expand Up @@ -68,7 +65,5 @@ def _configure(self, **kwargs):
OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION, "base2_exponential_bucket_histogram"
)

os.environ.setdefault(AWS_GEVENT_PATCH_MODULES, "all")

if kwargs.get("apply_patches", True):
apply_instrumentation_patches()
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,35 @@ def apply_instrumentation_patches() -> None:
"""
if _is_installed("gevent"):
try:
gevent_patch_module = os.environ.get(AWS_GEVENT_PATCH_MODULES)
if gevent_patch_module == "all":
# pylint: disable=import-outside-toplevel
# Delay import to only occur if monkey patch is needed (e.g. gevent is used to run application).
from gevent import monkey

monkey.patch_all()
elif gevent_patch_module == "none":
pass
else:
module_list = [module.strip() for module in gevent_patch_module.split(",")]
gevent_patch_module = os.environ.get(AWS_GEVENT_PATCH_MODULES, "all")

if gevent_patch_module != "none":
# pylint: disable=import-outside-toplevel
# Delay import to only occur if monkey patch is needed (e.g. gevent is used to run application).
from gevent import monkey

monkey.patch_all(
socket="socket" in module_list,
time="time" in module_list,
select="select" in module_list,
thread="thread" in module_list,
os="os" in module_list,
ssl="ssl" in module_list,
subprocess="subprocess" in module_list,
sys="sys" in module_list,
builtins="builtins" in module_list,
signal="signal" in module_list,
queue="queue" in module_list,
contextvars="contextvars" in module_list,
)
if gevent_patch_module == "all":

monkey.patch_all()
else:
module_list = [module.strip() for module in gevent_patch_module.split(",")]

monkey.patch_all(
socket="socket" in module_list,
time="time" in module_list,
select="select" in module_list,
thread="thread" in module_list,
os="os" in module_list,
ssl="ssl" in module_list,
subprocess="subprocess" in module_list,
sys="sys" in module_list,
builtins="builtins" in module_list,
signal="signal" in module_list,
queue="queue" in module_list,
contextvars="contextvars" in module_list,
)
except Exception as exc: # pylint: disable=broad-except
_logger.debug("Failed to monkey patch gevent, exception: %s", exc)
_logger.info("Failed to monkey patch gevent, exception: %s", exc)

if _is_installed("botocore ~= 1.0"):
# pylint: disable=import-outside-toplevel
Expand Down

0 comments on commit 8c72858

Please sign in to comment.