Skip to content

Commit

Permalink
fix(langchain): handle case when parent span wasn't traced (#3656)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rbasoalto authored Oct 15, 2024
1 parent 8a7e226 commit 846b8b2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _create_span(self, run_id, parent_id, **kwargs):

watched_span = None # type: Optional[WatchedSpan]
if parent_id:
parent_span = self.span_map[parent_id] # type: Optional[WatchedSpan]
parent_span = self.span_map.get(parent_id) # type: Optional[WatchedSpan]
if parent_span:
watched_span = WatchedSpan(parent_span.span.start_child(**kwargs))
parent_span.children.append(watched_span)
Expand Down

0 comments on commit 846b8b2

Please sign in to comment.