Skip to content

Commit ef1b2af

Browse files
authored
Setup opentelemetry patch only once (#4595)
All our integrations follow the `setup_once` logic while the otel patching was being done for each `Client` again leading to recursive patching. This was revealed by removing the transport test forks.
1 parent dbb8ead commit ef1b2af

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

sentry_sdk/opentelemetry/tracing.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,25 @@
1818
from sentry_sdk.utils import logger
1919

2020

21+
READABLE_SPAN_PATCHED = False
22+
23+
2124
def patch_readable_span() -> None:
2225
"""
2326
We need to pass through sentry specific metadata/objects from Span to ReadableSpan
2427
to work with them consistently in the SpanProcessor.
2528
"""
26-
old_readable_span = Span._readable_span
29+
global READABLE_SPAN_PATCHED
30+
if not READABLE_SPAN_PATCHED:
31+
old_readable_span = Span._readable_span
2732

28-
def sentry_patched_readable_span(self: Span) -> ReadableSpan:
29-
readable_span = old_readable_span(self)
30-
readable_span._sentry_meta = getattr(self, "_sentry_meta", {}) # type: ignore[attr-defined]
31-
return readable_span
33+
def sentry_patched_readable_span(self: Span) -> ReadableSpan:
34+
readable_span = old_readable_span(self)
35+
readable_span._sentry_meta = getattr(self, "_sentry_meta", {}) # type: ignore[attr-defined]
36+
return readable_span
3237

33-
Span._readable_span = sentry_patched_readable_span # type: ignore[method-assign]
38+
Span._readable_span = sentry_patched_readable_span # type: ignore[method-assign]
39+
READABLE_SPAN_PATCHED = True
3440

3541

3642
def setup_sentry_tracing() -> None:

0 commit comments

Comments
 (0)