Skip to content

Commit 6d4c89b

Browse files
committed
fix type issues
1 parent b4dcfc7 commit 6d4c89b

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

sentry_sdk/ai/utils.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
if TYPE_CHECKING:
1515
from typing import Any, Dict, List, Optional
1616

17-
from sentry_sdk._types import AnnotatedValue
18-
from sentry_sdk.serializer import serialize
19-
2017
MAX_GEN_AI_MESSAGE_BYTES = 20_000 # 20KB
2118

2219

sentry_sdk/client.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -607,30 +607,27 @@ def _prepare_event(
607607
event.get("breadcrumbs", []), {"len": previous_total_breadcrumbs}
608608
)
609609

610-
# Annotate truncated gen_ai messages in spans
611610
if scope is not None and scope._gen_ai_messages_truncated:
612-
spans = event.get("spans", [])
613-
if isinstance(spans, AnnotatedValue):
614-
spans = spans.value
615-
611+
spans = [] # type: List[Dict[str, Any]]
616612
for span in spans:
617613
if isinstance(span, dict):
618614
span_id = span.get("span_id")
619615
if span_id and span_id in scope._gen_ai_messages_truncated:
620616
span_data = span.get("data", {})
621-
original_count = span_data.pop(
622-
"_gen_ai_messages_original_count", None
623-
)
624-
if (
625-
original_count is not None
626-
and SPANDATA.GEN_AI_REQUEST_MESSAGES in span_data
627-
):
628-
span_data[SPANDATA.GEN_AI_REQUEST_MESSAGES] = (
629-
AnnotatedValue(
630-
span_data[SPANDATA.GEN_AI_REQUEST_MESSAGES],
631-
{"len": original_count},
632-
)
617+
if isinstance(span_data, dict):
618+
original_count = span_data.pop(
619+
"_gen_ai_messages_original_count", None
633620
)
621+
if (
622+
original_count is not None
623+
and SPANDATA.GEN_AI_REQUEST_MESSAGES in span_data
624+
):
625+
span_data[SPANDATA.GEN_AI_REQUEST_MESSAGES] = (
626+
AnnotatedValue(
627+
span_data[SPANDATA.GEN_AI_REQUEST_MESSAGES],
628+
{"len": original_count},
629+
)
630+
)
634631

635632
# Postprocess the event here so that annotated types do
636633
# generally not surface in before_send

0 commit comments

Comments
 (0)