Skip to content

Commit cf9c2d8

Browse files
authored
Remove TRANSACTION_SOURCE_UNKNOWN and default to CUSTOM (#1558)
Fixes #1557 see getsentry/develop#667 `unknown` is only supposed to be inferred by relay as a default and not set by any SDKs. Additionally, fix some of the other cases where start_transaction was begin called without a source in integrations.
1 parent 7a7f6d9 commit cf9c2d8

File tree

10 files changed

+22
-21
lines changed

10 files changed

+22
-21
lines changed

sentry_sdk/integrations/aiohttp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
_filter_headers,
1010
request_body_within_bounds,
1111
)
12-
from sentry_sdk.tracing import SOURCE_FOR_STYLE, Transaction
12+
from sentry_sdk.tracing import SOURCE_FOR_STYLE, Transaction, TRANSACTION_SOURCE_ROUTE
1313
from sentry_sdk.utils import (
1414
capture_internal_exceptions,
1515
event_from_exception,
@@ -103,6 +103,7 @@ async def sentry_app_handle(self, request, *args, **kwargs):
103103
# If this transaction name makes it to the UI, AIOHTTP's
104104
# URL resolver did not find a route or died trying.
105105
name="generic AIOHTTP request",
106+
source=TRANSACTION_SOURCE_ROUTE,
106107
)
107108
with hub.start_transaction(
108109
transaction, custom_sampling_context={"aiohttp_request": request}

sentry_sdk/integrations/rq.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from sentry_sdk.hub import Hub
66
from sentry_sdk.integrations import DidNotEnable, Integration
77
from sentry_sdk.integrations.logging import ignore_logger
8-
from sentry_sdk.tracing import Transaction
8+
from sentry_sdk.tracing import Transaction, TRANSACTION_SOURCE_TASK
99
from sentry_sdk.utils import capture_internal_exceptions, event_from_exception
1010

1111
try:
@@ -63,6 +63,7 @@ def sentry_patched_perform_job(self, job, *args, **kwargs):
6363
job.meta.get("_sentry_trace_headers") or {},
6464
op="rq.task",
6565
name="unknown RQ task",
66+
source=TRANSACTION_SOURCE_TASK,
6667
)
6768

6869
with capture_internal_exceptions():

sentry_sdk/integrations/starlette.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
request_body_within_bounds,
1313
)
1414
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
15-
from sentry_sdk.tracing import SOURCE_FOR_STYLE
15+
from sentry_sdk.tracing import SOURCE_FOR_STYLE, TRANSACTION_SOURCE_ROUTE
1616
from sentry_sdk.utils import (
17-
TRANSACTION_SOURCE_ROUTE,
1817
AnnotatedValue,
1918
capture_internal_exceptions,
2019
event_from_exception,

sentry_sdk/integrations/tornado.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
from inspect import iscoroutinefunction
44

55
from sentry_sdk.hub import Hub, _should_send_default_pii
6-
from sentry_sdk.tracing import TRANSACTION_SOURCE_COMPONENT, Transaction
6+
from sentry_sdk.tracing import (
7+
TRANSACTION_SOURCE_COMPONENT,
8+
TRANSACTION_SOURCE_ROUTE,
9+
Transaction,
10+
)
711
from sentry_sdk.utils import (
812
HAS_REAL_CONTEXTVARS,
913
CONTEXTVARS_ERROR_MESSAGE,
@@ -116,6 +120,7 @@ def _handle_request_impl(self):
116120
# sentry_urldispatcher_resolve is responsible for
117121
# setting a transaction name later.
118122
name="generic Tornado request",
123+
source=TRANSACTION_SOURCE_ROUTE,
119124
)
120125

121126
with hub.start_transaction(

sentry_sdk/integrations/wsgi.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
event_from_exception,
99
)
1010
from sentry_sdk._compat import PY2, reraise, iteritems
11-
from sentry_sdk.tracing import Transaction
11+
from sentry_sdk.tracing import Transaction, TRANSACTION_SOURCE_ROUTE
1212
from sentry_sdk.sessions import auto_session_tracking
1313
from sentry_sdk.integrations._wsgi_common import _filter_headers
1414
from sentry_sdk.profiler import profiling
@@ -123,7 +123,10 @@ def __call__(self, environ, start_response):
123123
)
124124

125125
transaction = Transaction.continue_from_environ(
126-
environ, op="http.server", name="generic WSGI request"
126+
environ,
127+
op="http.server",
128+
name="generic WSGI request",
129+
source=TRANSACTION_SOURCE_ROUTE,
127130
)
128131

129132
with hub.start_transaction(

sentry_sdk/tracing.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
TRANSACTION_SOURCE_VIEW = "view"
3535
TRANSACTION_SOURCE_COMPONENT = "component"
3636
TRANSACTION_SOURCE_TASK = "task"
37-
TRANSACTION_SOURCE_UNKNOWN = "unknown"
3837

3938
SOURCE_FOR_STYLE = {
4039
"endpoint": TRANSACTION_SOURCE_COMPONENT,
@@ -547,7 +546,7 @@ def __init__(
547546
sentry_tracestate=None, # type: Optional[str]
548547
third_party_tracestate=None, # type: Optional[str]
549548
baggage=None, # type: Optional[Baggage]
550-
source=TRANSACTION_SOURCE_UNKNOWN, # type: str
549+
source=TRANSACTION_SOURCE_CUSTOM, # type: str
551550
**kwargs # type: Any
552551
):
553552
# type: (...) -> None

sentry_sdk/utils.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,6 @@
4242
MAX_STRING_LENGTH = 512
4343
BASE64_ALPHABET = re.compile(r"^[a-zA-Z0-9/+=]*$")
4444

45-
# Transaction source
46-
# see https://develop.sentry.dev/sdk/event-payloads/transaction/#transaction-annotations
47-
TRANSACTION_SOURCE_CUSTOM = "custom"
48-
TRANSACTION_SOURCE_URL = "url"
49-
TRANSACTION_SOURCE_ROUTE = "route"
50-
TRANSACTION_SOURCE_VIEW = "view"
51-
TRANSACTION_SOURCE_COMPONENT = "component"
52-
TRANSACTION_SOURCE_TASK = "task"
53-
TRANSACTION_SOURCE_UNKNOWN = "unknown"
54-
5545

5646
def json_dumps(data):
5747
# type: (Any) -> bytes

tests/integrations/celery/test_celery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def dummy_task(x, y):
159159
assert execution_event["transaction_info"] == {"source": "task"}
160160

161161
assert submission_event["transaction"] == "submission"
162-
assert submission_event["transaction_info"] == {"source": "unknown"}
162+
assert submission_event["transaction_info"] == {"source": "custom"}
163163

164164
assert execution_event["type"] == submission_event["type"] == "transaction"
165165
assert execution_event["contexts"]["trace"]["trace_id"] == transaction.trace_id

tests/integrations/tornado/test_tornado.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def test_transactions(tornado_testcase, sentry_init, capture_events, handler, co
131131
assert client_tx["type"] == "transaction"
132132
assert client_tx["transaction"] == "client"
133133
assert client_tx["transaction_info"] == {
134-
"source": "unknown"
134+
"source": "custom"
135135
} # because this is just the start_transaction() above.
136136

137137
if server_error is not None:

tests/tracing/test_integration_tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ def test_basic(sentry_init, capture_events, sample_rate):
3232
assert len(events) == 1
3333
event = events[0]
3434

35+
assert event["transaction"] == "hi"
36+
assert event["transaction_info"]["source"] == "custom"
37+
3538
span1, span2 = event["spans"]
3639
parent_span = event
3740
assert span1["tags"]["status"] == "internal_error"

0 commit comments

Comments
 (0)