From fe079c8c5a9f913f4051599b94739e859bee1339 Mon Sep 17 00:00:00 2001 From: Neel Shah Date: Tue, 21 Nov 2023 12:51:37 +0100 Subject: [PATCH] Fix scope transaction source not being updated in scope.span setter --- sentry_sdk/scope.py | 2 ++ tests/tracing/test_misc.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index b9071cc694..d64e66711d 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -430,6 +430,8 @@ def span(self, span): transaction = span if transaction.name: self._transaction = transaction.name + if transaction.source: + self._transaction_info["source"] = transaction.source @property def profile(self): diff --git a/tests/tracing/test_misc.py b/tests/tracing/test_misc.py index 01bf1c1b07..3668f1b3a8 100644 --- a/tests/tracing/test_misc.py +++ b/tests/tracing/test_misc.py @@ -4,7 +4,7 @@ import os import sentry_sdk -from sentry_sdk import Hub, start_span, start_transaction, set_measurement +from sentry_sdk import Hub, start_span, start_transaction, set_measurement, push_scope from sentry_sdk.consts import MATCH_ALL from sentry_sdk.tracing import Span, Transaction from sentry_sdk.tracing_utils import should_propagate_trace @@ -357,3 +357,12 @@ def test_should_propagate_trace_to_sentry( Hub.current.client.transport.parsed_dsn = Dsn(dsn) assert should_propagate_trace(Hub.current, url) == expected_propagation_decision + + +def test_start_transaction_updates_scope_name_source(sentry_init): + sentry_init(traces_sample_rate=1.0) + + with push_scope() as scope: + with start_transaction(name="foobar", source="route"): + assert scope._transaction == "foobar" + assert scope._transaction_info == {"source": "route"}