@@ -63,6 +63,7 @@ def __init__(self):
63
63
self ._children_spans = defaultdict (
64
64
list
65
65
) # type: DefaultDict[int, List[ReadableSpan]]
66
+ self ._dropped_spans = defaultdict (lambda : 0 ) # type: DefaultDict[int, int]
66
67
67
68
def on_start (self , span , parent_context = None ):
68
69
# type: (Span, Optional[Context]) -> None
@@ -143,12 +144,17 @@ def _flush_root_span(self, span):
143
144
if not transaction_event :
144
145
return
145
146
147
+ collected_spans , dropped_spans = self ._collect_children (span )
146
148
spans = []
147
- for child in self . _collect_children ( span ) :
149
+ for child in collected_spans :
148
150
span_json = self ._span_to_json (child )
149
151
if span_json :
150
152
spans .append (span_json )
153
+
151
154
transaction_event ["spans" ] = spans
155
+ if dropped_spans > 0 :
156
+ transaction_event ["_dropped_spans" ] = dropped_spans
157
+
152
158
# TODO-neel-potel sort and cutoff max spans
153
159
154
160
sentry_sdk .capture_event (transaction_event )
@@ -166,25 +172,29 @@ def _append_child_span(self, span):
166
172
children_spans = self ._children_spans [span .parent .span_id ]
167
173
if len (children_spans ) < max_spans :
168
174
children_spans .append (span )
175
+ else :
176
+ self ._dropped_spans [span .parent .span_id ] += 1
169
177
170
178
def _collect_children (self , span ):
171
- # type: (ReadableSpan) -> List[ReadableSpan]
179
+ # type: (ReadableSpan) -> tuple[ List[ReadableSpan], int ]
172
180
if not span .context :
173
- return []
181
+ return [], 0
174
182
175
183
children = []
184
+ dropped_spans = 0
176
185
bfs_queue = deque () # type: Deque[int]
177
186
bfs_queue .append (span .context .span_id )
178
187
179
188
while bfs_queue :
180
189
parent_span_id = bfs_queue .popleft ()
181
190
node_children = self ._children_spans .pop (parent_span_id , [])
191
+ dropped_spans += self ._dropped_spans .pop (parent_span_id , 0 )
182
192
children .extend (node_children )
183
193
bfs_queue .extend (
184
194
[child .context .span_id for child in node_children if child .context ]
185
195
)
186
196
187
- return children
197
+ return children , dropped_spans
188
198
189
199
# we construct the event from scratch here
190
200
# and not use the current Transaction class for easier refactoring
0 commit comments