Skip to content

Commit 206cb38

Browse files
add db.result to breadcrumb data
1 parent 9fa29e5 commit 206cb38

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

sentry_sdk/integrations/clickhouse_driver.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# from: https://stackoverflow.com/a/71944042/300572
1616
if TYPE_CHECKING:
1717
from collections.abc import Iterator
18-
from typing import Any, Callable, ParamSpec, Union
18+
from typing import Any, Callable, Optional, ParamSpec, Union
1919
else:
2020
# Fake ParamSpec
2121
class ParamSpec:
@@ -96,18 +96,15 @@ def _inner(*args: "P.args", **kwargs: "P.kwargs") -> "T":
9696
},
9797
)
9898

99-
sentry_sdk.get_isolation_scope().add_breadcrumb(
100-
message=query,
101-
category="query",
102-
data={
103-
SPANDATA.DB_SYSTEM: "clickhouse",
104-
SPANDATA.DB_NAME: connection.database,
105-
SPANDATA.DB_DRIVER_NAME: "clickhouse-driver",
106-
SPANDATA.SERVER_ADDRESS: connection.host,
107-
SPANDATA.SERVER_PORT: connection.port,
108-
SPANDATA.DB_USER: connection.user,
109-
},
110-
)
99+
connection._query = query # type: ignore[attr-defined]
100+
connection._breadcrumb_data = { # type: ignore[attr-defined]
101+
SPANDATA.DB_SYSTEM: "clickhouse",
102+
SPANDATA.DB_NAME: connection.database,
103+
SPANDATA.DB_DRIVER_NAME: "clickhouse-driver",
104+
SPANDATA.SERVER_ADDRESS: connection.host,
105+
SPANDATA.SERVER_PORT: connection.port,
106+
SPANDATA.DB_USER: connection.user,
107+
}
111108
else:
112109
span = sentry_sdk.start_span(
113110
op=OP.DB,
@@ -150,6 +147,18 @@ def _inner_end(*args: "P.args", **kwargs: "P.kwargs") -> "T":
150147
return res
151148

152149
if isinstance(span, StreamedSpan):
150+
query = getattr(instance.connection, "_query", None) # type: ignore[attr-defined]
151+
breadcrumb_data: "Optional[dict[str, Any]]" = getattr(
152+
instance.connection, "_breadcrumb_data", None
153+
) # type: ignore[attr-defined]
154+
155+
if query is not None and breadcrumb_data is not None:
156+
sentry_sdk.get_isolation_scope().add_breadcrumb(
157+
message=query,
158+
category="query",
159+
data={"db.result": res, **breadcrumb_data},
160+
)
161+
153162
span.end()
154163
else:
155164
if res is not None:

0 commit comments

Comments
 (0)