We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b66c3d3 commit 03dc2caCopy full SHA for 03dc2ca
sentry_sdk/integrations/asgi.py
@@ -217,6 +217,7 @@ async def _run_app(
217
span_ctx: "ContextManager[Union[Span, StreamedSpan, None]]"
218
if span_streaming:
219
segment: "Optional[StreamedSpan]" = None
220
+ sentry_scope.set_custom_sampling_context({"asgi_scope": scope})
221
if ty in ("http", "websocket"):
222
if (
223
ty == "websocket"
sentry_sdk/integrations/redis/_sync_common.py
@@ -134,16 +134,20 @@ def sentry_patched_execute_command(
134
)
135
db_span.__enter__()
136
137
- set_db_data_fn(db_span, self)
138
- _set_client_data(db_span, is_cluster, name, *args)
+ with capture_internal_exceptions():
+ set_db_data_fn(db_span, self)
139
+ _set_client_data(db_span, is_cluster, name, *args)
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)
145
- db_span.__exit__(None, None, None)
146
+ if cache_span:
147
148
+ _set_cache_data(cache_span, self, cache_properties, value)
149
- if cache_span:
- _set_cache_data(cache_span, self, cache_properties, value)
- cache_span.__exit__(None, None, None)
150
+ cache_span.__exit__(None, None, None)
151
152
return value
153
sentry_sdk/integrations/redis/utils.py
@@ -149,13 +149,14 @@ def _set_pipeline_data(
def _set_client_data(
span: "Union[Span, StreamedSpan]", is_cluster: bool, name: str, *args: "Any"
) -> None:
- if name:
- if isinstance(span, StreamedSpan):
154
- span.set_attribute("redis.is_cluster", is_cluster)
+ if isinstance(span, StreamedSpan):
+ span.set_attribute("redis.is_cluster", is_cluster)
+ if name:
155
span.set_attribute("redis.command", name)
156
span.set_attribute(SPANDATA.DB_OPERATION, name)
157
- else:
158
- span.set_tag("redis.is_cluster", is_cluster)
+ else:
+ span.set_tag("redis.is_cluster", is_cluster)
159
160
span.set_tag("redis.command", name)
161
span.set_tag(SPANDATA.DB_OPERATION, name)
162
sentry_sdk/integrations/rust_tracing.py
@@ -218,6 +218,7 @@ def on_new_span(self, attrs: str, span_id: str) -> "TraceState":
sentry_span.set_op("function")
sentry_span.set_origin(self.origin)
+ sentry_span.start()
else:
sentry_span = parent_sentry_span.start_child(
224
op="function",
@@ -233,6 +234,7 @@ def on_new_span(self, attrs: str, span_id: str) -> "TraceState":
233
234
235
236
237
238
239
sentry_span = sentry_sdk.start_span(
240
@@ -260,7 +262,10 @@ def on_close(self, span_id: str, span_state: "TraceState") -> None:
260
262
return
261
263
264
parent_sentry_span, sentry_span = span_state
- sentry_span.finish()
265
+ if isinstance(sentry_span, StreamedSpan):
266
+ sentry_span.end()
267
268
+ sentry_span.finish()
269
sentry_sdk.get_current_scope().span = parent_sentry_span
270
271
def on_record(self, span_id: str, values: str, span_state: "TraceState") -> None:
sentry_sdk/integrations/strawberry.py
@@ -315,6 +315,8 @@ async def resolve(
315
span = sentry_sdk.traces.start_span(
316
parent_span=self.graphql_span, name=f"resolving {field_path}"
317
318
+ span.set_op(OP.GRAPHQL_RESOLVE)
319
+ span.set_origin(StrawberryIntegration.origin)
320
span.set_attribute("graphql.field_name", info.field_name)
321
span.set_attribute("graphql.parent_type", info.parent_type.name)
322
span.set_attribute("graphql.field_path", field_path)
sentry_sdk/scope.py
@@ -1302,7 +1302,7 @@ def _update_sample_rate_from_segment(self, span: "StreamedSpan") -> None:
1302
propagation_context = self.get_active_propagation_context()
1303
baggage = propagation_context.baggage
1304
1305
- if baggage is not None:
+ if baggage is not None and span.sample_rate is not None:
1306
baggage.sentry_items["sample_rate"] = str(span.sample_rate)
1307
1308
def continue_trace(
sentry_sdk/traces.py
@@ -436,7 +436,7 @@ def _end(
436
self.timestamp = datetime.now(timezone.utc)
437
438
if self.segment.sampled: # XXX this should just use its own sampled
439
- sentry_sdk.get_current_scope()._capture_span(self)
+ scope._capture_span(self)
440
441
self._finished = True
442
@@ -764,6 +764,13 @@ def set_source(self, source: "Union[str, SegmentSource]") -> None:
764
def is_segment(self) -> bool:
765
return False
766
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
774
@property
775
def span_id(self) -> str:
776
return "000000"
sentry_sdk/tracing_utils.py
@@ -816,7 +816,7 @@ def populate_from_segment(cls, segment: "StreamedSpan") -> "Baggage":
816
817
segment.get_attributes().get("sentry.span.source")
818
not in LOW_QUALITY_SEGMENT_SOURCES
819
- ):
+ ) and segment._name:
820
sentry_items["transaction"] = segment._name
821
822
if segment.sample_rate is not None:
0 commit comments