Skip to content

Commit 62f9e7b

Browse files
authored
Merge branch 'master' into dependabot/github_actions/actions/create-github-app-token-3.0.0
2 parents 042916f + 0b94624 commit 62f9e7b

File tree

18 files changed

+631
-119
lines changed

18 files changed

+631
-119
lines changed

.github/workflows/ai-integration-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
token: ${{ secrets.GITHUB_TOKEN }}
3535

3636
- name: Run Python SDK Tests
37-
uses: getsentry/testing-ai-sdk-integrations@285c012e522f241581534dfc89bd99ec3b1da4f6
37+
uses: getsentry/testing-ai-sdk-integrations@6b1f51ec8af03e19087df452b426aa7e46d2b20a
3838
env:
3939
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4040
with:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
token: ${{ steps.token.outputs.token }}
3232
fetch-depth: 0
3333
- name: Prepare release
34-
uses: getsentry/craft@d4cfac9d25d1fc72c9241e5d22aff559a114e4e9 # v2
34+
uses: getsentry/craft@013a7b2113c2cac0ff32d5180cfeaefc7c9ce5b6 # v2
3535
env:
3636
GITHUB_TOKEN: ${{ steps.token.outputs.token }}
3737
with:

scripts/populate_tox/package_dependencies.jsonl

Lines changed: 11 additions & 11 deletions
Large diffs are not rendered by default.

scripts/populate_tox/releases.jsonl

Lines changed: 22 additions & 23 deletions
Large diffs are not rendered by default.

sentry_sdk/_span_batcher.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ def _flush(self) -> None:
114114
envelopes = []
115115
for trace_id, spans in self._span_buffer.items():
116116
if spans:
117-
# TODO[span-first]
118-
# dsc = spans[0].dynamic_sampling_context()
119-
dsc = None
117+
dsc = spans[0]._dynamic_sampling_context()
120118

121119
# Max per envelope is 1000, so if we happen to have more than
122120
# 1000 spans in one bucket, we'll need to separate them.

sentry_sdk/ai/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import sentry_sdk
1414
from sentry_sdk.utils import logger
15+
from sentry_sdk.traces import StreamedSpan
16+
from sentry_sdk.tracing_utils import has_span_streaming_enabled
1517

1618
MAX_GEN_AI_MESSAGE_BYTES = 20_000 # 20KB
1719
# Maximum characters when only a single message is left after bytes truncation
@@ -523,7 +525,14 @@ def normalize_message_roles(messages: "list[dict[str, Any]]") -> "list[dict[str,
523525

524526

525527
def get_start_span_function() -> "Callable[..., Any]":
528+
if has_span_streaming_enabled(sentry_sdk.get_client().options):
529+
return sentry_sdk.traces.start_span
530+
526531
current_span = sentry_sdk.get_current_span()
532+
if isinstance(current_span, StreamedSpan):
533+
# mypy
534+
return sentry_sdk.traces.start_span
535+
527536
transaction_exists = (
528537
current_span is not None and current_span.containing_transaction is not None
529538
)

sentry_sdk/api.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from sentry_sdk._init_implementation import init
77
from sentry_sdk.consts import INSTRUMENTER
88
from sentry_sdk.scope import Scope, _ScopeManager, new_scope, isolation_scope
9+
from sentry_sdk.traces import StreamedSpan
910
from sentry_sdk.tracing import NoOpSpan, Transaction, trace
1011
from sentry_sdk.crons import monitor
1112

@@ -37,6 +38,7 @@
3738
LogLevelStr,
3839
SamplingContext,
3940
)
41+
from sentry_sdk.traces import StreamedSpan
4042
from sentry_sdk.tracing import Span, TransactionKwargs
4143

4244
T = TypeVar("T")
@@ -409,7 +411,9 @@ def set_measurement(name: str, value: float, unit: "MeasurementUnit" = "") -> No
409411
transaction.set_measurement(name, value, unit)
410412

411413

412-
def get_current_span(scope: "Optional[Scope]" = None) -> "Optional[Span]":
414+
def get_current_span(
415+
scope: "Optional[Scope]" = None,
416+
) -> "Optional[Union[Span, StreamedSpan]]":
413417
"""
414418
Returns the currently active span if there is one running, otherwise `None`
415419
"""
@@ -525,6 +529,16 @@ def update_current_span(
525529
if current_span is None:
526530
return
527531

532+
if isinstance(current_span, StreamedSpan):
533+
warnings.warn(
534+
"The `update_current_span` API isn't available in streaming mode. "
535+
"Retrieve the current span with get_current_span() and use its API "
536+
"directly.",
537+
DeprecationWarning,
538+
stacklevel=2,
539+
)
540+
return
541+
528542
if op is not None:
529543
current_span.op = op
530544

sentry_sdk/feature_flags.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import copy
22
import sentry_sdk
33
from sentry_sdk._lru_cache import LRUCache
4+
from sentry_sdk.tracing import Span
45
from threading import Lock
56

67
from typing import TYPE_CHECKING, Any
@@ -61,5 +62,5 @@ def add_feature_flag(flag: str, result: bool) -> None:
6162
flags.set(flag, result)
6263

6364
span = sentry_sdk.get_current_span()
64-
if span:
65+
if span and isinstance(span, Span):
6566
span.set_flag(f"flag.evaluation.{flag}", result)

sentry_sdk/integrations/celery/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
)
1515
from sentry_sdk.integrations.celery.utils import _now_seconds_since_epoch
1616
from sentry_sdk.integrations.logging import ignore_logger
17-
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME, TransactionSource
17+
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME, Span, TransactionSource
1818
from sentry_sdk.tracing_utils import Baggage
1919
from sentry_sdk.utils import (
2020
capture_internal_exceptions,
@@ -34,7 +34,6 @@
3434
from typing import Union
3535

3636
from sentry_sdk._types import EventProcessor, Event, Hint, ExcInfo
37-
from sentry_sdk.tracing import Span
3837

3938
F = TypeVar("F", bound=Callable[..., Any])
4039

@@ -100,7 +99,10 @@ def _set_status(status: str) -> None:
10099
with capture_internal_exceptions():
101100
scope = sentry_sdk.get_current_scope()
102101
if scope.span is not None:
103-
scope.span.set_status(status)
102+
if isinstance(scope.span, Span):
103+
scope.span.set_status(status)
104+
else:
105+
scope.span.status = "ok" if status == "ok" else "error"
104106

105107

106108
def _capture_exception(task: "Any", exc_info: "ExcInfo") -> None:

sentry_sdk/integrations/openai_agents/utils.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from sentry_sdk.consts import SPANDATA, SPANSTATUS, OP
1212
from sentry_sdk.integrations import DidNotEnable
1313
from sentry_sdk.scope import should_send_default_pii
14+
from sentry_sdk.tracing import Span
1415
from sentry_sdk.tracing_utils import set_span_errored
1516
from sentry_sdk.utils import event_from_exception, safe_serialize
1617
from sentry_sdk.ai._openai_completions_api import _transform_system_instructions
@@ -22,10 +23,10 @@
2223
from typing import TYPE_CHECKING
2324

2425
if TYPE_CHECKING:
25-
from typing import Any
26+
from typing import Any, Union
2627
from agents import Usage, TResponseInputItem
2728

28-
from sentry_sdk.tracing import Span
29+
from sentry_sdk.traces import StreamedSpan
2930
from sentry_sdk._types import TextPart
3031

3132
try:
@@ -46,8 +47,15 @@ def _capture_exception(exc: "Any") -> None:
4647
sentry_sdk.capture_event(event, hint=hint)
4748

4849

49-
def _record_exception_on_span(span: "Span", error: Exception) -> "Any":
50+
def _record_exception_on_span(
51+
span: "Union[Span, StreamedSpan]", error: Exception
52+
) -> "Any":
5053
set_span_errored(span)
54+
55+
if not isinstance(span, Span):
56+
# TODO[span-first]: make this work with streamedspans
57+
return
58+
5159
span.set_data("span.status", "error")
5260

5361
# Optionally capture the error details if we have them

0 commit comments

Comments
 (0)