RecursionError: maximum recursion depth exceeded
Describe your environment
OS: (e.g, Ubuntu) Python version: Python 3.12.9 SDK version: 1.30 API version: 1.30
What happened?
^^^^^^^^^^^^^
File "/home/admin/.venv/lib/python3.12/site-packages/opentelemetry/instrumentation/urllib3/__init__.py", line 316, in instrumented_urlopen
return wrapped(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/admin/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 787, in urlopen
response = self._make_request(
^^^^^^^^^^^^^^^^^^^
File "/home/admin/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 464, in _make_request
self._validate_conn(conn)
File "/home/admin/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 1093, in _validate_conn
conn.connect()
File "/home/admin/.venv/lib/python3.12/site-packages/urllib3/connection.py", line 741, in connect
sock_and_verified = _ssl_wrap_socket_and_match_hostname(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/admin/.venv/lib/python3.12/site-packages/urllib3/connection.py", line 873, in _ssl_wrap_socket_and_match_hostname
context = create_urllib3_context(
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/admin/.venv/lib/python3.12/site-packages/urllib3/util/ssl_.py", line 293, in create_urllib3_context
context.minimum_version = TLSVersion.TLSv1_2
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/python3/lib/python3.12/ssl.py", line 545, in minimum_version
super(SSLContext, SSLContext).minimum_version.__set__(self, value)
File "/usr/local/python3/lib/python3.12/ssl.py", line 545, in minimum_version
super(SSLContext, SSLContext).minimum_version.__set__(self, value)
File "/usr/local/python3/lib/python3.12/ssl.py", line 545, in minimum_version
super(SSLContext, SSLContext).minimum_version.__set__(self, value)
[Previous line repeated 851 more times]
File "/usr/local/python3/lib/python3.12/ssl.py", line 543, in minimum_version
if value == TLSVersion.SSLv3:
^^^^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded
Steps to Reproduce
when request or httpx will reproduce
Expected Result
post traces correct
Actual Result
RecursionError: maximum recursion depth exceeded
Additional context
No response
Would you like to implement a fix?
None
I have same question.
Title: maximum recursion depth exceeded error when using OpenTelemetry with Flask and Python 3.12.9
Body:
Hi OpenTelemetry team,
I'm encountering a maximum recursion depth exceeded error in my Python application when using OpenTelemetry auto-instrumentation.
✅ Environment:
- Python version: 3.12.9
- Framework: Flask
- Instrumentation method: OpenTelemetry Operator
-
Auto-instrumentation image:
ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-python:0.51b0
✅ OpenTelemetry environment variables:
python:
env:
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: http://***
- name: OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED
value: "true"
⚠️ Error:
2025-04-11 08:45:50,191.191 WARNING [Dummy-4] [****_file.py:76] [...] - ****: maximum recursion depth exceeded
This issue occurs when my application uploads an image file to an object storage service. The failure happens deep inside the request logic, and the log shows a recursion depth error.
✅ Additional Info:
I can also see OpenTelemetry sending traces successfully:
http://****-collector.****:4318 "POST /v1/traces HTTP/11" 200 2
But this recursion issue is affecting functionality and stability.
🙏 Request:
Could this be related to how logging is auto-instrumented in recent versions of the auto-instrumentation image? Any suggested workaround or fix?
Note: If I disable auto-instrumentation, this issue does not occur.
Let me know if more debug info (e.g., full traceback or minimal example) is helpful.
Thanks a lot! 🙏
Do you have a reproducer? Which version of urllib3?
Don't know if this helps but setting otel_logger.propagate = False worked for me.
Do you have a reproducer? Which version of urllib3?
My version of urllib3 is 2.2.3, and the version of opentelemetry-instrumentation-urllib3 is 0.51b0.
root@dify-api-v2:/app/api# pip show urllib3
Name: urllib3
Version: 2.2.3
Summary: HTTP library with thread-safe connection pooling, file post, and more.
Home-page:
Author:
Author-email: Andrey Petrov <[email protected]>
License:
Location: /otel-auto-instrumentation
Requires:
Required-by: botocore, clickhouse-connect, docker, elastic-transport, kubernetes, mailchimp-transactional, opensearch-py, qdrant-client, requests, sagemaker, sentry-sdk, types-requests, volcengine-python-sdk
root@dify-api-v2:/app/api# python -m pip list | grep urllib3
opentelemetry-instrumentation-urllib3 0.51b0
urllib3 2.2.3
Don't know if this helps but setting
otel_logger.propagate = Falseworked for me.
Thank you very much. I test it in my enviroment,but the aforementioned error still occurs.
I suspect this issue is caused by gevent. Maybe you used the code from Dify? https://github.com/langgenius/dify/blob/8299614e602925208ae98cef6ed3c1ec56d257df/api/docker/entrypoint.sh#L35
This works for me
Don't know if this helps but setting otel_logger.propagate = False worked for me.
from logging import getLogger
otel_logger = getLogger("opentelemetry")
otel_logger.propagate = False