Skip to content

Commit bd4d825

Browse files
authored
chore: Remove more old transaction stuff (#7492)
- remove `scope.transaction` (`set_transaction_name` remains for now; changed all direct uses of `scope.transaction =` to use `set_transaction_name` instead) - remove more interop utils (`_serialized_v1_attribute_to_serialized_v2_attribute` etc.) - remove event processor-based transaction name setting (superseded by `set_transaction_name` directly in patches) - ...
1 parent d68570b commit bd4d825

15 files changed

Lines changed: 32 additions & 457 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ uv run ruff format tests sentry_sdk
100100
We use `mypy` for typing our codebase. Use the following command to typecheck the source:
101101

102102
```
103-
uv run --group typing mypy sentry_sdk
103+
uv run --group typing mypy sentry_sdk
104104
```
105105

106106
##### Install Coding Style Pre-commit Hooks
@@ -167,7 +167,7 @@ TESTPATH=tests/integrations/logging/test_logging.py uv run tox -e py3.12-common
167167
To select specific tests, you can forward arguments to `pytest` like so
168168

169169
```bash
170-
uv run tox -e py3.12-celery-v5.5.3 -- -k test_transaction_events
170+
uv run tox -e py3.12-celery-v5.5.3 -- -k test_simple_with_performance
171171
```
172172

173173
In general, you use

‎MIGRATION_GUIDE.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
156156
- The `update_current_span` API was removed.
157157
- `SanicIntegration` no longer accepts `unsampled_statuses`.
158158
- The `trace_ignore_status_codes` option was removed.
159+
- `add_attachment` no longer accepts an `add_to_transactions` argument.
159160

160161

161162
## Deprecated

‎sentry_sdk/_types.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ class DataCollection(TypedDict):
394394
"default",
395395
"error",
396396
"crash",
397-
"transaction",
398397
"security",
399398
"attachment",
400399
"session",

‎sentry_sdk/api.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,8 @@ def add_attachment(
174174
filename: "Optional[str]" = None,
175175
path: "Optional[str]" = None,
176176
content_type: "Optional[str]" = None,
177-
add_to_transactions: bool = False,
178177
) -> None:
179-
return get_isolation_scope().add_attachment(
180-
bytes, filename, path, content_type, add_to_transactions
181-
)
178+
return get_isolation_scope().add_attachment(bytes, filename, path, content_type)
182179

183180

184181
@scopemethod

‎sentry_sdk/attachments.py‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ class Attachment:
1313
1414
This class stores attachments that can be sent along with an event. Attachments are files or other data, e.g.
1515
config or log files, that are relevant to an event. Attachments are set on the ``Scope``, and are sent along with
16-
all non-transaction events (or all events including transactions if ``add_to_transactions`` is ``True``) that are
17-
captured within the ``Scope``.
16+
all non-transaction events that are captured within the ``Scope``.
1817
1918
To add an attachment to a ``Scope``, use :py:meth:`sentry_sdk.Scope.add_attachment`. The parameters for
2019
``add_attachment`` are the same as the parameters for this class's constructor.
@@ -25,7 +24,6 @@ class Attachment:
2524
:param path: Path to a file to attach. Must be provided unless ``bytes`` is provided.
2625
:param content_type: The content type of the attachment. If not provided, it will be guessed from the ``filename``
2726
parameter, if available, or the ``path`` parameter if ``filename`` is ``None``.
28-
:param add_to_transactions: Whether to add this attachment to transactions. Defaults to ``False``.
2927
"""
3028

3129
def __init__(
@@ -34,7 +32,6 @@ def __init__(
3432
filename: "Optional[str]" = None,
3533
path: "Optional[str]" = None,
3634
content_type: "Optional[str]" = None,
37-
add_to_transactions: bool = False,
3835
) -> None:
3936
if bytes is None and path is None:
4037
raise TypeError("path or raw bytes required for attachment")
@@ -48,7 +45,6 @@ def __init__(
4845
self.filename = filename
4946
self.path = path
5047
self.content_type = content_type
51-
self.add_to_transactions = add_to_transactions
5248

5349
def to_envelope_item(self) -> "Item":
5450
"""Returns an envelope item for this attachment."""

‎sentry_sdk/client.py‎

Lines changed: 3 additions & 206 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
import json
21
import os
3-
import platform
42
import random
53
import socket
6-
import sys
74
import uuid
8-
from collections.abc import Iterable, Mapping
5+
from collections.abc import Mapping
96
from contextvars import ContextVar
107
from datetime import datetime, timezone
118
from importlib import import_module
12-
from typing import TYPE_CHECKING, Dict, List, cast, overload
9+
from typing import TYPE_CHECKING, Dict, cast, overload
1310

1411
from sentry_sdk._compat import check_uwsgi_thread_support
1512
from sentry_sdk._log_batcher import LogBatcher
@@ -18,7 +15,6 @@
1815
from sentry_sdk.consts import (
1916
DEFAULT_MAX_VALUE_LENGTH,
2017
DEFAULT_OPTIONS,
21-
SPANSTATUS,
2218
VERSION,
2319
ClientConstructor,
2420
)
@@ -34,7 +30,7 @@
3430
from sentry_sdk.scrubber import EventScrubber
3531
from sentry_sdk.serializer import serialize
3632
from sentry_sdk.sessions import SessionFlusher
37-
from sentry_sdk.traces import SpanStatus, StreamedSpan, trace
33+
from sentry_sdk.traces import StreamedSpan, trace
3834
from sentry_sdk.transport import (
3935
AsyncHttpTransport,
4036
HttpTransportCore,
@@ -44,7 +40,6 @@
4440
AnnotatedValue,
4541
capture_internal_exceptions,
4642
current_stacktrace,
47-
datetime_from_isoformat,
4843
env_to_bool,
4944
format_timestamp,
5045
get_before_send_log,
@@ -70,7 +65,6 @@
7065
Log,
7166
Metric,
7267
SDKInfo,
73-
SerializedAttributeValue,
7468
)
7569
from sentry_sdk.integrations import Integration
7670
from sentry_sdk.scope import Scope
@@ -92,203 +86,6 @@
9286
}
9387

9488

95-
def _serialized_v1_attribute_to_serialized_v2_attribute(
96-
attribute_value: "Any",
97-
) -> "Optional[SerializedAttributeValue]":
98-
if isinstance(attribute_value, bool):
99-
return {
100-
"value": attribute_value,
101-
"type": "boolean",
102-
}
103-
104-
if isinstance(attribute_value, int):
105-
return {
106-
"value": attribute_value,
107-
"type": "integer",
108-
}
109-
110-
if isinstance(attribute_value, float):
111-
return {
112-
"value": attribute_value,
113-
"type": "double",
114-
}
115-
116-
if isinstance(attribute_value, str):
117-
return {
118-
"value": attribute_value,
119-
"type": "string",
120-
}
121-
122-
if isinstance(attribute_value, list):
123-
if not attribute_value:
124-
return {"value": [], "type": "array"}
125-
126-
ty = type(attribute_value[0])
127-
if ty in (int, str, bool, float) and all(
128-
type(v) is ty for v in attribute_value
129-
):
130-
return {
131-
"value": attribute_value,
132-
"type": "array",
133-
}
134-
135-
# Types returned when the serializer for V1 span attributes recurses into some container types.
136-
if isinstance(attribute_value, (dict, list)):
137-
return {
138-
"value": json.dumps(attribute_value),
139-
"type": "string",
140-
}
141-
142-
return None
143-
144-
145-
def _serialized_v1_span_to_serialized_v2_span(
146-
span: "dict[str, Any]", event: "Event"
147-
) -> "dict[str, Any]":
148-
# See SpanBatcher._to_transport_format() for analogous population of all entries except "attributes".
149-
res: "dict[str, Any]" = {
150-
"status": SpanStatus.OK.value,
151-
"is_segment": False,
152-
}
153-
154-
if "trace_id" in span:
155-
res["trace_id"] = span["trace_id"]
156-
157-
if "span_id" in span:
158-
res["span_id"] = span["span_id"]
159-
160-
if "description" in span:
161-
description = span["description"]
162-
163-
if description is None and "op" in span:
164-
description = span["op"]
165-
166-
res["name"] = description
167-
168-
if "start_timestamp" in span:
169-
start_timestamp = None
170-
try:
171-
start_timestamp = datetime_from_isoformat(span["start_timestamp"])
172-
except Exception:
173-
pass
174-
175-
if start_timestamp is not None:
176-
res["start_timestamp"] = start_timestamp.timestamp()
177-
178-
if "timestamp" in span:
179-
end_timestamp = None
180-
try:
181-
end_timestamp = datetime_from_isoformat(span["timestamp"])
182-
except Exception:
183-
pass
184-
185-
if end_timestamp is not None:
186-
res["end_timestamp"] = end_timestamp.timestamp()
187-
188-
if "parent_span_id" in span:
189-
res["parent_span_id"] = span["parent_span_id"]
190-
191-
if "status" in span and span["status"] != SPANSTATUS.OK:
192-
res["status"] = "error"
193-
194-
attributes: "Dict[str, Any]" = {}
195-
196-
if "op" in span:
197-
attributes["sentry.op"] = span["op"]
198-
if "origin" in span:
199-
attributes["sentry.origin"] = span["origin"]
200-
201-
span_data = span.get("data")
202-
if isinstance(span_data, dict):
203-
attributes.update(span_data)
204-
205-
span_tags = span.get("tags")
206-
if isinstance(span_tags, dict):
207-
attributes.update(span_tags)
208-
209-
# See Scope._apply_user_attributes_to_telemetry() for user attributes.
210-
user = event.get("user")
211-
if isinstance(user, dict):
212-
if "id" in user:
213-
attributes["user.id"] = user["id"]
214-
if "username" in user:
215-
attributes["user.name"] = user["username"]
216-
if "email" in user:
217-
attributes["user.email"] = user["email"]
218-
219-
# See Scope.set_global_attributes() for release, environment, and SDK metadata.
220-
if "release" in event:
221-
attributes["sentry.release"] = event["release"]
222-
if "environment" in event:
223-
attributes["sentry.environment"] = event["environment"]
224-
if "server_name" in event:
225-
attributes["server.address"] = event["server_name"]
226-
if "transaction" in event:
227-
attributes["sentry.segment.name"] = event["transaction"]
228-
229-
trace_context = event.get("contexts", {}).get("trace", {})
230-
if "span_id" in trace_context:
231-
attributes["sentry.segment.id"] = trace_context["span_id"]
232-
233-
sdk_info = event.get("sdk")
234-
if isinstance(sdk_info, dict):
235-
if "name" in sdk_info:
236-
attributes["sentry.sdk.name"] = sdk_info["name"]
237-
if "version" in sdk_info:
238-
attributes["sentry.sdk.version"] = sdk_info["version"]
239-
240-
attributes["process.runtime.name"] = platform.python_implementation()
241-
attributes["process.runtime.version"] = (
242-
f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
243-
)
244-
245-
if not attributes:
246-
return res
247-
248-
res["attributes"] = {}
249-
for key, value in attributes.items():
250-
converted_value = _serialized_v1_attribute_to_serialized_v2_attribute(value)
251-
if converted_value is None:
252-
continue
253-
254-
res["attributes"][key] = converted_value
255-
256-
# Remove redundant attribute, as status is stored in the status field.
257-
if "status" in res["attributes"]:
258-
del res["attributes"]["status"]
259-
260-
return res
261-
262-
263-
def _split_gen_ai_spans(
264-
event_opt: "Event",
265-
) -> "Optional[tuple[List[Dict[str, object]], List[Dict[str, object]]]]":
266-
if "spans" not in event_opt:
267-
return None
268-
269-
spans: "Any" = event_opt["spans"]
270-
if isinstance(spans, AnnotatedValue):
271-
spans = spans.value
272-
273-
if not isinstance(spans, Iterable):
274-
return None
275-
276-
non_gen_ai_spans = []
277-
gen_ai_spans = []
278-
for span in spans:
279-
if not isinstance(span, dict):
280-
non_gen_ai_spans.append(span)
281-
continue
282-
283-
span_op = span.get("op")
284-
if isinstance(span_op, str) and span_op.startswith("gen_ai."):
285-
gen_ai_spans.append(span)
286-
else:
287-
non_gen_ai_spans.append(span)
288-
289-
return non_gen_ai_spans, gen_ai_spans
290-
291-
29289
def _get_options(*args: "Optional[str]", **kwargs: "Any") -> "Dict[str, Any]":
29390
if args and (isinstance(args[0], (bytes, str)) or args[0] is None):
29491
dsn: "Optional[str]" = args[0]

0 commit comments

Comments
 (0)