Skip to content

Commit d9dc957

Browse files
committed
.
1 parent 2c8cfbd commit d9dc957

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

MIGRATION_GUIDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
1010
### Changed
1111

1212
- The SDK now supports Python 3.7 and higher.
13+
- Transaction names can no longer contain commas and equals signs. If present, these characters will be stripped.
1314
- `sentry_sdk.start_span` now only takes keyword arguments.
1415
- `sentry_sdk.start_span` no longer takes an explicit `span` argument.
1516
- The `Span()` constructor does not accept a `hub` parameter anymore.

sentry_sdk/tracing.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,11 +1189,6 @@ class POTelSpan:
11891189
OTel span wrapper providing compatibility with the old span interface.
11901190
"""
11911191

1192-
# XXX Maybe it makes sense to repurpose the existing Span class for this.
1193-
# For now I'm keeping this class separate to have a clean slate.
1194-
1195-
# XXX The wrapper itself should have as little state as possible
1196-
11971192
def __init__(
11981193
self,
11991194
*,
@@ -1225,14 +1220,14 @@ def __init__(
12251220
# OTel timestamps have nanosecond precision
12261221
start_timestamp = convert_to_otel_timestamp(start_timestamp)
12271222

1228-
self._otel_span = tracer.start_span(
1229-
name or description or op or "", start_time=start_timestamp
1230-
)
1223+
span_name = self._sanitize_name(name or description or op or "")
1224+
self._otel_span = tracer.start_span(span_name, start_time=start_timestamp)
12311225

12321226
self.origin = origin or DEFAULT_SPAN_ORIGIN
12331227
self.op = op
12341228
self.description = description
1235-
self.name = name
1229+
self.name = span_name
1230+
12361231
if status is not None:
12371232
self.set_status(status)
12381233

@@ -1602,6 +1597,10 @@ def set_context(self, key, value):
16021597

16031598
self.set_attribute(f"{SentrySpanAttribute.CONTEXT}.{key}", value)
16041599

1600+
def _sanitize_name(self, name):
1601+
"""No commas and equals allowed in tracestate."""
1602+
return name.replace(",", "").replace("=", "")
1603+
16051604

16061605
if TYPE_CHECKING:
16071606

tests/integrations/pymongo/test_pymongo.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import re
2+
13
from sentry_sdk import capture_message, start_transaction
24
from sentry_sdk.consts import SPANDATA
35
from sentry_sdk.integrations.pymongo import PyMongoIntegration, _strip_pii
@@ -72,8 +74,8 @@ def test_transactions(sentry_init, capture_events, mongo_server, with_pii):
7274
assert insert_fail["data"]["db.operation"] == "insert"
7375

7476
assert find["description"].startswith('{"find')
75-
assert insert_success["description"].startswith('{"insert')
76-
assert insert_fail["description"].startswith('{"insert')
77+
assert re.match("^{['\"]insert.*", insert_success["description"])
78+
assert re.match("^{['\"]insert.*", insert_fail["description"])
7779

7880
assert find["data"][SPANDATA.DB_MONGODB_COLLECTION] == "test_collection"
7981
assert insert_success["data"][SPANDATA.DB_MONGODB_COLLECTION] == "test_collection"
@@ -119,7 +121,11 @@ def test_breadcrumbs(
119121
) # force query execution
120122
capture_message("hi")
121123

122-
(event,) = events
124+
if traces_sample_rate:
125+
event = events[1]
126+
else:
127+
event = events[0]
128+
123129
(crumb,) = event["breadcrumbs"]["values"]
124130

125131
assert crumb["category"] == "query"

0 commit comments

Comments
 (0)