diff --git a/sentry_sdk/integrations/langchain.py b/sentry_sdk/integrations/langchain.py index 11cf82c000..431fc46bec 100644 --- a/sentry_sdk/integrations/langchain.py +++ b/sentry_sdk/integrations/langchain.py @@ -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)