Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
- `SanicIntegration` no longer accepts `unsampled_statuses`.
- The `trace_ignore_status_codes` option was removed.
- `add_attachment` no longer accepts an `add_to_transactions` argument.
- The `stream_gen_ai_spans` option was removed. All spans are streamed now.


## Deprecated
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ class DataCollection(TypedDict):
"start_timestamp": float,
"end_timestamp": NotRequired[float],
"attributes": NotRequired[Attributes],
"_segment_span": NotRequired["sentry_sdk.traces.StreamedSpan"],
"_segment_span": NotRequired["sentry_sdk.traces.Span"],
},
)

Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/ai/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
if TYPE_CHECKING:
from typing import Any, Awaitable, Callable, Optional, TypeVar, Union

from sentry_sdk.traces import StreamedSpan
from sentry_sdk.traces import Span

F = TypeVar("F", bound=Union[Callable[..., Any], Callable[..., Awaitable[Any]]])


def record_token_usage(
span: "StreamedSpan",
span: "Span",
input_tokens: "Optional[int]" = None,
input_tokens_cached: "Optional[int]" = None,
input_tokens_cache_write: "Optional[int]" = None,
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/ai/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
if TYPE_CHECKING:
from typing import Any, Dict, Optional, Tuple

from sentry_sdk.traces import StreamedSpan
from sentry_sdk.traces import Span

import sentry_sdk
from sentry_sdk.utils import logger
Expand Down Expand Up @@ -448,7 +448,7 @@ def _normalize_data(data: "Any", unpack: bool = True) -> "Any":


def set_data_normalized(
span: "StreamedSpan",
span: "Span",
key: str,
value: "Any",
unpack: bool = True,
Expand Down
6 changes: 3 additions & 3 deletions sentry_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
LogLevelStr,
)
from sentry_sdk.client import BaseClient
from sentry_sdk.traces import StreamedSpan
from sentry_sdk.traces import Span

T = TypeVar("T")
F = TypeVar("F", bound=Callable[..., Any])
Expand Down Expand Up @@ -267,11 +267,11 @@ async def flush_async(


@scopemethod
def start_span(**kwargs: "Any") -> "StreamedSpan":
def start_span(**kwargs: "Any") -> "Span":
return traces.start_span(**kwargs)


def get_current_span(scope: "Optional[Scope]" = None) -> "Optional[StreamedSpan]":
def get_current_span(scope: "Optional[Scope]" = None) -> "Optional[Span]":
"""
Returns the currently active span if there is one running, otherwise `None`
"""
Expand Down
12 changes: 6 additions & 6 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from sentry_sdk.scrubber import EventScrubber
from sentry_sdk.serializer import serialize
from sentry_sdk.sessions import SessionFlusher
from sentry_sdk.traces import StreamedSpan, trace
from sentry_sdk.traces import Span, trace
from sentry_sdk.transport import (
AsyncHttpTransport,
HttpTransportCore,
Expand Down Expand Up @@ -70,7 +70,7 @@
from sentry_sdk.scope import Scope
from sentry_sdk.session import Session
from sentry_sdk.spotlight import SpotlightClient
from sentry_sdk.traces import StreamedSpan
from sentry_sdk.traces import Span
from sentry_sdk.transport import Item, Transport
from sentry_sdk.utils import Dsn

Expand Down Expand Up @@ -215,7 +215,7 @@ def _capture_log(self, log: "Log", scope: "Scope") -> None:
def _capture_metric(self, metric: "Metric", scope: "Scope") -> None:
pass

def _capture_span(self, span: "StreamedSpan", scope: "Scope") -> None:
def _capture_span(self, span: "Span", scope: "Scope") -> None:
pass

def capture_session(self, *args: "Any", **kwargs: "Any") -> None:
Expand Down Expand Up @@ -815,7 +815,7 @@ def capture_event(

def _capture_telemetry(
self,
telemetry: "Optional[Union[Log, Metric, StreamedSpan]]",
telemetry: "Optional[Union[Log, Metric, Span]]",
ty: str,
scope: "Scope",
) -> None:
Expand Down Expand Up @@ -864,7 +864,7 @@ def _capture_telemetry(
if serialized is None:
return

elif ty == "span" and isinstance(telemetry, StreamedSpan):
elif ty == "span" and isinstance(telemetry, Span):
# Reset the span to its original value before we attempted
# to call the `before_send_span` callback
if exception_raised_in_before_send_func:
Expand Down Expand Up @@ -908,7 +908,7 @@ def _capture_log(self, log: "Optional[Log]", scope: "Scope") -> None:
def _capture_metric(self, metric: "Optional[Metric]", scope: "Scope") -> None:
self._capture_telemetry(metric, "metric", scope)

def _capture_span(self, span: "Optional[StreamedSpan]", scope: "Scope") -> None:
def _capture_span(self, span: "Optional[Span]", scope: "Scope") -> None:
self._capture_telemetry(span, "span", scope)

def capture_session(
Expand Down
1 change: 0 additions & 1 deletion sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,6 @@ def __init__(
before_send_span: "Optional[Callable[[SpanJSON, Hint], Optional[SpanJSON]]]" = None,
org_id: "Optional[str]" = None,
strict_trace_continuation: bool = False,
stream_gen_ai_spans: bool = True,
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
) -> None:
"""Initialize the Sentry SDK with the given parameters. All parameters described here can be used in a call to `sentry_sdk.init()`.

Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from sentry_sdk.sessions import track_session
from sentry_sdk.traces import (
SegmentNameSource,
Span,
SpanStatus,
StreamedSpan,
)
from sentry_sdk.tracing import (
BAGGAGE_HEADER_NAME,
Expand Down Expand Up @@ -342,7 +342,7 @@ async def on_request_start(
parsed_url.url if parsed_url else SENSITIVE_DATA_SUBSTITUTE,
)

span: "Optional[StreamedSpan]" = None
span: "Optional[Span]" = None
attributes: "Attributes" = {
"sentry.op": OP.HTTP_CLIENT,
"sentry.origin": AioHttpIntegration.origin,
Expand Down
10 changes: 5 additions & 5 deletions sentry_sdk/integrations/aiomysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sentry_sdk
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
from sentry_sdk.traces import StreamedSpan
from sentry_sdk.traces import Span
from sentry_sdk.tracing_utils import (
add_query_source,
record_sql_queries,
Expand Down Expand Up @@ -105,11 +105,11 @@ async def _inner(*args: Any, **kwargs: Any) -> T:
if conn:
_set_db_data(span, conn)
res = await f(*args, **kwargs)
if isinstance(span, StreamedSpan):
if isinstance(span, Span):
with capture_internal_exceptions():
add_query_source(span)

if not isinstance(span, StreamedSpan):
if not isinstance(span, Span):
with capture_internal_exceptions():
add_query_source(span)

Expand Down Expand Up @@ -158,11 +158,11 @@ async def _inner(*args: Any, **kwargs: Any) -> T:
if conn:
_set_db_data(span, conn)
res = await f(*args, **kwargs)
if isinstance(span, StreamedSpan):
if isinstance(span, Span):
with capture_internal_exceptions():
add_query_source(span)

if not isinstance(span, StreamedSpan):
if not isinstance(span, Span):
with capture_internal_exceptions():
add_query_source(span)

Expand Down
22 changes: 11 additions & 11 deletions sentry_sdk/integrations/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.traces import StreamedSpan
from sentry_sdk.traces import Span
from sentry_sdk.utils import (
capture_internal_exceptions,
event_from_exception,
Expand Down Expand Up @@ -83,7 +83,7 @@
from sentry_sdk._types import TextPart

class _PatchedRawMessageStream(Stream[RawMessageStreamEvent]):
_span: StreamedSpan
_span: Span
_integration: "AnthropicIntegration"

_model: Optional[ModelParam]
Expand All @@ -93,7 +93,7 @@ class _PatchedRawMessageStream(Stream[RawMessageStreamEvent]):
_finish_reason: Optional[str]

class _PatchedMessageStream(MessageStream):
_span: StreamedSpan
_span: Span
_integration: "AnthropicIntegration"

_model: Optional[ModelParam]
Expand All @@ -103,7 +103,7 @@ class _PatchedMessageStream(MessageStream):
_finish_reason: Optional[str]

class _PatchedRawAsyncMessageStream(AsyncStream[RawMessageStreamEvent]):
_span: StreamedSpan
_span: Span
_integration: "AnthropicIntegration"

_model: Optional[ModelParam]
Expand All @@ -113,7 +113,7 @@ class _PatchedRawAsyncMessageStream(AsyncStream[RawMessageStreamEvent]):
_finish_reason: Optional[str]

class _PatchedAsyncMessageStream(AsyncMessageStream):
_span: StreamedSpan
_span: Span
_integration: "AnthropicIntegration"

_model: Optional[ModelParam]
Expand All @@ -123,7 +123,7 @@ class _PatchedAsyncMessageStream(AsyncMessageStream):
_finish_reason: Optional[str]

class _PatchedMessageStreamManager(MessageStreamManager):
_span: StreamedSpan
_span: Span
_integration: "AnthropicIntegration"

_max_tokens: int
Expand All @@ -136,7 +136,7 @@ class _PatchedMessageStreamManager(MessageStreamManager):
_tools: Optional[Iterable[ToolUnionParam]]

class _PatchedAsyncMessageStreamManager(AsyncMessageStreamManager[Any]):
_span: StreamedSpan
_span: Span
_integration: "AnthropicIntegration"

_max_tokens: int
Expand Down Expand Up @@ -441,7 +441,7 @@ def _transform_system_instructions(


def _set_common_input_data(
span: "StreamedSpan",
span: "Span",
integration: "AnthropicIntegration",
max_tokens: "int",
messages: "Iterable[MessageParam]",
Expand Down Expand Up @@ -556,7 +556,7 @@ def _set_common_input_data(


def _set_create_input_data(
span: "StreamedSpan",
span: "Span",
kwargs: "dict[str, Any]",
integration: "AnthropicIntegration",
) -> None:
Expand Down Expand Up @@ -640,7 +640,7 @@ async def _wrap_asynchronous_message_iterator(


def _set_output_data(
span: "StreamedSpan",
span: "Span",
integration: "AnthropicIntegration",
model: "str | None",
input_tokens: "int | None",
Expand Down Expand Up @@ -928,7 +928,7 @@ def _accumulate_event_data(


def _set_streaming_output_data(
span: "StreamedSpan",
span: "Span",
integration: "AnthropicIntegration",
model: "Optional[str]",
usage: "_RecordedUsage",
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/arq.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ async def _sentry_coroutine(
return await coroutine(ctx, *args, **kwargs)

scope = sentry_sdk.get_current_scope()
span = scope.streamed_span
span = scope.span
if span is not None:
span.name = name

Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
)
from sentry_sdk.traces import (
SegmentNameSource,
StreamedSpan,
Span,
)
from sentry_sdk.tracing import (
SOURCE_FOR_STYLE,
Expand Down Expand Up @@ -218,7 +218,7 @@ async def _run_app(

method = scope.get("method", "").upper()

span: "Optional[ContextManager[Optional[StreamedSpan]]]" = None
span: "Optional[ContextManager[Optional[Span]]]" = None
attributes: "Attributes" = {
"sentry.segment.name.source": getattr(
transaction_source, "value", transaction_source
Expand Down
6 changes: 3 additions & 3 deletions sentry_sdk/integrations/asyncpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sentry_sdk
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
from sentry_sdk.traces import StreamedSpan
from sentry_sdk.traces import Span
from sentry_sdk.tracing_utils import (
add_query_source,
record_sql_queries,
Expand Down Expand Up @@ -111,7 +111,7 @@ def _record(
params_list: "tuple[Any, ...] | None",
*,
executemany: bool = False,
) -> "Iterator[StreamedSpan]":
) -> "Iterator[Span]":
client = sentry_sdk.get_client()
integration = client.get_integration(AsyncPGIntegration)
if integration is not None and not integration._record_params:
Expand Down Expand Up @@ -231,7 +231,7 @@ async def _inner(*args: "Any", **kwargs: "Any") -> "T":
return _inner


def _set_db_data(span: "StreamedSpan", conn: "Any") -> None:
def _set_db_data(span: "Span", conn: "Any") -> None:
addr = conn._addr
database = conn._params.database
user = conn._params.user
Expand Down
8 changes: 4 additions & 4 deletions sentry_sdk/integrations/boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sentry_sdk
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
from sentry_sdk.traces import StreamedSpan
from sentry_sdk.traces import Span
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME
from sentry_sdk.tracing_utils import (
add_http_breadcrumb,
Expand Down Expand Up @@ -78,7 +78,7 @@ def _sentry_request_created(

breadcrumb: "dict[str, Any]" = {}

span: "Optional[StreamedSpan]" = None
span: "Optional[Span]" = None

url_attributes = get_url_attributes(client, parsed_url)
breadcrumb.update(url_attributes)
Expand Down Expand Up @@ -165,7 +165,7 @@ def _replace_header(request: "AWSRequest", key: str, value: str) -> None:
def _sentry_after_call(
context: "Dict[str, Any]", parsed: "Dict[str, Any]", **kwargs: "Any"
) -> None:
span: "Optional[StreamedSpan]" = context.pop("_sentrysdk_span", None)
span: "Optional[Span]" = context.pop("_sentrysdk_span", None)

# Span could be absent if the integration is disabled.
if span is None:
Expand Down Expand Up @@ -213,7 +213,7 @@ def sentry_streaming_body_close(*args: "Any", **kwargs: "Any") -> None:
def _sentry_after_call_error(
context: "Dict[str, Any]", exception: "Type[BaseException]", **kwargs: "Any"
) -> None:
span: "Optional[StreamedSpan]" = context.pop("_sentrysdk_span", None)
span: "Optional[Span]" = context.pop("_sentrysdk_span", None)

# Span could be absent if the integration is disabled.
if span is None:
Expand Down
Loading
Loading