Skip to content

Commit 7fb4863

Browse files
committed
.
1 parent a39337b commit 7fb4863

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

sentry_sdk/integrations/asgi.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,24 @@ async def _sentry_wrapped_send(
362362
reraise(*exc_info)
363363

364364
finally:
365-
with capture_internal_exceptions():
366-
name, source = self._get_segment_name_and_source(
367-
self.transaction_style, scope
365+
if isinstance(span, StreamedSpan):
366+
already_set = (
367+
span is not None
368+
and span.name != _DEFAULT_TRANSACTION_NAME
369+
and span.get_attributes().get("sentry.span.source")
370+
in [
371+
SegmentSource.COMPONENT.value,
372+
SegmentSource.ROUTE.value,
373+
SegmentSource.CUSTOM.value,
374+
]
368375
)
369-
if isinstance(span, StreamedSpan):
370-
span.name = name
371-
span.set_attribute("sentry.span.source", source)
376+
with capture_internal_exceptions():
377+
if not already_set:
378+
name, source = self._get_segment_name_and_source(
379+
self.transaction_style, scope
380+
)
381+
span.name = name
382+
span.set_attribute("sentry.span.source", source)
372383
finally:
373384
_asgi_middleware_applied.set(False)
374385

sentry_sdk/traces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ def __init__(
259259
self._name: str = name
260260
self._active: bool = active
261261
self._attributes: "Attributes" = {}
262+
262263
if attributes:
263264
for attribute, value in attributes.items():
264265
self.set_attribute(attribute, value)
@@ -287,7 +288,6 @@ def __init__(
287288
self._span_id: "Optional[str]" = None
288289

289290
self._status = SpanStatus.OK.value
290-
self.set_attribute("sentry.span.source", SegmentSource.CUSTOM.value)
291291

292292
self._update_active_thread()
293293

tests/conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,12 @@ class UnwrappedItem:
329329

330330
@pytest.fixture
331331
def capture_items(monkeypatch):
332-
"""Capture envelope payload, unfurling individual items."""
332+
"""
333+
Capture envelope payload, unfurling individual items.
334+
335+
Makes it easier to work with both events and attribute-based telemetry in
336+
one test.
337+
"""
333338

334339
def inner(*types):
335340
telemetry = []

0 commit comments

Comments
 (0)