Skip to content

Commit d8afe93

Browse files
merge
2 parents 582566b + 9649022 commit d8afe93

45 files changed

Lines changed: 1078 additions & 1860 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎MIGRATION_GUIDE.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
115115
- Dropped support for PySpark below 3.0.
116116
- Dropped support for redis-py below 4.2.
117117
- Dropped support for Pydantic AI below 1.76.
118+
- Dropped support for OpenAI Agents below 0.10.3.
118119
- Removed the RedisIntegration `max_data_size` option.
119120
- Removed the possibility to supply a specific client to the LaunchDarklyIntegration.
120121
- The `enable_tracing` option was removed. Use `traces_sample_rate=1.0` instead.

‎scripts/populate_tox/package_dependencies.jsonl‎

Lines changed: 20 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎scripts/populate_tox/releases.jsonl‎

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎sentry_sdk/ai/monitoring.py‎

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
from typing import TYPE_CHECKING
22

3-
from sentry_sdk.ai.utils import _set_span_data_attribute
43
from sentry_sdk.consts import SPANDATA
5-
from sentry_sdk.traces import StreamedSpan
6-
from sentry_sdk.tracing import Span
74

85
if TYPE_CHECKING:
96
from typing import Any, Awaitable, Callable, Optional, TypeVar, Union
107

8+
from sentry_sdk.traces import StreamedSpan
9+
1110
F = TypeVar("F", bound=Union[Callable[..., Any], Callable[..., Awaitable[Any]]])
1211

1312

1413
def record_token_usage(
15-
span: "Union[Span, StreamedSpan]",
14+
span: "StreamedSpan",
1615
input_tokens: "Optional[int]" = None,
1716
input_tokens_cached: "Optional[int]" = None,
1817
input_tokens_cache_write: "Optional[int]" = None,
@@ -21,30 +20,25 @@ def record_token_usage(
2120
total_tokens: "Optional[int]" = None,
2221
) -> None:
2322
if input_tokens is not None:
24-
_set_span_data_attribute(span, SPANDATA.GEN_AI_USAGE_INPUT_TOKENS, input_tokens)
23+
span.set_attribute(SPANDATA.GEN_AI_USAGE_INPUT_TOKENS, input_tokens)
2524

2625
if input_tokens_cached is not None:
27-
_set_span_data_attribute(
28-
span,
26+
span.set_attribute(
2927
SPANDATA.GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS,
3028
input_tokens_cached,
3129
)
3230

3331
if input_tokens_cache_write is not None:
34-
_set_span_data_attribute(
35-
span,
32+
span.set_attribute(
3633
SPANDATA.GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS,
3734
input_tokens_cache_write,
3835
)
3936

4037
if output_tokens is not None:
41-
_set_span_data_attribute(
42-
span, SPANDATA.GEN_AI_USAGE_OUTPUT_TOKENS, output_tokens
43-
)
38+
span.set_attribute(SPANDATA.GEN_AI_USAGE_OUTPUT_TOKENS, output_tokens)
4439

4540
if output_tokens_reasoning is not None:
46-
_set_span_data_attribute(
47-
span,
41+
span.set_attribute(
4842
SPANDATA.GEN_AI_USAGE_REASONING_OUTPUT_TOKENS,
4943
output_tokens_reasoning,
5044
)
@@ -53,4 +47,4 @@ def record_token_usage(
5347
total_tokens = input_tokens + output_tokens
5448

5549
if total_tokens is not None:
56-
_set_span_data_attribute(span, SPANDATA.GEN_AI_USAGE_TOTAL_TOKENS, total_tokens)
50+
span.set_attribute(SPANDATA.GEN_AI_USAGE_TOTAL_TOKENS, total_tokens)

‎sentry_sdk/ai/utils.py‎

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
from typing import TYPE_CHECKING
44

55
if TYPE_CHECKING:
6-
from typing import Any, Dict, Optional, Tuple, Union
6+
from typing import Any, Dict, Optional, Tuple
77

8-
from sentry_sdk.tracing import Span
8+
from sentry_sdk.traces import StreamedSpan
99

1010
import sentry_sdk
11-
from sentry_sdk.traces import StreamedSpan
1211
from sentry_sdk.utils import logger
1312

1413

@@ -449,25 +448,16 @@ def _normalize_data(data: "Any", unpack: bool = True) -> "Any":
449448

450449

451450
def set_data_normalized(
452-
span: "Union[Span, StreamedSpan]",
451+
span: "StreamedSpan",
453452
key: str,
454453
value: "Any",
455454
unpack: bool = True,
456455
) -> None:
457456
normalized = _normalize_data(value, unpack=unpack)
458457
if isinstance(normalized, (int, float, bool, str)):
459-
_set_span_data_attribute(span, key, normalized)
458+
span.set_attribute(key, normalized)
460459
else:
461-
_set_span_data_attribute(span, key, json.dumps(normalized))
462-
463-
464-
def _set_span_data_attribute(
465-
span: "Union[Span, StreamedSpan]", key: str, value: "Any"
466-
) -> None:
467-
if isinstance(span, StreamedSpan):
468-
span.set_attribute(key, value)
469-
else:
470-
span.set_data(key, value)
460+
span.set_attribute(key, json.dumps(normalized))
471461

472462

473463
def normalize_message_role(role: str) -> str:

‎sentry_sdk/consts.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,12 @@ class SPANDATA:
593593
Example: [{"role": "assistant", "parts": [{"type": "text", "content": "The weather in Paris is currently rainy with a temperature of 57°F."}], "finish_reason": "stop"}]
594594
"""
595595

596+
GEN_AI_RESPONSE_TIME_TO_FIRST_CHUNK = "gen_ai.response.time_to_first_chunk"
597+
"""
598+
Time in seconds when the first response content chunk arrived in streaming responses.
599+
Example: 0.6853435
600+
"""
601+
596602
GEN_AI_RESPONSE_TIME_TO_FIRST_TOKEN = "gen_ai.response.time_to_first_token"
597603
"""
598604
The time it took to receive the first token from the model.

‎sentry_sdk/integrations/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def iter_default_integrations(
155155
"loguru": (0, 7, 0),
156156
"mcp": (1, 15, 0),
157157
"openai": (1, 0, 0),
158-
"openai_agents": (0, 0, 19),
158+
"openai_agents": (0, 10, 3),
159159
"openfeature": (0, 7, 1),
160160
"pydantic_ai": (1, 76, 0),
161161
"pymongo": (3, 5, 0),

‎sentry_sdk/integrations/aiohttp.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
from aiohttp.web_urldispatcher import UrlMappingMatchInfo
7474

7575
from sentry_sdk._types import Attributes, Event, EventProcessor
76-
from sentry_sdk.tracing import Span
7776
from sentry_sdk.utils import ExcInfo
7877

7978

@@ -343,7 +342,7 @@ async def on_request_start(
343342
parsed_url.url if parsed_url else SENSITIVE_DATA_SUBSTITUTE,
344343
)
345344

346-
span: "Union[Span, StreamedSpan, None]" = None
345+
span: "Optional[StreamedSpan]" = None
347346
attributes: "Attributes" = {
348347
"sentry.op": OP.HTTP_CLIENT,
349348
"sentry.origin": AioHttpIntegration.origin,

‎sentry_sdk/integrations/aiomysql.py‎

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -241,32 +241,21 @@ def _get_connect_data(conn: Any, *, use_streaming_keys: bool = False) -> dict[st
241241

242242
def _set_db_data(span: Any, conn: Any) -> None:
243243
"""Set database-related span data from connection object."""
244-
if isinstance(span, StreamedSpan):
245-
set_value = span.set_attribute
246-
db_system = SPANDATA.DB_SYSTEM_NAME
247-
db_name = SPANDATA.DB_NAMESPACE
248-
else:
249-
# Remove this else block once we've completely migrated to streamed spans
250-
# The use of deprecated attributes here is to ensure backwards compatibility
251-
set_value = span.set_data
252-
db_system = SPANDATA.DB_SYSTEM
253-
db_name = SPANDATA.DB_NAME
254-
255-
set_value(db_system, "mysql")
256-
set_value(SPANDATA.DB_DRIVER_NAME, "aiomysql")
244+
span.set_attribute(SPANDATA.DB_SYSTEM_NAME, "mysql")
245+
span.set_attribute(SPANDATA.DB_DRIVER_NAME, "aiomysql")
257246

258247
host = getattr(conn, "host", None)
259248
if host is not None:
260-
set_value(SPANDATA.SERVER_ADDRESS, host)
249+
span.set_attribute(SPANDATA.SERVER_ADDRESS, host)
261250

262251
port = getattr(conn, "port", None)
263252
if port is not None:
264-
set_value(SPANDATA.SERVER_PORT, port)
253+
span.set_attribute(SPANDATA.SERVER_PORT, port)
265254

266255
database = getattr(conn, "db", None)
267256
if database is not None:
268-
set_value(db_name, database)
257+
span.set_attribute(SPANDATA.DB_NAMESPACE, database)
269258

270259
user = getattr(conn, "user", None)
271260
if user is not None:
272-
set_value(SPANDATA.DB_USER, user)
261+
span.set_attribute(SPANDATA.DB_USER, user)

‎sentry_sdk/integrations/anthropic.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ def _set_common_input_data(
455455
"""
456456
Set input data for the span based on the provided keyword arguments for the anthropic message creation.
457457
"""
458-
span.set_attribute(SPANDATA.GEN_AI_SYSTEM, "anthropic")
458+
span.set_attribute(SPANDATA.GEN_AI_PROVIDER_NAME, "anthropic")
459459
span.set_attribute(SPANDATA.GEN_AI_OPERATION_NAME, "chat")
460460

461461
if max_tokens is not None and _is_given(max_tokens):

0 commit comments

Comments
 (0)