Skip to content

Commit 031f0b1

Browse files
authored
Fix RecursionError by preventing duplicate instrumentation in urllib3
Added a guard (_instrumented flag) to prevent urllib3 instrumentation from running multiple times, which caused RecursionError (#4532). This ensures _instrument() exits early if already applied.
1 parent 5279805 commit 031f0b1

File tree

1 file changed

+4
-1
lines changed
  • instrumentation/opentelemetry-instrumentation-urllib3/src/opentelemetry/instrumentation/urllib3

1 file changed

+4
-1
lines changed

instrumentation/opentelemetry-instrumentation-urllib3/src/opentelemetry/instrumentation/urllib3/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class RequestInfo:
199199
class URLLib3Instrumentor(BaseInstrumentor):
200200
def instrumentation_dependencies(self) -> Collection[str]:
201201
return _instruments
202-
202+
_instrumented = False
203203
def _instrument(self, **kwargs):
204204
"""Instruments the urllib3 module
205205
@@ -214,6 +214,9 @@ def _instrument(self, **kwargs):
214214
list of regexes used to exclude URLs from tracking
215215
"""
216216
# initialize semantic conventions opt-in if needed
217+
if self._instrumented:
218+
return
219+
self._instrumented = True
217220
_OpenTelemetrySemanticConventionStability._initialize()
218221
sem_conv_opt_in_mode = _OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
219222
_OpenTelemetryStabilitySignalType.HTTP,

0 commit comments

Comments
 (0)