Skip to content

Commit e6ca6ac

Browse files
committed
Add monkey.patch to instrumentation_patch
1 parent 6bffb7a commit e6ca6ac

File tree

4 files changed

+8
-11
lines changed

4 files changed

+8
-11
lines changed

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_distro.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# SPDX-License-Identifier: Apache-2.0
33
import os
44
import sys
5-
from pathlib import Path
65
from logging import Logger, getLogger
76

87
from amazon.opentelemetry.distro.patches._instrumentation_patch import apply_instrumentation_patches
@@ -56,15 +55,6 @@ def _configure(self, **kwargs):
5655
if cwd_path not in sys.path:
5756
sys.path.insert(0, cwd_path)
5857

59-
# If application is using gevent, the application may crash due to SSL recursive issues. Check if application has the module 'gevent', and if so, patch SSL before gevent is started.
60-
for path in Path('/').rglob('*'):
61-
try:
62-
if path.is_dir() and path.name == 'gevent':
63-
from gevent import monkey; monkey.patch_ssl()
64-
break
65-
except Exception:
66-
continue
67-
6858
os.environ.setdefault(OTEL_EXPORTER_OTLP_PROTOCOL, "http/protobuf")
6959

7060
super(AwsOpenTelemetryDistro, self)._configure()

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/patches/_instrumentation_patch.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ def apply_instrumentation_patches() -> None:
2020
2121
Where possible, automated testing should be run to catch upstream changes resulting in broken patches
2222
"""
23+
if _is_installed("gevent"):
24+
# pylint: disable=import-outside-toplevel
25+
# Delay import to only occur if monkey patch is needed (e.g. gevent is used to run application).
26+
from gevent import monkey
27+
28+
monkey.patch_ssl()
2329

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

dev-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ codespell==2.1.0
1414
requests==2.32.0
1515
ruamel.yaml==0.17.21
1616
flaky==3.7.0
17-
botocore==1.34.67
17+
botocore==1.34.67

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ commands_pre =
3030
; Install common packages for all the tests. These are not needed in all the
3131
; cases but it saves a lot of boilerplate in this file.
3232
test: pip install botocore
33+
test: pip install gevent
3334
test: pip install "opentelemetry-api[test] @ {env:CORE_REPO}#egg=opentelemetry-api&subdirectory=opentelemetry-api"
3435
test: pip install "opentelemetry-sdk[test] @ {env:CORE_REPO}#egg=opentelemetry-sdk&subdirectory=opentelemetry-sdk"
3536
test: pip install "opentelemetry-instrumentation[test] @ {env:CONTRIB_REPO}#egg=opentelemetry-instrumentation&subdirectory=opentelemetry-instrumentation"

0 commit comments

Comments
 (0)