Skip to content

Commit 846b8b2

Browse files
authored
fix(langchain): handle case when parent span wasn't traced (#3656)
It's possible for the parent span to not have been traced (or have been GCd) so a KeyError would be raised when trying to fetch the span for the parent run_id. Now we defensively `.get()` the parent span instead of subscripting it.
1 parent 8a7e226 commit 846b8b2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

sentry_sdk/integrations/langchain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def _create_span(self, run_id, parent_id, **kwargs):
138138

139139
watched_span = None # type: Optional[WatchedSpan]
140140
if parent_id:
141-
parent_span = self.span_map[parent_id] # type: Optional[WatchedSpan]
141+
parent_span = self.span_map.get(parent_id) # type: Optional[WatchedSpan]
142142
if parent_span:
143143
watched_span = WatchedSpan(parent_span.span.start_child(**kwargs))
144144
parent_span.children.append(watched_span)

0 commit comments

Comments
 (0)