Skip to content

Commit aabec99

Browse files
committed
Merge branch 'potel-base' into ivana/potel/fix-asyncpg
2 parents 02dc96d + a67125a commit aabec99

File tree

5 files changed

+153
-78
lines changed

5 files changed

+153
-78
lines changed

MIGRATION_GUIDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
1818
- A `Profile` object does not have a `.hub` property anymore.
1919
- `sentry_sdk.continue_trace` no longer returns a `Transaction` and is now a context manager.
2020
- Redis integration: In Redis pipeline spans there is no `span["data"]["redis.commands"]` that contains a dict `{"count": 3, "first_ten": ["cmd1", "cmd2", ...]}` but instead `span["data"]["redis.commands.count"]` (containing `3`) and `span["data"]["redis.commands.first_ten"]` (containing `["cmd1", "cmd2", ...]`).
21+
- clickhouse-driver integration: The query is now available under the `db.query.text` span attribute (only if `send_default_pii` is `True`).
2122

2223
### Removed
2324

25+
- Spans no longer have a `description`. Use `name` instead.
2426
- Dropped support for Python 3.6.
2527
- `sentry_sdk.metrics` and associated metrics APIs have been removed as Sentry no longer accepts metrics data in this form. See https://sentry.zendesk.com/hc/en-us/articles/26369339769883-Upcoming-API-Changes-to-Metrics
2628
- The experimental options `enable_metrics`, `before_emit_metric` and `metric_code_locations` have been removed.

sentry_sdk/integrations/clickhouse_driver.py

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,15 @@ def _inner(*args: P.args, **kwargs: P.kwargs) -> T:
9191

9292
_set_db_data(span, connection)
9393

94-
span.set_data("query", query)
94+
if should_send_default_pii():
95+
span.set_attribute("db.query.text", query)
9596

9697
if query_id:
97-
span.set_data("db.query_id", query_id)
98+
span.set_attribute("db.query_id", query_id)
9899

99100
if params and should_send_default_pii():
100-
span.set_data("db.params", params)
101+
connection._sentry_db_params = params
102+
span.set_attribute("db.params", str(params))
101103

102104
# run the original code
103105
ret = f(*args, **kwargs)
@@ -115,12 +117,26 @@ def _inner_end(*args: P.args, **kwargs: P.kwargs) -> T:
115117

116118
if span is not None:
117119
if res is not None and should_send_default_pii():
118-
span.set_data("db.result", res)
120+
span.set_attribute("db.result", str(res))
119121

120122
with capture_internal_exceptions():
121-
span.scope.add_breadcrumb(
122-
message=span._data.pop("query"), category="query", data=span._data
123-
)
123+
query = span.get_attribute("db.query.text")
124+
if query:
125+
data = {}
126+
for attr in (
127+
"db.params",
128+
"db.result",
129+
SPANDATA.DB_SYSTEM,
130+
SPANDATA.DB_USER,
131+
SPANDATA.SERVER_ADDRESS,
132+
SPANDATA.SERVER_PORT,
133+
):
134+
if span.get_attribute(attr):
135+
data[attr] = span.get_attribute(attr)
136+
137+
sentry_sdk.add_breadcrumb(
138+
message=query, category="query", data=data
139+
)
124140

125141
span.finish()
126142

@@ -139,9 +155,15 @@ def _inner_send_data(*args: P.args, **kwargs: P.kwargs) -> T:
139155
_set_db_data(span, instance.connection)
140156

141157
if should_send_default_pii():
142-
db_params = span._data.get("db.params", [])
158+
db_params = (
159+
getattr(instance.connection, "_sentry_db_params", None) or []
160+
)
143161
db_params.extend(data)
144-
span.set_data("db.params", db_params)
162+
span.set_attribute("db.params", str(db_params))
163+
try:
164+
del instance.connection._sentry_db_params
165+
except AttributeError:
166+
pass
145167

146168
return f(*args, **kwargs)
147169

@@ -151,8 +173,8 @@ def _inner_send_data(*args: P.args, **kwargs: P.kwargs) -> T:
151173
def _set_db_data(
152174
span: Span, connection: clickhouse_driver.connection.Connection
153175
) -> None:
154-
span.set_data(SPANDATA.DB_SYSTEM, "clickhouse")
155-
span.set_data(SPANDATA.SERVER_ADDRESS, connection.host)
156-
span.set_data(SPANDATA.SERVER_PORT, connection.port)
157-
span.set_data(SPANDATA.DB_NAME, connection.database)
158-
span.set_data(SPANDATA.DB_USER, connection.user)
176+
span.set_attribute(SPANDATA.DB_SYSTEM, "clickhouse")
177+
span.set_attribute(SPANDATA.SERVER_ADDRESS, connection.host)
178+
span.set_attribute(SPANDATA.SERVER_PORT, connection.port)
179+
span.set_attribute(SPANDATA.DB_NAME, connection.database)
180+
span.set_attribute(SPANDATA.DB_USER, connection.user)

sentry_sdk/integrations/opentelemetry/scope.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import warnings
2-
31
from typing import cast
42
from contextlib import contextmanager
53

@@ -125,13 +123,6 @@ def start_transaction(self, custom_sampling_context=None, **kwargs):
125123

126124
def start_span(self, custom_sampling_context=None, **kwargs):
127125
# type: (Optional[SamplingContext], Any) -> POTelSpan
128-
if kwargs.get("description") is not None:
129-
warnings.warn(
130-
"The `description` parameter is deprecated. Please use `name` instead.",
131-
DeprecationWarning,
132-
stacklevel=2,
133-
)
134-
135126
return POTelSpan(**kwargs, scope=self)
136127

137128

sentry_sdk/tracing.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,22 +1273,18 @@ def __enter__(self):
12731273

12741274
def __exit__(self, ty, value, tb):
12751275
# type: (Optional[Any], Optional[Any], Optional[Any]) -> None
1276+
if value is not None:
1277+
self.set_status(SPANSTATUS.INTERNAL_ERROR)
1278+
12761279
self.finish()
1277-
# XXX set status to error if unset and an exception occurred?
12781280
context.detach(self._ctx_token)
12791281

1280-
def _get_attribute(self, name):
1281-
# type: (str) -> Optional[Any]
1282-
if not isinstance(self._otel_span, ReadableSpan):
1283-
return None
1284-
return self._otel_span.attributes.get(name)
1285-
12861282
@property
12871283
def description(self):
12881284
# type: () -> Optional[str]
12891285
from sentry_sdk.integrations.opentelemetry.consts import SentrySpanAttribute
12901286

1291-
return self._get_attribute(SentrySpanAttribute.DESCRIPTION)
1287+
return self.get_attribute(SentrySpanAttribute.DESCRIPTION)
12921288

12931289
@description.setter
12941290
def description(self, value):
@@ -1303,7 +1299,7 @@ def origin(self):
13031299
# type: () -> Optional[str]
13041300
from sentry_sdk.integrations.opentelemetry.consts import SentrySpanAttribute
13051301

1306-
return self._get_attribute(SentrySpanAttribute.ORIGIN)
1302+
return self.get_attribute(SentrySpanAttribute.ORIGIN)
13071303

13081304
@origin.setter
13091305
def origin(self, value):
@@ -1376,7 +1372,7 @@ def op(self):
13761372
# type: () -> Optional[str]
13771373
from sentry_sdk.integrations.opentelemetry.consts import SentrySpanAttribute
13781374

1379-
return self._get_attribute(SentrySpanAttribute.OP)
1375+
return self.get_attribute(SentrySpanAttribute.OP)
13801376

13811377
@op.setter
13821378
def op(self, value):
@@ -1391,7 +1387,7 @@ def name(self):
13911387
# type: () -> Optional[str]
13921388
from sentry_sdk.integrations.opentelemetry.consts import SentrySpanAttribute
13931389

1394-
return self._get_attribute(SentrySpanAttribute.NAME)
1390+
return self.get_attribute(SentrySpanAttribute.NAME)
13951391

13961392
@name.setter
13971393
def name(self, value):
@@ -1507,6 +1503,12 @@ def set_data(self, key, value):
15071503
# TODO-neel-potel we cannot add dicts here
15081504
self.set_attribute(key, value)
15091505

1506+
def get_attribute(self, name):
1507+
# type: (str) -> Optional[Any]
1508+
if not isinstance(self._otel_span, ReadableSpan):
1509+
return None
1510+
return self._otel_span.attributes.get(name)
1511+
15101512
def set_attribute(self, key, value):
15111513
# type: (str, Any) -> None
15121514
self._otel_span.set_attribute(key, value)

0 commit comments

Comments
 (0)