Skip to content

Commit ddf54ef

Browse files
authored
ref: Remove transaction-based tracing (#7468)
- Remove the `Span` and `Transaction` classes and associated types - Remove transaction/old span support from transport, client, scope - Rewire top-level API to `sentry_sdk.traces.*` - Remove old span counting/reporting (`dropped_spans` etc.) - Remove `has_span_streaming_enabled` - ...and more It's a big diff but no logic changes, just removing anything old span related. Closes https://linear.app/getsentry/issue/PY-2654/rewire-top-level-tracing-api-to-span-streaming Closes https://linear.app/getsentry/issue/PY-2655/remove-legacy-tracing Closes https://linear.app/getsentry/issue/PY-2653/remove-has-span-streaming-enabled-branches-from-core
1 parent e2a6518 commit ddf54ef

16 files changed

Lines changed: 70 additions & 1983 deletions

‎docs/api.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ Performance Monitoring
3939

4040
.. autofunction:: sentry_sdk.api.trace
4141
.. autofunction:: sentry_sdk.api.continue_trace
42+
.. autofunction:: sentry_sdk.api.new_trace
4243
.. autofunction:: sentry_sdk.api.get_current_span
4344
.. autofunction:: sentry_sdk.api.start_span
44-
.. autofunction:: sentry_sdk.api.start_transaction
4545

4646

4747
Distributed Tracing

‎docs/apidocs.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ API Docs
2323
.. autoclass:: sentry_sdk.HttpTransport
2424
:members:
2525

26-
.. autoclass:: sentry_sdk.tracing.Transaction
26+
.. autoclass:: sentry_sdk.traces.StreamedSpan
2727
:members:
2828

29-
.. autoclass:: sentry_sdk.tracing.Span
29+
.. autoclass:: sentry_sdk.traces.NoOpStreamedSpan
3030
:members:
3131

3232
.. autoclass:: sentry_sdk.session.Session

‎sentry_sdk/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"capture_exception",
2323
"capture_message",
2424
"continue_trace",
25+
"new_trace",
2526
"flush",
2627
"flush_async",
2728
"get_baggage",
@@ -45,7 +46,6 @@
4546
"set_tags",
4647
"set_user",
4748
"start_span",
48-
"start_transaction",
4949
"trace",
5050
"monitor",
5151
"logger",

‎sentry_sdk/_types.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ class DataCollection(TypedDict):
383383
EventProcessor = Callable[[Event, Hint], Optional[Event]]
384384
ErrorProcessor = Callable[[Event, ExcInfo], Optional[Event]]
385385
BreadcrumbProcessor = Callable[[Breadcrumb, BreadcrumbHint], Optional[Breadcrumb]]
386-
TransactionProcessor = Callable[[Event, Hint], Optional[Event]]
387386
LogProcessor = Callable[[Log, Hint], Optional[Log]]
388387

389388
TracesSampler = Callable[[SamplingContext], Union[float, int, bool]]

‎sentry_sdk/ai/monitoring.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ def record_token_usage(
2424

2525
if input_tokens_cached is not None:
2626
span.set_attribute(
27-
SPANDATA.GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS,
28-
input_tokens_cached,
27+
SPANDATA.GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS, input_tokens_cached
2928
)
3029

3130
if input_tokens_cache_write is not None:

‎sentry_sdk/api.py‎

Lines changed: 18 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import inspect
22
from typing import TYPE_CHECKING
33

4-
from sentry_sdk import Client, tracing_utils
4+
from sentry_sdk import Client, traces
55
from sentry_sdk._init_implementation import init
66
from sentry_sdk.crons import monitor
77
from sentry_sdk.scope import Scope, isolation_scope, new_scope
8-
from sentry_sdk.tracing import NoOpSpan, Transaction, trace
8+
from sentry_sdk.traces import trace
99

1010
if TYPE_CHECKING:
1111
from collections.abc import Mapping
@@ -19,19 +19,16 @@
1919
overload,
2020
)
2121

22-
from typing_extensions import Unpack
23-
2422
from sentry_sdk._types import (
2523
Breadcrumb,
2624
BreadcrumbHint,
2725
Event,
2826
ExcInfo,
2927
Hint,
3028
LogLevelStr,
31-
SamplingContext,
3229
)
3330
from sentry_sdk.client import BaseClient
34-
from sentry_sdk.tracing import Span, TransactionKwargs
31+
from sentry_sdk.traces import StreamedSpan
3532

3633
T = TypeVar("T")
3734
F = TypeVar("F", bound=Callable[..., Any])
@@ -50,6 +47,7 @@ def overload(x: "T") -> "T":
5047
"capture_exception",
5148
"capture_message",
5249
"continue_trace",
50+
"new_trace",
5351
"flush",
5452
"flush_async",
5553
"get_baggage",
@@ -73,7 +71,6 @@ def overload(x: "T") -> "T":
7371
"set_tags",
7472
"set_user",
7573
"start_span",
76-
"start_transaction",
7774
"trace",
7875
"monitor",
7976
"start_session",
@@ -273,59 +270,15 @@ async def flush_async(
273270

274271

275272
@scopemethod
276-
def start_span(
277-
**kwargs: "Any",
278-
) -> "Span":
279-
return get_current_scope().start_span(**kwargs)
280-
281-
282-
@scopemethod
283-
def start_transaction(
284-
transaction: "Optional[Transaction]" = None,
285-
custom_sampling_context: "Optional[SamplingContext]" = None,
286-
**kwargs: "Unpack[TransactionKwargs]",
287-
) -> "Union[Transaction, NoOpSpan]":
288-
"""
289-
Start and return a transaction on the current scope.
290-
291-
Start an existing transaction if given, otherwise create and start a new
292-
transaction with kwargs.
293-
294-
This is the entry point to manual tracing instrumentation.
295-
296-
A tree structure can be built by adding child spans to the transaction,
297-
and child spans to other spans. To start a new child span within the
298-
transaction or any span, call the respective `.start_child()` method.
299-
300-
Every child span must be finished before the transaction is finished,
301-
otherwise the unfinished spans are discarded.
273+
def start_span(**kwargs: "Any") -> "StreamedSpan":
274+
return traces.start_span(**kwargs)
302275

303-
When used as context managers, spans and transactions are automatically
304-
finished at the end of the `with` block. If not using context managers,
305-
call the `.finish()` method.
306276

307-
When the transaction is finished, it will be sent to Sentry with all its
308-
finished child spans.
309-
310-
:param transaction: The transaction to start. If omitted, we create and
311-
start a new transaction.
312-
:param custom_sampling_context: The transaction's custom sampling context.
313-
:param kwargs: Optional keyword arguments to be passed to the Transaction
314-
constructor. See :py:class:`sentry_sdk.tracing.Transaction` for
315-
available arguments.
316-
"""
317-
return get_current_scope().start_transaction(
318-
transaction, custom_sampling_context, **kwargs
319-
)
320-
321-
322-
def get_current_span(
323-
scope: "Optional[Scope]" = None,
324-
) -> "Optional[Span]":
277+
def get_current_span(scope: "Optional[Scope]" = None) -> "Optional[StreamedSpan]":
325278
"""
326279
Returns the currently active span if there is one running, otherwise `None`
327280
"""
328-
return tracing_utils.get_current_span(scope)
281+
return traces.get_current_span(scope)
329282

330283

331284
def get_traceparent() -> "Optional[str]":
@@ -346,19 +299,18 @@ def get_baggage() -> "Optional[str]":
346299
return None
347300

348301

349-
def continue_trace(
350-
environ_or_headers: "Dict[str, Any]",
351-
op: "Optional[str]" = None,
352-
name: "Optional[str]" = None,
353-
source: "Optional[str]" = None,
354-
origin: str = "manual",
355-
) -> "Transaction":
302+
def continue_trace(incoming: "Dict[str, Any]") -> None:
356303
"""
357-
Sets the propagation context from environment or headers and returns a transaction.
304+
Sets the propagation context from environment or headers.
358305
"""
359-
return get_isolation_scope().continue_trace(
360-
environ_or_headers, op, name, source, origin
361-
)
306+
return traces.continue_trace(incoming)
307+
308+
309+
def new_trace() -> None:
310+
"""
311+
Resets the propagation context, forcing a new trace.
312+
"""
313+
return traces.new_trace()
362314

363315

364316
@scopemethod

0 commit comments

Comments
 (0)