Skip to content

Fix scope transaction source not being updated in scope.span setter #2519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 10 additions & 1 deletion tests/tracing/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"}