Skip to content

Commit a626201

Browse files
committed
defaultdict
1 parent 2e2e5b9 commit a626201

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

sentry_sdk/integrations/opentelemetry/potel_span_processor.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections import deque
1+
from collections import deque, defaultdict
22

33
from opentelemetry.trace import format_trace_id, format_span_id
44
from opentelemetry.context import Context
@@ -17,7 +17,7 @@
1717
from sentry_sdk._types import TYPE_CHECKING
1818

1919
if TYPE_CHECKING:
20-
from typing import Optional, List, Any, Deque
20+
from typing import Optional, List, Any, Deque, DefaultDict
2121
from sentry_sdk._types import Event
2222

2323

@@ -35,7 +35,9 @@ def __new__(cls):
3535

3636
def __init__(self):
3737
# type: () -> None
38-
self._children_spans = {} # type: dict[int, List[ReadableSpan]]
38+
self._children_spans = defaultdict(
39+
list
40+
) # type: DefaultDict[int, List[ReadableSpan]]
3941

4042
def on_start(self, span, parent_context=None):
4143
# type: (Span, Optional[Context]) -> None
@@ -48,7 +50,7 @@ def on_end(self, span):
4850

4951
# TODO-neel-potel-remote only take parent if not remote
5052
if span.parent:
51-
self._children_spans.setdefault(span.parent.span_id, []).append(span)
53+
self._children_spans[span.parent.span_id].append(span)
5254
else:
5355
# if have a root span ending, we build a transaction and send it
5456
self._flush_root_span(span)
@@ -75,7 +77,7 @@ def _flush_root_span(self, span):
7577
span_json = self._span_to_json(child)
7678
if span_json:
7779
spans.append(span_json)
78-
transaction_event.setdefault("spans", []).extend(spans)
80+
transaction_event["spans"] = spans
7981
# TODO-neel-potel sort and cutoff max spans
8082

8183
capture_event(transaction_event)

0 commit comments

Comments
 (0)