8000 Revert "ref: Remove deprecated `Transaction` creation method" · au79stein/sentry-python@46087c3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 46087c3

Browse files
Revert "ref: Remove deprecated Transaction creation method"
This reverts commit 4bc100b, which was accidentally committed to this branch.
1 parent 4bc100b commit 46087c3

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

MIGRATION_GUIDE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ Looking to upgrade from Sentry SDK 1.x to 2.x? Here's a comprehensive list of wh
7171
- Removed support for the `install` method for custom integrations. Please use `setup_once` instead.
7272
- Removed `sentry_sdk.tracing.Span.new_span`. Use `sentry_sdk.tracing.Span.start_child` instead.
7373
- Removed `sentry_sdk.tracing.Transaction.new_span`. Use `sentry_sdk.tracing.Transaction.start_child` instead.
74-
- Removed support for creating transactions via `sentry_sdk.tracing.Span(transaction=...)`. To create a transaction, please use `sentry_sdk.tracing.Transaction(name=...)`.
7574
- Removed `sentry_sdk.utils.Auth.store_api_url`.
7675
- `sentry_sdk.utils.Auth.get_api_url`'s now accepts a `sentry_sdk.consts.EndpointType` enum instead of a string as its only parameter. We recommend omitting this argument when calling the function, since the parameter's default value is the only possible `sentry_sdk.consts.EndpointType` value. The parameter exists for future compatibility.
7776
- Removed `tracing_utils_py2.py`. The `start_child_span_decorator` is now in `sentry_sdk.tracing_utils`.

sentry_sdk/tracing.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class SpanKwargs(TypedDict, total=False):
4040
description: str
4141
# hub: Optional[sentry_sdk.Hub] is deprecated, and therefore omitted here!
4242
status: str
43+
# transaction: str is deprecated, and therefore omitted here!
4344
containing_transaction: Optional["Transaction"]
4445
start_timestamp: Optional[Union[datetime, float]]
4546
scope: "sentry_sdk.Scope"
@@ -131,6 +132,20 @@ class Span:
131132
"scope",
132133
)
133134

135+
def __new__(cls, **kwargs):
136+
# type: (**Any) -> Any
137+
"""
138+
Backwards-compatible implementation of Span and Transaction
139+
creation.
140+
"""
141+
142+
# TODO: consider removing this in a future release.
143+
# This is for backwards compatibility with releases before Transaction
144+
# existed, to allow for a smoother transition.
145+
if "transaction" in kwargs:
146+
return object.__new__(Transaction)
147+
return object.__new__(cls)
148+
134149
def __init__(
135150
self,
136151
trace_id=None, # type: Optional[str]
@@ -142,6 +157,7 @@ def __init__(
142157
description=None, # type: Optional[str]
143158
hub=None, # type: Optional[sentry_sdk.Hub] # deprecated
144159
status=None, # type: Optional[str]
160+
transaction=None, # type: Optional[str] # deprecated
145161
containing_transaction=None, # type: Optional[Transaction]
146162
start_timestamp=None, # type: Optional[Union[datetime, float]]
147163
scope=None, # type: Optional[sentry_sdk.Scope]
@@ -582,6 +598,15 @@ def __init__(
582598
See https://develop.sentry.dev/sdk/event-payloads/transaction/#transaction-annotations
583599
for more information. Default "custom".
584600
"""
601+
# TODO: consider removing this in a future release.
602+
# This is for backwards compatibility with releases before Transaction
603+
# existed, to allow for a smoother transition.
604+
if not name and "transaction" in kwargs:
605+
logger.warning(
606+
"Deprecated: use Transaction(name=...) to create transactions "
607+
"instead of Span(transaction=...)."
608+
)
609+
name = kwargs.pop("transaction") # type: ignore
585610

586611
super().__init__(**kwargs)
587612

0 commit comments

Comments
 (0)
0