Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions sentry_sdk/integrations/langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,6 @@ class LangchainIntegration(Integration):

_ignored_exceptions: "set[type[Exception]]" = set()

def __init__(
self: "LangchainIntegration",
include_prompts: bool = True,
) -> None:
self.include_prompts = include_prompts

@staticmethod
def setup_once() -> None:
version = parse_version(LANGCHAIN_VERSION)
Expand All @@ -210,9 +204,8 @@ def _capture_exception(exc: "Any", scope: "Optional[Any]" = None) -> None:
class SentryLangchainCallback(BaseCallbackHandler):
"""Callback handler that creates Sentry spans."""

def __init__(self, include_prompts: bool) -> None:
def __init__(self) -> None:
self.span_map: "OrderedDict[UUID, Union[Span, _AgentFrameworkChatGenerationContext]]" = OrderedDict()
self.include_prompts = include_prompts

def _handle_error(self, run_id: "UUID", error: "Any") -> None:
is_ignored = isinstance(error, tuple(LangchainIntegration._ignored_exceptions))
Expand Down Expand Up @@ -398,7 +391,7 @@ def on_llm_start(
record_inputs = False
if has_data_collection_enabled(client.options):
record_inputs = client.options["data_collection"]["gen_ai"]["inputs"]
elif should_send_default_pii() and self.include_prompts:
elif should_send_default_pii():
# TODO: Remove this branch once `send_default_pii` is deprecated
record_inputs = True

Expand Down Expand Up @@ -493,7 +486,7 @@ def on_chat_model_start(
record_inputs = False
if has_data_collection_enabled(client.options):
record_inputs = client.options["data_collection"]["gen_ai"]["inputs"]
elif should_send_default_pii() and self.include_prompts:
elif should_send_default_pii():
# TODO: Remove this branch once `send_default_pii` is deprecated
record_inputs = True

Expand Down Expand Up @@ -546,7 +539,7 @@ def on_chat_model_end(
record_outputs = False
if has_data_collection_enabled(client.options):
record_outputs = client.options["data_collection"]["gen_ai"]["outputs"]
elif should_send_default_pii() and self.include_prompts:
elif should_send_default_pii():
# TODO: Remove this branch once `send_default_pii` is deprecated
record_outputs = True

Expand Down Expand Up @@ -584,7 +577,7 @@ def on_llm_end(
record_outputs = False
if has_data_collection_enabled(client.options):
record_outputs = client.options["data_collection"]["gen_ai"]["outputs"]
elif should_send_default_pii() and self.include_prompts:
elif should_send_default_pii():
# TODO: Remove this branch once `send_default_pii` is deprecated
record_outputs = True

Expand Down Expand Up @@ -694,7 +687,7 @@ def on_tool_start(
record_inputs = False
if has_data_collection_enabled(client.options):
record_inputs = client.options["data_collection"]["gen_ai"]["inputs"]
elif should_send_default_pii() and self.include_prompts:
elif should_send_default_pii():
# TODO: Remove this branch once `send_default_pii` is deprecated
record_inputs = True

Expand Down Expand Up @@ -725,7 +718,7 @@ def on_tool_end(
record_outputs = False
if has_data_collection_enabled(client.options):
record_outputs = client.options["data_collection"]["gen_ai"]["outputs"]
elif should_send_default_pii() and self.include_prompts:
elif should_send_default_pii():
# TODO: Remove this branch once `send_default_pii` is deprecated
record_outputs = True

Expand Down Expand Up @@ -1078,9 +1071,7 @@ def new_configure(
isinstance(cb, SentryLangchainCallback)
for cb in itertools.chain(callbacks_list, inheritable_callbacks_list)
):
sentry_handler = SentryLangchainCallback(
integration.include_prompts,
)
sentry_handler = SentryLangchainCallback()
if isinstance(local_callbacks, BaseCallbackManager):
local_callbacks = local_callbacks.copy()
local_callbacks.handlers = [
Expand Down Expand Up @@ -1118,7 +1109,7 @@ def new_invoke(self: "Any", *args: "Any", **kwargs: "Any") -> "Any":
if has_data_collection_enabled(client.options):
record_inputs = client.options["data_collection"]["gen_ai"]["inputs"]
record_outputs = client.options["data_collection"]["gen_ai"]["outputs"]
elif should_send_default_pii() and integration.include_prompts:
elif should_send_default_pii():
# TODO: Remove this branch once `send_default_pii` is deprecated
record_inputs = True
record_outputs = True
Expand Down Expand Up @@ -1172,7 +1163,7 @@ def new_stream(self: "Any", *args: "Any", **kwargs: "Any") -> "Any":
if has_data_collection_enabled(client.options):
record_inputs = client.options["data_collection"]["gen_ai"]["inputs"]
record_outputs = client.options["data_collection"]["gen_ai"]["outputs"]
elif should_send_default_pii() and integration.include_prompts:
elif should_send_default_pii():
# TODO: Remove this branch once `send_default_pii` is deprecated
record_inputs = True
record_outputs = True
Expand Down
Loading
Loading