Skip to content

Commit 25914a5

Browse files
ref(tracing): Simplify backwards-compat code (#3379)
With this change, we aim to simplify the backwards-compatibility code for POTel tracing. We do this as follows: - Remove `start_*` functions from `tracing` - Remove unused parameters from `tracing.POTelSpan.__init__`. - Make all parameters to `tracing.POTelSpan.__init__` kwarg-only. - Allow `tracing.POTelSpan.__init__` to accept arbitrary kwargs, which are all ignored, for compatibility with old `Span` interface. - Completely remove `start_inactive_span`, since inactive spans can be created by setting `active=False` when constructing a `POTelSpan`.
1 parent 6742739 commit 25914a5

File tree

2 files changed

+13
-32
lines changed

2 files changed

+13
-32
lines changed

sentry_sdk/api.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def overload(x):
7777
"set_tags",
7878
"set_user",
7979
"start_span",
80-
"start_inactive_span",
8180
"start_transaction",
8281
"trace",
8382
"monitor",
@@ -338,14 +337,11 @@ def start_span(
338337
**kwargs, # type: Any
339338
):
340339
# type: (...) -> POTelSpan
341-
return tracing.start_span(**kwargs)
342-
343-
344-
def start_inactive_span(
345-
**kwargs, # type: Any
346-
):
347-
# type: (...) -> POTelSpan
348-
return tracing.start_inactive_span(**kwargs)
340+
"""
341+
Alias for tracing.POTelSpan constructor. The method signature is the same.
342+
"""
343+
# TODO: Consider adding type hints to the method signature.
344+
return tracing.POTelSpan(**kwargs)
349345

350346

351347
def start_transaction(
@@ -387,7 +383,7 @@ def start_transaction(
387383
constructor. See :py:class:`sentry_sdk.tracing.Transaction` for
388384
available arguments.
389385
"""
390-
return tracing.start_transaction(transaction, custom_sampling_context, **kwargs)
386+
return start_span(**kwargs)
391387

392388

393389
def set_measurement(name, value, unit=""):

sentry_sdk/tracing.py

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,21 +1249,19 @@ class POTelSpan:
12491249

12501250
def __init__(
12511251
self,
1252+
*,
12521253
active=True, # type: bool
1253-
trace_id=None, # type: Optional[str]
1254-
span_id=None, # type: Optional[str]
1255-
parent_span_id=None, # type: Optional[str]
1256-
same_process_as_parent=True, # type: bool
1257-
sampled=None, # type: Optional[bool]
12581254
op=None, # type: Optional[str]
12591255
description=None, # type: Optional[str]
1260-
status=None, # type: Optional[str]
1261-
containing_transaction=None, # type: Optional[Transaction]
1262-
start_timestamp=None, # type: Optional[Union[datetime, float]]
1263-
scope=None, # type: Optional[sentry_sdk.Scope]
12641256
origin="manual", # type: str
1257+
**_, # type: dict[str, object]
12651258
):
12661259
# type: (...) -> None
1260+
"""
1261+
For backwards compatibility with old the old Span interface, this class
1262+
accepts arbitrary keyword arguments, in addition to the ones explicitly
1263+
listed in the signature. These additional arguments are ignored.
1264+
"""
12671265
from sentry_sdk.integrations.opentelemetry.consts import SentrySpanAttribute
12681266

12691267
self._otel_span = tracer.start_span(description or op or "") # XXX
@@ -1443,19 +1441,6 @@ async def my_async_function():
14431441
return start_child_span_decorator
14441442

14451443

1446-
def start_span(*args, **kwargs):
1447-
return POTelSpan(*args, active=True, **kwargs)
1448-
1449-
1450-
def start_inactive_span(*args, **kwargs):
1451-
return POTelSpan(*args, active=False, **kwargs)
1452-
1453-
1454-
def start_transaction(*args, **kwargs):
1455-
# XXX force_transaction?
1456-
return POTelSpan(*args, active=True, **kwargs)
1457-
1458-
14591444
# Circular imports
14601445

14611446
from sentry_sdk.tracing_utils import (

0 commit comments

Comments
 (0)