Skip to content

Commit 71a6728

Browse files
committed
fix source and txn name
1 parent ba5a988 commit 71a6728

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

sentry_sdk/integrations/celery/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,6 @@ def _inner(*args: "Any", **kwargs: "Any") -> "Any":
339339
}
340340
}
341341

342-
scope.set_transaction_name(task.name, source=TransactionSource.TASK)
343-
344342
span: "Union[Span, StreamedSpan]"
345343
span_ctx: "Union[StreamedSpan, Span, NoOpMgr]" = NoOpMgr()
346344

sentry_sdk/scope.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,19 @@ def span(self, span: "Optional[Union[Span, StreamedSpan]]") -> None:
893893
if transaction.source:
894894
self._transaction_info["source"] = transaction.source
895895

896+
# Also set _transaction and _transaction_info in streaming mode as this
897+
# is used for populating events and linking them to segments
898+
if (
899+
isinstance(span, StreamedSpan)
900+
and not isinstance(span, NoOpStreamedSpan)
901+
and span._is_segment
902+
):
903+
self._transaction = span.name
904+
if span._attributes.get("sentry.span.source"):
905+
self._transaction_info["source"] = span._attributes[
906+
"sentry.span.source"
907+
]
908+
896909
@property
897910
def profile(self) -> "Optional[Profile]":
898911
return self._profile

tests/integrations/celery/test_celery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ def test_traces_sampler_gets_task_info_in_sampling_context(
522522
celery_invocation,
523523
DictionaryContaining, # noqa:N803
524524
):
525-
traces_sampler = mock.Mock()
525+
traces_sampler = mock.Mock(return_value=1.0)
526526
celery = init_celery(
527527
traces_sampler=traces_sampler,
528528
_experiments={"trace_lifecycle": "stream" if span_streaming else "static"},

0 commit comments

Comments
 (0)