Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1f32952
fix(ai): redact message parts content of type blob
constantinius Dec 17, 2025
795bcea
fix(ai): skip non dict messages
constantinius Dec 17, 2025
a623e13
fix(ai): typing
constantinius Dec 17, 2025
3d3ce5b
fix(ai): content items may not be dicts
constantinius Dec 17, 2025
433bc88
fix(integrations): google-genai: reworked `gen_ai.request.messages` e…
constantinius Jan 5, 2026
4244319
fix(integrations): address cursor review comments
constantinius Jan 8, 2026
f72aa45
fix(integrations): ensure file_data returns valid blob structure only…
constantinius Jan 8, 2026
2be0419
fix(integrations): add type ignore for missing PIL.Image import
constantinius Jan 8, 2026
4abdcf8
Merge branch 'master' into constantinius/fix/integrations/google-gena…
constantinius Jan 13, 2026
86f6ecb
fix: linting issue and review comment
constantinius Jan 13, 2026
7e9335e
Merge branch 'master' into constantinius/fix/integrations/google-gena…
constantinius Jan 14, 2026
0355c63
fix(integrations): google-genai do not encode binary data that gets r…
constantinius Jan 14, 2026
910c679
fix(integrations): Use explicit None checks instead of `or {}` pattern
constantinius Jan 14, 2026
bd78165
feat(ai): Add shared content transformation functions for multimodal …
constantinius Jan 15, 2026
e7eb226
Merge shared content transformation functions
constantinius Jan 15, 2026
fc6bbfe
refactor(google-genai): Use shared transform_content_part for dict fo…
constantinius Jan 15, 2026
412b93e
refactor(ai): split transform_content_part into SDK-specific functions
constantinius Jan 15, 2026
ff7247b
Merge SDK-specific transform functions
constantinius Jan 15, 2026
b9b629e
refactor(google-genai): use transform_google_content_part directly
constantinius Jan 15, 2026
b80f6e9
test: added comprehensive tests for direct API access with various ki…
constantinius Jan 16, 2026
37b1761
fix: modality and tpe for file references
constantinius Jan 19, 2026
7d825af
fix: wrong modality and type for file references
constantinius Jan 19, 2026
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
55 changes: 55 additions & 0 deletions sentry_sdk/ai/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from sys import getsizeof
from typing import TYPE_CHECKING

from sentry_sdk._types import SENSITIVE_DATA_SUBSTITUTE

if TYPE_CHECKING:
from typing import Any, Callable, Dict, List, Optional, Tuple

Expand Down Expand Up @@ -141,6 +143,57 @@ def _find_truncation_index(messages: "List[Dict[str, Any]]", max_bytes: int) ->
return 0


def redact_blob_message_parts(
messages: "List[Dict[str, Any]]",
) -> "List[Dict[str, Any]]":
"""
Redact blob message parts from the messages, by removing the "content" key.
e.g:
{
"role": "user",
"content": [
{
"text": "How many ponies do you see in the image?",
"type": "text"
},
{
"type": "blob",
"modality": "image",
"mime_type": "image/jpeg",
"content": "data:image/jpeg;base64,..."
}
]
}
becomes:
{
"role": "user",
"content": [
{
"text": "How many ponies do you see in the image?",
"type": "text"
},
{
"type": "blob",
"modality": "image",
"mime_type": "image/jpeg",
"content": "[Filtered]"
}
]
}
"""

for message in messages:
if not isinstance(message, dict):
continue

content = message.get("content")
if isinstance(content, list):
for item in content:
if isinstance(item, dict) and item.get("type") == "blob":
item["content"] = SENSITIVE_DATA_SUBSTITUTE
return messages


def truncate_messages_by_size(
messages: "List[Dict[str, Any]]",
max_bytes: int = MAX_GEN_AI_MESSAGE_BYTES,
Expand Down Expand Up @@ -186,6 +239,8 @@ def truncate_and_annotate_messages(
if not messages:
return None

messages = redact_blob_message_parts(messages)

truncated_messages, removed_count = truncate_messages_by_size(messages, max_bytes)
if removed_count > 0:
scope._gen_ai_original_message_count[span.span_id] = len(messages)
Expand Down
Loading
Loading