Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a7990ad
ref(openai): Separate input handling to improve typing
alexander-alderman-webb Jan 21, 2026
c6ebc0f
remove old func
alexander-alderman-webb Jan 21, 2026
8d9fa37
.
alexander-alderman-webb Jan 21, 2026
ab41f1e
expand type
alexander-alderman-webb Jan 21, 2026
b3117ac
add ignores
alexander-alderman-webb Jan 21, 2026
847d4b2
revert unrelated change
alexander-alderman-webb Jan 21, 2026
4f25a56
feat(openai): Set system instruction attribute
alexander-alderman-webb Jan 21, 2026
903bbbd
use union
alexander-alderman-webb Jan 21, 2026
f304bec
mypy
alexander-alderman-webb Jan 21, 2026
921a82f
Merge branch 'webb/openai-separate-input-handling' into webb/openai-a…
alexander-alderman-webb Jan 21, 2026
9f5d801
.
alexander-alderman-webb Jan 21, 2026
d66ffe1
use specific openai types
alexander-alderman-webb Jan 21, 2026
ac3ce00
wip
alexander-alderman-webb Jan 22, 2026
ef9fe6f
.
alexander-alderman-webb Jan 22, 2026
ce84a29
.
alexander-alderman-webb Jan 22, 2026
dee9930
remove test
alexander-alderman-webb Jan 22, 2026
cb00ab3
.
alexander-alderman-webb Jan 22, 2026
26b932b
.
alexander-alderman-webb Jan 22, 2026
04dc92c
.
alexander-alderman-webb Jan 22, 2026
c7263ea
edge case
alexander-alderman-webb Jan 22, 2026
d947899
full responses api tests
alexander-alderman-webb Jan 22, 2026
8cbeac1
remove sentry_sdk/ai/_openai_completions_api.py
alexander-alderman-webb Jan 22, 2026
bcebcc8
fix test
alexander-alderman-webb Jan 22, 2026
f749ae4
Merge branch 'master' into webb/openai-separate-input-handling
alexander-alderman-webb Jan 23, 2026
87dd8fe
Merge branch 'webb/openai-separate-input-handling' into webb/openai-a…
alexander-alderman-webb Jan 23, 2026
085b496
feat(openai-agents): Set system instruction attribute on gen_ai.chat …
alexander-alderman-webb Jan 23, 2026
48c7fbe
add type ignores
alexander-alderman-webb Jan 23, 2026
3f5ad11
more defensive checks in case input is not iterable
alexander-alderman-webb Jan 23, 2026
ebf2d9c
merge
alexander-alderman-webb Jan 23, 2026
fc9f1fa
pick up changes to extraction functions
alexander-alderman-webb Jan 23, 2026
bcdd87c
fix func name
alexander-alderman-webb Jan 23, 2026
68b853f
fix Iterable import
alexander-alderman-webb Jan 23, 2026
5ee5274
remove runtime import
alexander-alderman-webb Jan 23, 2026
a8840d5
more early returns
alexander-alderman-webb Jan 26, 2026
382e933
revert unrelated tests
alexander-alderman-webb Jan 26, 2026
179d59e
revert unrelated change
alexander-alderman-webb Jan 26, 2026
12cb219
address comment
alexander-alderman-webb Jan 26, 2026
a6152fe
remove unused type ignore
alexander-alderman-webb Jan 26, 2026
74b5a4c
merge
alexander-alderman-webb Jan 26, 2026
f8ac8d8
ref: Replace set_data_noramlized with Span.set_data for system instru…
alexander-alderman-webb Jan 26, 2026
9f89d53
add json.dumps()
alexander-alderman-webb Jan 26, 2026
2c84e54
.
alexander-alderman-webb Jan 26, 2026
eda980c
fix typo in filename
alexander-alderman-webb Jan 26, 2026
6f668d9
Merge branch 'webb/openai-agents-chat-system-instructions' into webb/…
alexander-alderman-webb Jan 26, 2026
1640d7d
merge master
alexander-alderman-webb Jan 28, 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
7 changes: 3 additions & 4 deletions sentry_sdk/integrations/anthropic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import json
from collections.abc import Iterable
from functools import wraps
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -217,11 +218,9 @@ def _set_input_data(
if isinstance(system_instructions, str) or isinstance(
system_instructions, Iterable
):
set_data_normalized(
span,
span.set_data(
SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS,
_transform_system_instructions(system_instructions),
unpack=False,
json.dumps(_transform_system_instructions(system_instructions)),
)

normalized_messages = []
Expand Down
7 changes: 3 additions & 4 deletions sentry_sdk/integrations/google_genai/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
import json
import inspect
from functools import wraps
from .consts import ORIGIN, TOOL_ATTRIBUTES_MAP, GEN_AI_SYSTEM
Expand Down Expand Up @@ -808,11 +809,9 @@ def set_span_data_for_request(
system_instructions = config.get("system_instruction")

if system_instructions is not None:
set_data_normalized(
Copy link
Member

@sl0thentr0py sl0thentr0py Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i generally dislike this function, garbage signature, just creates clutter

span,
span.set_data(
SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS,
_transform_system_instructions(system_instructions),
unpack=False,
json.dumps(_transform_system_instructions(system_instructions)),
)

# Extract messages from contents
Expand Down
7 changes: 3 additions & 4 deletions sentry_sdk/integrations/langchain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import contextvars
import itertools
import sys
import json
import warnings
from collections import OrderedDict
from functools import wraps
Expand Down Expand Up @@ -467,11 +468,9 @@ def on_chat_model_start(
if should_send_default_pii() and self.include_prompts:
system_instructions = _get_system_instructions(messages)
if len(system_instructions) > 0:
set_data_normalized(
span,
span.set_data(
SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS,
_transform_system_instructions(system_instructions),
unpack=False,
json.dumps(_transform_system_instructions(system_instructions)),
)

normalized_messages = []
Expand Down
31 changes: 14 additions & 17 deletions sentry_sdk/integrations/openai.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import json
import time
from functools import wraps
from collections.abc import Iterable
Expand Down Expand Up @@ -273,16 +274,16 @@ def _set_responses_api_input_data(
and explicit_instructions is not None
and _is_given(explicit_instructions)
):
set_data_normalized(
span,
span.set_data(
SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS,
[
{
"type": "text",
"content": explicit_instructions,
}
],
unpack=False,
json.dumps(
[
{
"type": "text",
"content": explicit_instructions,
}
]
),
)

set_data_normalized(span, SPANDATA.GEN_AI_OPERATION_NAME, "responses")
Expand All @@ -309,11 +310,9 @@ def _set_responses_api_input_data(
instructions_text_parts += _transform_system_instructions(system_instructions)

if len(instructions_text_parts) > 0:
set_data_normalized(
span,
span.set_data(
SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS,
instructions_text_parts,
unpack=False,
json.dumps(instructions_text_parts),
)

if isinstance(messages, str):
Expand Down Expand Up @@ -365,11 +364,9 @@ def _set_completions_api_input_data(

system_instructions = _get_system_instructions_completions(messages)
if len(system_instructions) > 0:
set_data_normalized(
span,
span.set_data(
SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS,
_transform_system_instructions(system_instructions),
unpack=False,
json.dumps(_transform_system_instructions(system_instructions)),
)

if isinstance(messages, str):
Expand Down
8 changes: 4 additions & 4 deletions sentry_sdk/integrations/openai_agents/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

import sentry_sdk
from sentry_sdk.ai.utils import (
GEN_AI_ALLOWED_MESSAGE_ROLES,
Expand Down Expand Up @@ -146,11 +148,9 @@ def _set_input_data(
instructions_text_parts += _transform_system_instructions(system_instructions)

if len(instructions_text_parts) > 0:
set_data_normalized(
span,
span.set_data(
SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS,
instructions_text_parts,
unpack=False,
json.dumps(instructions_text_parts),
)

non_system_messages = [
Expand Down
12 changes: 7 additions & 5 deletions sentry_sdk/integrations/pydantic_ai/spans/ai_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

import sentry_sdk
from sentry_sdk._types import BLOB_DATA_SUBSTITUTE
from sentry_sdk.ai.utils import (
Expand Down Expand Up @@ -101,13 +103,13 @@ def _set_input_messages(span: "sentry_sdk.tracing.Span", messages: "Any") -> Non

permanent_instructions, current_instructions = _get_system_instructions(messages)
if len(permanent_instructions) > 0 or len(current_instructions) > 0:
set_data_normalized(
span,
span.set_data(
SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS,
_transform_system_instructions(
permanent_instructions, current_instructions
json.dumps(
_transform_system_instructions(
permanent_instructions, current_instructions
)
),
unpack=False,
)

try:
Expand Down
Loading