Skip to content

Commit b1fa3b5

Browse files
.
1 parent 3d89b9e commit b1fa3b5

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

sentry_sdk/tracing_utils.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ def record_sql_queries(
135135
span_origin: str = "manual",
136136
) -> "Generator[sentry_sdk.tracing.Span, None, None]":
137137
# TODO: Bring back capturing of params by default
138-
if sentry_sdk.get_client().options["_experiments"].get("record_sql_params", False):
138+
client = sentry_sdk.get_client()
139+
if client.options["_experiments"].get("record_sql_params", False):
139140
if not params_list or params_list == [None]:
140141
params_list = None
141142

@@ -160,14 +161,26 @@ def record_sql_queries(
160161
with capture_internal_exceptions():
161162
sentry_sdk.add_breadcrumb(message=query, category="query", data=data)
162163

163-
with sentry_sdk.start_span(
164-
op=OP.DB,
165-
name=query,
166-
origin=span_origin,
167-
) as span:
168-
for k, v in data.items():
169-
span.set_data(k, v)
170-
yield span
164+
if has_span_streaming_enabled(client.options):
165+
with sentry_sdk.traces.start_span(
166+
name=query,
167+
attributes={
168+
"sentry.origin": span_origin,
169+
"sentry.op": OP.DB,
170+
},
171+
) as span:
172+
for k, v in data.items():
173+
span.set_attribute(k, v)
174+
yield span
175+
else:
176+
with sentry_sdk.start_span(
177+
op=OP.DB,
178+
name=query,
179+
origin=span_origin,
180+
) as span:
181+
for k, v in data.items():
182+
span.set_data(k, v)
183+
yield span
171184

172185

173186
def maybe_create_breadcrumbs_from_span(

0 commit comments

Comments
 (0)