Skip to content

Commit 971642b

Browse files
ref(tracing): Simplify backwards-compat code
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__` - Completely remove `start_inactive_span`, since inactive spans can be created by setting `active=False` when constructing a `POTelSpan`. - Handle backwards-compatibility in top-level API by stripping any invalid `kwargs` before calling the `POTelSpan` constructor.
1 parent 144d976 commit 971642b

File tree

2 files changed

+13
-30
lines changed

2 files changed

+13
-30
lines changed

sentry_sdk/api.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,15 @@ def overload(x):
7878
"set_tags",
7979
"set_user",
8080
"start_span",
81-
"start_inactive_span",
8281
"start_transaction",
8382
"trace",
8483
"monitor",
8584
]
8685

8786

87+
_potel_span_init_kwargs = None
88+
89+
8890
def scopemethod(f):
8991
# type: (F) -> F
9092
f.__doc__ = "%s\n\n%s" % (
@@ -339,14 +341,16 @@ def start_span(
339341
**kwargs, # type: Any
340342
):
341343
# type: (...) -> POTelSpan
342-
return tracing.start_span(**kwargs)
344+
global _potel_span_init_kwargs
343345

346+
if _potel_span_init_kwargs is None:
347+
_potel_span_init_kwargs = inspect.signature(tracing.POTelSpan).parameters.keys()
344348

345-
def start_inactive_span(
346-
**kwargs, # type: Any
347-
):
348-
# type: (...) -> POTelSpan
349-
return tracing.start_inactive_span(**kwargs)
349+
filtered_kwargs = {
350+
kwarg: kwargs[kwarg] for kwarg in _potel_span_init_kwargs if kwarg in kwargs
351+
}
352+
353+
return tracing.POTelSpan(**filtered_kwargs)
350354

351355

352356
def start_transaction(
@@ -388,7 +392,7 @@ def start_transaction(
388392
constructor. See :py:class:`sentry_sdk.tracing.Transaction` for
389393
available arguments.
390394
"""
391-
return tracing.start_transaction(transaction, custom_sampling_context, **kwargs)
395+
return start_span(**kwargs)
392396

393397

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

sentry_sdk/tracing.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,18 +1249,10 @@ 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
12651257
):
12661258
# type: (...) -> None
@@ -1443,19 +1435,6 @@ async def my_async_function():
14431435
return start_child_span_decorator
14441436

14451437

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-
14591438
# Circular imports
14601439

14611440
from sentry_sdk.tracing_utils import (

0 commit comments

Comments
 (0)