Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2348,7 +2348,7 @@ By: @mgaligniana (#1773)
await ctx['session'].aclose()

async def main():
with sentry_sdk.start_transaction(name="testing_arq_tasks", source=TransactionSource.COMPONENT.value):
with sentry_sdk.start_transaction(name="testing_arq_tasks", source=TransactionSource.COMPONENT):
redis = await create_pool(RedisSettings())
for url in ('https://facebook.com', 'https://microsoft.com', 'https://github.com', "asdf"
):
Expand Down Expand Up @@ -2434,7 +2434,7 @@ By: @mgaligniana (#1773)
traces_sample_rate=1.0,
)

with sentry_sdk.start_transaction(name="testing_huey_tasks", source=TransactionSource.COMPONENT.value):
with sentry_sdk.start_transaction(name="testing_huey_tasks", source=TransactionSource.COMPONENT):
r = add_numbers(1, 2)

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async def sentry_app_handle(self, request, *args, **kwargs):
# If this transaction name makes it to the UI, AIOHTTP's
# URL resolver did not find a route or died trying.
name="generic AIOHTTP request",
source=TransactionSource.ROUTE.value,
source=TransactionSource.ROUTE,
origin=AioHttpIntegration.origin,
)
with sentry_sdk.start_transaction(
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/arq.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async def _sentry_run_job(self, job_id, score):
name="unknown arq task",
status="ok",
op=OP.QUEUE_TASK_ARQ,
source=TransactionSource.TASK.value,
source=TransactionSource.TASK,
origin=ArqIntegration.origin,
)

Expand Down
12 changes: 6 additions & 6 deletions sentry_sdk/integrations/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ def event_processor(self, event, hint, asgi_scope):
already_set = event["transaction"] != _DEFAULT_TRANSACTION_NAME and event[
"transaction_info"
].get("source") in [
TransactionSource.COMPONENT.value,
TransactionSource.ROUTE.value,
TransactionSource.CUSTOM.value,
TransactionSource.COMPONENT,
TransactionSource.ROUTE,
TransactionSource.CUSTOM,
]
if not already_set:
name, source = self._get_transaction_name_and_source(
Expand Down Expand Up @@ -310,7 +310,7 @@ def _get_transaction_name_and_source(self, transaction_style, asgi_scope):
name = transaction_from_function(endpoint) or ""
else:
name = _get_url(asgi_scope, "http" if ty == "http" else "ws", host=None)
source = TransactionSource.URL.value
source = TransactionSource.URL

elif transaction_style == "url":
# FastAPI includes the route object in the scope to let Sentry extract the
Expand All @@ -322,11 +322,11 @@ def _get_transaction_name_and_source(self, transaction_style, asgi_scope):
name = path
else:
name = _get_url(asgi_scope, "http" if ty == "http" else "ws", host=None)
source = TransactionSource.URL.value
source = TransactionSource.URL

if name is None:
name = _DEFAULT_TRANSACTION_NAME
source = TransactionSource.ROUTE.value
source = TransactionSource.ROUTE
return name, source

return name, source
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/aws_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def sentry_handler(aws_event, aws_context, *args, **kwargs):
headers,
op=OP.FUNCTION_AWS,
name=aws_context.function_name,
source=TransactionSource.COMPONENT.value,
source=TransactionSource.COMPONENT,
origin=AwsLambdaIntegration.origin,
)
with sentry_sdk.start_transaction(
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/celery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def _inner(*args, **kwargs):
headers,
op=OP.QUEUE_TASK_CELERY,
name="unknown celery task",
source=TransactionSource.TASK.value,
source=TransactionSource.TASK,
origin=CeleryIntegration.origin,
)
transaction.name = task.name
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/chalice.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def wrapped_view_function(**function_args):
configured_time = app.lambda_context.get_remaining_time_in_millis()
scope.set_transaction_name(
app.lambda_context.function_name,
source=TransactionSource.COMPONENT.value,
source=TransactionSource.COMPONENT,
)

scope.add_event_processor(
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def _set_transaction_name_and_source(scope, transaction_style, request):

if transaction_name is None:
transaction_name = request.path_info
source = TransactionSource.URL.value
source = TransactionSource.URL
else:
source = SOURCE_FOR_STYLE[transaction_style]

Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _set_transaction_name_and_source(scope, transaction_style, request):

if not name:
name = _DEFAULT_TRANSACTION_NAME
source = TransactionSource.ROUTE.value
source = TransactionSource.ROUTE
else:
source = SOURCE_FOR_STYLE[transaction_style]

Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def sentry_func(functionhandler, gcp_event, *args, **kwargs):
headers,
op=OP.FUNCTION_GCP,
name=environ.get("FUNCTION_NAME", ""),
source=TransactionSource.COMPONENT.value,
source=TransactionSource.COMPONENT,
origin=GcpIntegration.origin,
)
sampling_context = {
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/grpc/aio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def wrapped(request, context):
dict(context.invocation_metadata()),
op=OP.GRPC_SERVER,
name=name,
source=TransactionSource.CUSTOM.value,
source=TransactionSource.CUSTOM,
origin=SPAN_ORIGIN,
)

Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/grpc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def behavior(request, context):
metadata,
op=OP.GRPC_SERVER,
name=name,
source=TransactionSource.CUSTOM.value,
source=TransactionSource.CUSTOM,
origin=SPAN_ORIGIN,
)

Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/huey.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _sentry_execute(self, task, timestamp=None):
sentry_headers or {},
name=task.name,
op=OP.QUEUE_TASK_HUEY,
source=TransactionSource.TASK.value,
source=TransactionSource.TASK,
origin=HueyIntegration.origin,
)
transaction.set_status(SPANSTATUS.OK)
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/litestar.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def event_processor(event, _):

if not tx_name:
tx_name = _DEFAULT_TRANSACTION_NAME
tx_info = {"source": TransactionSource.ROUTE.value}
tx_info = {"source": TransactionSource.ROUTE}

event.update(
{
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _f(*f_args, _tracing=None, **f_kwargs):
op=OP.QUEUE_TASK_RAY,
name=qualname_from_function(f),
origin=RayIntegration.origin,
source=TransactionSource.TASK.value,
source=TransactionSource.TASK,
)

with sentry_sdk.start_transaction(transaction) as transaction:
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/rq.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def sentry_patched_perform_job(self, job, *args, **kwargs):
job.meta.get("_sentry_trace_headers") or {},
op=OP.QUEUE_TASK_RQ,
name="unknown RQ task",
source=TransactionSource.TASK.value,
source=TransactionSource.TASK,
origin=RqIntegration.origin,
)

Expand Down
8 changes: 4 additions & 4 deletions sentry_sdk/integrations/sanic.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ async def _context_enter(request):
op=OP.HTTP_SERVER,
# Unless the request results in a 404 error, the name and source will get overwritten in _set_transaction
name=request.path,
source=TransactionSource.URL.value,
source=TransactionSource.URL,
origin=SanicIntegration.origin,
)
request.ctx._sentry_transaction = sentry_sdk.start_transaction(
Expand Down Expand Up @@ -230,7 +230,7 @@ async def _set_transaction(request, route, **_):
scope = sentry_sdk.get_current_scope()
route_name = route.name.replace(request.app.name, "").strip(".")
scope.set_transaction_name(
route_name, source=TransactionSource.COMPONENT.value
route_name, source=TransactionSource.COMPONENT
)


Expand Down Expand Up @@ -306,11 +306,11 @@ def _legacy_router_get(self, *args):
sanic_route = sanic_route[len(sanic_app_name) + 1 :]

scope.set_transaction_name(
sanic_route, source=TransactionSource.COMPONENT.value
sanic_route, source=TransactionSource.COMPONENT
)
else:
scope.set_transaction_name(
rv[0].__name__, source=TransactionSource.COMPONENT.value
rv[0].__name__, source=TransactionSource.COMPONENT
)

return rv
Expand Down
6 changes: 3 additions & 3 deletions sentry_sdk/integrations/starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ def _set_transaction_name_and_source(scope, transaction_style, request):

if name is None:
name = _DEFAULT_TRANSACTION_NAME
source = TransactionSource.ROUTE.value
source = TransactionSource.ROUTE

scope.set_transaction_name(name, source=source)
logger.debug(
Expand All @@ -728,9 +728,9 @@ def _get_transaction_from_middleware(app, asgi_scope, integration):

if integration.transaction_style == "endpoint":
name = transaction_from_function(app.__class__)
source = TransactionSource.COMPONENT.value
source = TransactionSource.COMPONENT
elif integration.transaction_style == "url":
name = _transaction_name_from_router(asgi_scope)
source = TransactionSource.ROUTE.value
source = TransactionSource.ROUTE

return name, source
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/starlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def event_processor(event, _):

if not tx_name:
tx_name = _DEFAULT_TRANSACTION_NAME
tx_info = {"source": TransactionSource.ROUTE.value}
tx_info = {"source": TransactionSource.ROUTE}

event.update(
{
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/strawberry.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def on_operation(self):
transaction = self.graphql_span.containing_transaction
if transaction and self.execution_context.operation_name:
transaction.name = self.execution_context.operation_name
transaction.source = TransactionSource.COMPONENT.value
transaction.source = TransactionSource.COMPONENT
transaction.op = op

self.graphql_span.finish()
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def _handle_request_impl(self):
# sentry_urldispatcher_resolve is responsible for
# setting a transaction name later.
name="generic Tornado request",
source=TransactionSource.ROUTE.value,
source=TransactionSource.ROUTE,
origin=TornadoIntegration.origin,
)

Expand Down Expand Up @@ -157,7 +157,7 @@ def tornado_processor(event, hint):
with capture_internal_exceptions():
method = getattr(handler, handler.request.method.lower())
event["transaction"] = transaction_from_function(method) or ""
event["transaction_info"] = {"source": TransactionSource.COMPONENT.value}
event["transaction_info"] = {"source": TransactionSource.COMPONENT}

with capture_internal_exceptions():
extractor = TornadoRequestExtractor(request)
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __call__(self, environ, start_response):
environ,
op=OP.HTTP_SERVER,
name="generic WSGI request",
source=TransactionSource.ROUTE.value,
source=TransactionSource.ROUTE,
origin=self.span_origin,
)

Expand Down
8 changes: 4 additions & 4 deletions sentry_sdk/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@

GOOD_TRANSACTION_SOURCES = frozenset(
[
TransactionSource.ROUTE.value,
TransactionSource.VIEW.value,
TransactionSource.COMPONENT.value,
TransactionSource.TASK.value,
TransactionSource.ROUTE,
TransactionSource.VIEW,
TransactionSource.COMPONENT,
TransactionSource.TASK,
]
)

Expand Down
33 changes: 18 additions & 15 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,30 +131,33 @@ class TransactionKwargs(SpanKwargs, total=False):

# Transaction source
# see https://develop.sentry.dev/sdk/event-payloads/transaction/#transaction-annotations
class TransactionSource(Enum):
class TransactionSource(str, Enum):
COMPONENT = "component"
CUSTOM = "custom"
URL = "url"
ROUTE = "route"
VIEW = "view"
COMPONENT = "component"
TASK = "task"
URL = "url"
VIEW = "view"

def __str__(self):
return self.value
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see this! Thanks for the explanation!



# These are typically high cardinality and the server hates them
LOW_QUALITY_TRANSACTION_SOURCES = [
TransactionSource.URL.value,
TransactionSource.URL,
]

SOURCE_FOR_STYLE = {
"endpoint": TransactionSource.COMPONENT.value,
"function_name": TransactionSource.COMPONENT.value,
"handler_name": TransactionSource.COMPONENT.value,
"method_and_path_pattern": TransactionSource.ROUTE.value,
"path": TransactionSource.URL.value,
"route_name": TransactionSource.COMPONENT.value,
"route_pattern": TransactionSource.ROUTE.value,
"uri_template": TransactionSource.ROUTE.value,
"url": TransactionSource.ROUTE.value,
"endpoint": TransactionSource.COMPONENT,
"function_name": TransactionSource.COMPONENT,
"handler_name": TransactionSource.COMPONENT,
"method_and_path_pattern": TransactionSource.ROUTE,
"path": TransactionSource.URL,
"route_name": TransactionSource.COMPONENT,
"route_pattern": TransactionSource.ROUTE,
"uri_template": TransactionSource.ROUTE,
"url": TransactionSource.ROUTE,
}


Expand Down Expand Up @@ -782,7 +785,7 @@ def __init__( # type: ignore[misc]
name="", # type: str
parent_sampled=None, # type: Optional[bool]
baggage=None, # type: Optional[Baggage]
source=TransactionSource.CUSTOM.value, # type: str
source=TransactionSource.CUSTOM, # type: str
**kwargs, # type: Unpack[SpanKwargs]
):
# type: (...) -> None
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/asgi/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async def app(scope, receive, send):
def asgi3_custom_transaction_app():
async def app(scope, receive, send):
sentry_sdk.get_current_scope().set_transaction_name(
"foobar", source=TransactionSource.CUSTOM.value
"foobar", source=TransactionSource.CUSTOM
)
await send(
{
Expand Down
6 changes: 3 additions & 3 deletions tests/integrations/sanic/test_sanic.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,15 @@ def __init__(
url="/message",
expected_status=200,
expected_transaction_name="hi",
expected_source=TransactionSource.COMPONENT.value,
expected_source=TransactionSource.COMPONENT,
),
TransactionTestConfig(
# Transaction still recorded when we have an internal server error
integration_args=(),
url="/500",
expected_status=500,
expected_transaction_name="fivehundred",
expected_source=TransactionSource.COMPONENT.value,
expected_source=TransactionSource.COMPONENT,
),
TransactionTestConfig(
# By default, no transaction when we have a 404 error
Expand All @@ -393,7 +393,7 @@ def __init__(
url="/404",
expected_status=404,
expected_transaction_name="/404",
expected_source=TransactionSource.URL.value,
expected_source=TransactionSource.URL,
),
TransactionTestConfig(
# Transaction can be suppressed for other HTTP statuses, too, by passing config to the integration
Expand Down
Loading
Loading