12
12
from opentelemetry .sdk .trace import Span , ReadableSpan , SpanProcessor
13
13
14
14
import sentry_sdk
15
+ from sentry_sdk ._types import AnnotatedValue
15
16
from sentry_sdk .consts import SPANDATA
16
17
from sentry_sdk .tracing import DEFAULT_SPAN_ORIGIN
17
18
from sentry_sdk .utils import get_current_thread_meta
@@ -63,6 +64,7 @@ def __init__(self):
63
64
self ._children_spans = defaultdict (
64
65
list
65
66
) # type: DefaultDict[int, List[ReadableSpan]]
67
+ self ._dropped_spans = defaultdict (lambda : 0 )
66
68
67
69
def on_start (self , span , parent_context = None ):
68
70
# type: (Span, Optional[Context]) -> None
@@ -148,7 +150,17 @@ def _flush_root_span(self, span):
148
150
span_json = self ._span_to_json (child )
149
151
if span_json :
150
152
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
+ )
152
164
# TODO-neel-potel sort and cutoff max spans
153
165
154
166
sentry_sdk .capture_event (transaction_event )
@@ -166,6 +178,8 @@ def _append_child_span(self, span):
166
178
children_spans = self ._children_spans [span .parent .span_id ]
167
179
if len (children_spans ) < max_spans :
168
180
children_spans .append (span )
181
+ else :
182
+ self ._dropped_spans [span .parent .span_id ] += 1
169
183
170
184
def _collect_children (self , span ):
171
185
# type: (ReadableSpan) -> List[ReadableSpan]
0 commit comments