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
27 changes: 13 additions & 14 deletions sentry_sdk/integrations/cohere.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@

import sentry_sdk
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.utils import (
capture_internal_exceptions,
event_from_exception,
has_data_collection_enabled,
parse_version,
reraise,
)
Expand Down Expand Up @@ -90,14 +88,6 @@ def setup_once() -> None:
BaseCohere.chat_stream = _wrap_chat(BaseCohere.chat_stream, streaming=True)


def _should_record(category: str) -> bool:
client = sentry_sdk.get_client()
if has_data_collection_enabled(client.options):
return bool(client.options["data_collection"]["gen_ai"][category])

return should_send_default_pii()


def _capture_exception(exc: "Any") -> None:
event, hint = event_from_exception(
exc,
Expand Down Expand Up @@ -177,7 +167,7 @@ def new_chat(*args: "Any", **kwargs: "Any") -> "Any":
reraise(*exc_info)

with capture_internal_exceptions():
if _should_record("inputs"):
if sentry_sdk.get_client().options["data_collection"]["gen_ai"]["inputs"]:
set_data_normalized(
span,
SPANDATA.AI_INPUT_MESSAGES,
Expand Down Expand Up @@ -213,7 +203,9 @@ def new_iterator() -> "Iterator[StreamedChatResponse]":
collect_chat_response_fields(
span,
x.response,
include_pii=_should_record("outputs"),
include_pii=sentry_sdk.get_client().options[
"data_collection"
]["gen_ai"]["outputs"],
)
yield x
span.end()
Expand All @@ -223,7 +215,9 @@ def new_iterator() -> "Iterator[StreamedChatResponse]":
collect_chat_response_fields(
span,
res,
include_pii=_should_record("outputs"),
include_pii=sentry_sdk.get_client().options["data_collection"][
"gen_ai"
]["outputs"],
)
span.end()
else:
Expand All @@ -248,7 +242,12 @@ def new_embed(*args: "Any", **kwargs: "Any") -> "Any":
"sentry.origin": CohereIntegration.origin,
},
) as span:
if "texts" in kwargs and _should_record("inputs"):
if (
"texts" in kwargs
and sentry_sdk.get_client().options["data_collection"]["gen_ai"][
"inputs"
]
):
if isinstance(kwargs["texts"], str):
set_data_normalized(span, SPANDATA.AI_TEXTS, [kwargs["texts"]])
elif (
Expand Down
Loading
Loading