Skip to content

Commit 6bffb7a

Browse files
committed
Add Monkey Patch for Gevent
1 parent 912dd93 commit 6bffb7a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

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

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

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

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+
5868
os.environ.setdefault(OTEL_EXPORTER_OTLP_PROTOCOL, "http/protobuf")
5969

6070
super(AwsOpenTelemetryDistro, self)._configure()

0 commit comments

Comments
 (0)