Skip to content

Commit 846a736

Browse files
committed
Record number of dropped spans
1 parent eb93c1f commit 846a736

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

sentry_sdk/integrations/opentelemetry/span_processor.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from opentelemetry.sdk.trace import Span, ReadableSpan, SpanProcessor
1313

1414
import sentry_sdk
15+
from sentry_sdk._types import AnnotatedValue
1516
from sentry_sdk.consts import SPANDATA
1617
from sentry_sdk.tracing import DEFAULT_SPAN_ORIGIN
1718
from sentry_sdk.utils import get_current_thread_meta
@@ -63,6 +64,7 @@ def __init__(self):
6364
self._children_spans = defaultdict(
6465
list
6566
) # type: DefaultDict[int, List[ReadableSpan]]
67+
self._dropped_spans = defaultdict(lambda: 0)
6668

6769
def on_start(self, span, parent_context=None):
6870
# type: (Span, Optional[Context]) -> None
@@ -148,7 +150,17 @@ def _flush_root_span(self, span):
148150
span_json = self._span_to_json(child)
149151
if span_json:
150152
spans.append(span_json)
151-
transaction_event["spans"] = spans
153+
154+
dropped_spans = 0
155+
if span in self._dropped_spans:
156+
dropped_spans = self._dropped_spans.pop(span)
157+
158+
if dropped_spans == 0:
159+
transaction_event["spans"] = spans
160+
else:
161+
transaction_event["spans"] = AnnotatedValue(
162+
spans, {"len": len(spans) + dropped_spans}
163+
)
152164
# TODO-neel-potel sort and cutoff max spans
153165

154166
sentry_sdk.capture_event(transaction_event)
@@ -166,6 +178,8 @@ def _append_child_span(self, span):
166178
children_spans = self._children_spans[span.parent.span_id]
167179
if len(children_spans) < max_spans:
168180
children_spans.append(span)
181+
else:
182+
self._dropped_spans[span.parent.span_id] += 1
169183

170184
def _collect_children(self, span):
171185
# type: (ReadableSpan) -> List[ReadableSpan]

0 commit comments

Comments
 (0)