Skip to content

Commit 03dc2ca

Browse files
committed
more fixes
1 parent b66c3d3 commit 03dc2ca

File tree

8 files changed

+36
-16
lines changed

8 files changed

+36
-16
lines changed

sentry_sdk/integrations/asgi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ async def _run_app(
217217
span_ctx: "ContextManager[Union[Span, StreamedSpan, None]]"
218218
if span_streaming:
219219
segment: "Optional[StreamedSpan]" = None
220+
sentry_scope.set_custom_sampling_context({"asgi_scope": scope})
220221
if ty in ("http", "websocket"):
221222
if (
222223
ty == "websocket"

sentry_sdk/integrations/redis/_sync_common.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,20 @@ def sentry_patched_execute_command(
134134
)
135135
db_span.__enter__()
136136

137-
set_db_data_fn(db_span, self)
138-
_set_client_data(db_span, is_cluster, name, *args)
137+
with capture_internal_exceptions():
138+
set_db_data_fn(db_span, self)
139+
_set_client_data(db_span, is_cluster, name, *args)
139140

140-
value = old_execute_command(self, name, *args, **kwargs)
141+
try:
142+
value = old_execute_command(self, name, *args, **kwargs)
143+
finally:
144+
db_span.__exit__(None, None, None)
141145

142-
db_span.__exit__(None, None, None)
146+
if cache_span:
147+
with capture_internal_exceptions():
148+
_set_cache_data(cache_span, self, cache_properties, value)
143149

144-
if cache_span:
145-
_set_cache_data(cache_span, self, cache_properties, value)
146-
cache_span.__exit__(None, None, None)
150+
cache_span.__exit__(None, None, None)
147151

148152
return value
149153

sentry_sdk/integrations/redis/utils.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,14 @@ def _set_pipeline_data(
149149
def _set_client_data(
150150
span: "Union[Span, StreamedSpan]", is_cluster: bool, name: str, *args: "Any"
151151
) -> None:
152-
if name:
153-
if isinstance(span, StreamedSpan):
154-
span.set_attribute("redis.is_cluster", is_cluster)
152+
if isinstance(span, StreamedSpan):
153+
span.set_attribute("redis.is_cluster", is_cluster)
154+
if name:
155155
span.set_attribute("redis.command", name)
156156
span.set_attribute(SPANDATA.DB_OPERATION, name)
157-
else:
158-
span.set_tag("redis.is_cluster", is_cluster)
157+
else:
158+
span.set_tag("redis.is_cluster", is_cluster)
159+
if name:
159160
span.set_tag("redis.command", name)
160161
span.set_tag(SPANDATA.DB_OPERATION, name)
161162

sentry_sdk/integrations/rust_tracing.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ def on_new_span(self, attrs: str, span_id: str) -> "TraceState":
218218
)
219219
sentry_span.set_op("function")
220220
sentry_span.set_origin(self.origin)
221+
sentry_span.start()
221222
else:
222223
sentry_span = parent_sentry_span.start_child(
223224
op="function",
@@ -233,6 +234,7 @@ def on_new_span(self, attrs: str, span_id: str) -> "TraceState":
233234
)
234235
sentry_span.set_op("function")
235236
sentry_span.set_origin(self.origin)
237+
sentry_span.start()
236238
else:
237239
sentry_span = sentry_sdk.start_span(
238240
op="function",
@@ -260,7 +262,10 @@ def on_close(self, span_id: str, span_state: "TraceState") -> None:
260262
return
261263

262264
parent_sentry_span, sentry_span = span_state
263-
sentry_span.finish()
265+
if isinstance(sentry_span, StreamedSpan):
266+
sentry_span.end()
267+
else:
268+
sentry_span.finish()
264269
sentry_sdk.get_current_scope().span = parent_sentry_span
265270

266271
def on_record(self, span_id: str, values: str, span_state: "TraceState") -> None:

sentry_sdk/integrations/strawberry.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ async def resolve(
315315
span = sentry_sdk.traces.start_span(
316316
parent_span=self.graphql_span, name=f"resolving {field_path}"
317317
)
318+
span.set_op(OP.GRAPHQL_RESOLVE)
319+
span.set_origin(StrawberryIntegration.origin)
318320
span.set_attribute("graphql.field_name", info.field_name)
319321
span.set_attribute("graphql.parent_type", info.parent_type.name)
320322
span.set_attribute("graphql.field_path", field_path)

sentry_sdk/scope.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ def _update_sample_rate_from_segment(self, span: "StreamedSpan") -> None:
13021302
propagation_context = self.get_active_propagation_context()
13031303
baggage = propagation_context.baggage
13041304

1305-
if baggage is not None:
1305+
if baggage is not None and span.sample_rate is not None:
13061306
baggage.sentry_items["sample_rate"] = str(span.sample_rate)
13071307

13081308
def continue_trace(

sentry_sdk/traces.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def _end(
436436
self.timestamp = datetime.now(timezone.utc)
437437

438438
if self.segment.sampled: # XXX this should just use its own sampled
439-
sentry_sdk.get_current_scope()._capture_span(self)
439+
scope._capture_span(self)
440440

441441
self._finished = True
442442

@@ -764,6 +764,13 @@ def set_source(self, source: "Union[str, SegmentSource]") -> None:
764764
def is_segment(self) -> bool:
765765
return False
766766

767+
def to_traceparent(self) -> str:
768+
propagation_context = (
769+
sentry_sdk.get_current_scope().get_active_propagation_context()
770+
)
771+
772+
return f"{propagation_context.trace_id}-{propagation_context.span_id}-0"
773+
767774
@property
768775
def span_id(self) -> str:
769776
return "000000"

sentry_sdk/tracing_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ def populate_from_segment(cls, segment: "StreamedSpan") -> "Baggage":
816816
if (
817817
segment.get_attributes().get("sentry.span.source")
818818
not in LOW_QUALITY_SEGMENT_SOURCES
819-
):
819+
) and segment._name:
820820
sentry_items["transaction"] = segment._name
821821

822822
if segment.sample_rate is not None:

0 commit comments

Comments
 (0)