Skip to content

Commit 72620d1

Browse files
authored
Replace old Span/Transaction completely with POTelSpan (#3966)
* `POTelSpan` no longer exists * Old `Span/Transaction` both point to new `Span` * `NoOpSpan` is still around to enable future potential errors-only stuff closes #3968
1 parent 19754c8 commit 72620d1

File tree

15 files changed

+60
-1036
lines changed

15 files changed

+60
-1036
lines changed

sentry_sdk/ai/monitoring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import sentry_sdk.utils
55
from sentry_sdk import start_span
6-
from sentry_sdk.tracing import POTelSpan as Span
6+
from sentry_sdk.tracing import Span
77
from sentry_sdk.utils import ContextVar
88

99
from typing import TYPE_CHECKING

sentry_sdk/ai/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
if TYPE_CHECKING:
44
from typing import Any
55

6-
from sentry_sdk.tracing import POTelSpan as Span
6+
from sentry_sdk.tracing import Span
77
from sentry_sdk.utils import logger
88

99

sentry_sdk/api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from sentry_sdk import tracing_utils, Client
55
from sentry_sdk._init_implementation import init
6-
from sentry_sdk.tracing import POTelSpan, Transaction, trace
6+
from sentry_sdk.tracing import trace
77
from sentry_sdk.crons import monitor
88

99
# TODO-neel-potel make 2 scope strategies/impls and switch
@@ -239,7 +239,7 @@ def flush(
239239

240240

241241
def start_span(**kwargs):
242-
# type: (type.Any) -> POTelSpan
242+
# type: (type.Any) -> Span
243243
"""
244244
Start and return a span.
245245
@@ -256,10 +256,10 @@ def start_span(**kwargs):
256256

257257

258258
def start_transaction(
259-
transaction=None, # type: Optional[Transaction]
259+
transaction=None, # type: Optional[Span]
260260
**kwargs, # type: Unpack[TransactionKwargs]
261261
):
262-
# type: (...) -> POTelSpan
262+
# type: (...) -> Span
263263
"""
264264
.. deprecated:: 3.0.0
265265
This function is deprecated and will be removed in a future release.

sentry_sdk/integrations/langchain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from sentry_sdk.consts import OP, SPANDATA, SPANSTATUS
77
from sentry_sdk.ai.utils import set_data_normalized
88
from sentry_sdk.scope import should_send_default_pii
9-
from sentry_sdk.tracing import POTelSpan as Span
9+
from sentry_sdk.tracing import Span
1010
from sentry_sdk.integrations import DidNotEnable, Integration
1111
from sentry_sdk.utils import logger, capture_internal_exceptions
1212

sentry_sdk/integrations/opentelemetry/scope.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
)
2929
from sentry_sdk.integrations.opentelemetry.utils import trace_state_from_baggage
3030
from sentry_sdk.scope import Scope, ScopeType
31-
from sentry_sdk.tracing import POTelSpan
31+
from sentry_sdk.tracing import Span
3232
from sentry_sdk._types import TYPE_CHECKING
3333

3434
if TYPE_CHECKING:
@@ -128,7 +128,7 @@ def _incoming_otel_span_context(self):
128128
return span_context
129129

130130
def start_transaction(self, **kwargs):
131-
# type: (Unpack[TransactionKwargs]) -> POTelSpan
131+
# type: (Unpack[TransactionKwargs]) -> Span
132132
"""
133133
.. deprecated:: 3.0.0
134134
This function is deprecated and will be removed in a future release.
@@ -137,8 +137,8 @@ def start_transaction(self, **kwargs):
137137
return self.start_span(**kwargs)
138138

139139
def start_span(self, **kwargs):
140-
# type: (Any) -> POTelSpan
141-
return POTelSpan(**kwargs, scope=self)
140+
# type: (Any) -> Span
141+
return Span(**kwargs, scope=self)
142142

143143

144144
_INITIAL_CURRENT_SCOPE = None

sentry_sdk/integrations/opentelemetry/span_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def force_flush(self, timeout_millis=30000):
9898
def _add_root_span(self, span, parent_span):
9999
# type: (Span, AbstractSpan) -> None
100100
"""
101-
This is required to make POTelSpan.root_span work
101+
This is required to make Span.root_span work
102102
since we can't traverse back to the root purely with otel efficiently.
103103
"""
104104
if parent_span != INVALID_SPAN and not parent_span.get_span_context().is_remote:

sentry_sdk/integrations/rust_tracing.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import sentry_sdk
3838
from sentry_sdk.integrations import Integration
3939
from sentry_sdk.scope import should_send_default_pii
40-
from sentry_sdk.tracing import POTelSpan as SentrySpan
40+
from sentry_sdk.tracing import Span
4141
from sentry_sdk.utils import SENSITIVE_DATA_SUBSTITUTE
4242

4343

@@ -169,7 +169,7 @@ def _include_tracing_fields(self) -> bool:
169169
else self.include_tracing_fields
170170
)
171171

172-
def on_event(self, event: str, _span_state: Optional[SentrySpan]) -> None:
172+
def on_event(self, event: str, _span_state: Optional[Span]) -> None:
173173
deserialized_event = json.loads(event)
174174
metadata = deserialized_event.get("metadata", {})
175175

@@ -183,7 +183,7 @@ def on_event(self, event: str, _span_state: Optional[SentrySpan]) -> None:
183183
elif event_type == EventTypeMapping.Event:
184184
process_event(deserialized_event)
185185

186-
def on_new_span(self, attrs: str, span_id: str) -> Optional[SentrySpan]:
186+
def on_new_span(self, attrs: str, span_id: str) -> Optional[Span]:
187187
attrs = json.loads(attrs)
188188
metadata = attrs.get("metadata", {})
189189

@@ -220,11 +220,11 @@ def on_new_span(self, attrs: str, span_id: str) -> Optional[SentrySpan]:
220220

221221
return span
222222

223-
def on_close(self, span_id: str, span: Optional[SentrySpan]) -> None:
223+
def on_close(self, span_id: str, span: Optional[Span]) -> None:
224224
if span is not None:
225225
span.__exit__(None, None, None)
226226

227-
def on_record(self, span_id: str, values: str, span: Optional[SentrySpan]) -> None:
227+
def on_record(self, span_id: str, values: str, span: Optional[Span]) -> None:
228228
if span is not None:
229229
deserialized_values = json.loads(values)
230230
for key, value in deserialized_values.items():

sentry_sdk/integrations/wsgi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
_request_headers_to_span_attributes,
1313
)
1414
from sentry_sdk.sessions import track_session
15-
from sentry_sdk.tracing import Transaction, TRANSACTION_SOURCE_ROUTE
15+
from sentry_sdk.tracing import Span, TRANSACTION_SOURCE_ROUTE
1616
from sentry_sdk.utils import (
1717
ContextVar,
1818
capture_internal_exceptions,
@@ -157,7 +157,7 @@ def __call__(self, environ, start_response):
157157

158158
def _sentry_start_response( # type: ignore
159159
old_start_response, # type: StartResponse
160-
transaction, # type: Optional[Transaction]
160+
transaction, # type: Optional[Span]
161161
status, # type: str
162162
response_headers, # type: WsgiResponseHeaders
163163
exc_info=None, # type: Optional[WsgiExcInfo]

sentry_sdk/scope.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
SENTRY_TRACE_HEADER_NAME,
2727
NoOpSpan,
2828
Span,
29-
POTelSpan,
30-
Transaction,
3129
)
3230
from sentry_sdk.utils import (
3331
capture_internal_exception,
@@ -677,7 +675,7 @@ def clear(self):
677675
self.clear_breadcrumbs()
678676
self._should_capture = True # type: bool
679677

680-
self._span = None # type: Optional[POTelSpan]
678+
self._span = None # type: Optional[Span]
681679
self._session = None # type: Optional[Session]
682680
self._force_auto_session_tracking = None # type: Optional[bool]
683681

@@ -707,7 +705,7 @@ def fingerprint(self, value):
707705
@property
708706
def transaction(self):
709707
# type: () -> Any
710-
# would be type: () -> Optional[Transaction], see https://github.com/python/mypy/issues/3004
708+
# would be type: () -> Optional[Span], see https://github.com/python/mypy/issues/3004
711709
"""Return the transaction (root span) in the scope, if any."""
712710

713711
# there is no span/transaction on the scope
@@ -734,7 +732,7 @@ def transaction(self, value):
734732
# anything set in the scope.
735733
# XXX: note that with the introduction of the Scope.transaction getter,
736734
# there is a semantic and type mismatch between getter and setter. The
737-
# getter returns a Transaction, the setter sets a transaction name.
735+
# getter returns a Span, the setter sets a transaction name.
738736
# Without breaking version compatibility, we could make the setter set a
739737
# transaction name or transaction (self._span) depending on the type of
740738
# the value argument.
@@ -785,13 +783,13 @@ def set_user(self, value):
785783

786784
@property
787785
def span(self):
788-
# type: () -> Optional[POTelSpan]
786+
# type: () -> Optional[Span]
789787
"""Get current tracing span."""
790788
return self._span
791789

792790
@span.setter
793791
def span(self, span):
794-
# type: (Optional[POTelSpan]) -> None
792+
# type: (Optional[Span]) -> None
795793
"""Set current tracing span."""
796794
self._span = span
797795

@@ -952,7 +950,7 @@ def add_breadcrumb(self, crumb=None, hint=None, **kwargs):
952950
self._breadcrumbs.popleft()
953951

954952
def start_transaction(self, transaction=None, **kwargs):
955-
# type: (Optional[Transaction], Optional[SamplingContext], Unpack[TransactionKwargs]) -> Union[Transaction, NoOpSpan]
953+
# type: (Optional[Span], Optional[SamplingContext], Unpack[TransactionKwargs]) -> Union[Span, NoOpSpan]
956954
"""
957955
Start and return a transaction.
958956
@@ -981,14 +979,15 @@ def start_transaction(self, transaction=None, **kwargs):
981979
constructor. See :py:class:`sentry_sdk.tracing.Transaction` for
982980
available arguments.
983981
"""
982+
# TODO-neel-potel fix signature and no op
984983
kwargs.setdefault("scope", self)
985984

986985
client = self.get_client()
987986

988987
try_autostart_continuous_profiler()
989988

990989
# if we haven't been given a transaction, make one
991-
transaction = Transaction(**kwargs)
990+
transaction = Span(**kwargs)
992991

993992
# use traces_sample_rate, traces_sampler, and/or inheritance to make a
994993
# sampling decision
@@ -1024,6 +1023,7 @@ def start_span(self, **kwargs):
10241023
10251024
For supported `**kwargs` see :py:class:`sentry_sdk.tracing.Span`.
10261025
"""
1026+
# TODO-neel-potel fix signature and no op
10271027
if kwargs.get("description") is not None:
10281028
warnings.warn(
10291029
"The `description` parameter is deprecated. Please use `name` instead.",
@@ -1054,13 +1054,14 @@ def start_span(self, **kwargs):
10541054
def continue_trace(
10551055
self, environ_or_headers, op=None, name=None, source=None, origin=None
10561056
):
1057-
# type: (Dict[str, Any], Optional[str], Optional[str], Optional[str], Optional[str]) -> Transaction
1057+
# TODO-neel-potel fix signature and no op
1058+
# type: (Dict[str, Any], Optional[str], Optional[str], Optional[str], Optional[str]) -> Span
10581059
"""
10591060
Sets the propagation context from environment or headers and returns a transaction.
10601061
"""
10611062
self.generate_propagation_context(environ_or_headers)
10621063

1063-
transaction = Transaction.continue_from_headers(
1064+
transaction = Span.continue_from_headers(
10641065
normalize_incoming_data(environ_or_headers),
10651066
op=op,
10661067
origin=origin,

0 commit comments

Comments
 (0)