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
70 changes: 28 additions & 42 deletions sentry_sdk/integrations/typesafe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import sentry_sdk
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.utils import has_data_collection_enabled

if TYPE_CHECKING:
from typing import (
Expand Down Expand Up @@ -263,26 +261,20 @@ def wrap_system_one(self: "TypeSafeClient", *args: "Any", **kwargs: "Any") -> "A
SPANDATA.GEN_AI_USAGE_OUTPUT_TOKENS, response.usage.output_tokens
)

if (
has_data_collection_enabled(client.options)
and client.options["data_collection"]["gen_ai"]["outputs"]
) or (
not has_data_collection_enabled(client.options)
and should_send_default_pii()
):
span.set_attribute(
SPANDATA.GEN_AI_OUTPUT_MESSAGES,
json.dumps(
[
{
"type": "evaluation",
"answers": _transform_evaluation_answers(
response.answers
),
}
]
),
)
if not client.options["data_collection"]["gen_ai"]["outputs"]:
return response

span.set_attribute(
SPANDATA.GEN_AI_OUTPUT_MESSAGES,
json.dumps(
[
{
"type": "evaluation",
"answers": _transform_evaluation_answers(response.answers),
}
]
),
)

return response

Expand Down Expand Up @@ -353,26 +345,20 @@ async def wrap_system_one_async(
SPANDATA.GEN_AI_USAGE_OUTPUT_TOKENS, response.usage.output_tokens
)

if (
has_data_collection_enabled(client.options)
and client.options["data_collection"]["gen_ai"]["outputs"]
) or (
not has_data_collection_enabled(client.options)
and should_send_default_pii()
):
span.set_attribute(
SPANDATA.GEN_AI_OUTPUT_MESSAGES,
json.dumps(
[
{
"type": "evaluation",
"answers": _transform_evaluation_answers(
response.answers
),
}
]
),
)
if not client.options["data_collection"]["gen_ai"]["outputs"]:
return response

span.set_attribute(
SPANDATA.GEN_AI_OUTPUT_MESSAGES,
json.dumps(
[
{
"type": "evaluation",
"answers": _transform_evaluation_answers(response.answers),
}
]
),
)

return response

Expand Down
14 changes: 12 additions & 2 deletions tests/integrations/typesafe/test_typesafe.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ def test_system_one(sentry_init, capture_items, typesafe_response):
sentry_init(
integrations=[TypeSafeIntegration()],
traces_sample_rate=1.0,
data_collection={},
data_collection={
"gen_ai": {
"inputs": True,
"outputs": True,
}
},
)

client = TypeSafeClient(api_key="z")
Expand Down Expand Up @@ -201,7 +206,12 @@ async def test_system_one_async(sentry_init, capture_items, typesafe_response):
sentry_init(
integrations=[TypeSafeIntegration()],
traces_sample_rate=1.0,
data_collection={},
data_collection={
"gen_ai": {
"inputs": True,
"outputs": True,
}
},
)

client = AsyncTypeSafeClient(api_key="z")
Expand Down
Loading