Skip to content
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

Unified naming for span ops #1661

Merged
merged 15 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,26 @@ def _get_default_options():
"version": VERSION,
"packages": [{"name": "pypi:sentry-sdk", "version": VERSION}],
}


class OP:
ASGI_SERVER = "asgi.server"
DB = "db"
DB_REDIS = "db.redis"
EVENT_DJANGO = "event.django"
FUNCTION_AWS_LAMBDA = "function.aws.lambda"
FUNCTION_GCP = "function.gcp"
HTTP_CLIENT = "http.client"
HTTP_CLIENT_STREAM = "http.client.stream"
HTTP_SERVER = "http.server"
MIDDLEWARE_DJANGO = "middleware.django"
MIDDLEWARE_STARLETTE = "middleware.starlette"
QUEUE_SUBMIT_CELERY = "queue.submit.celery"
QUEUE_TASK_CELERY = "queue.task.celery"
QUEUE_TASK_RQ = "queue.task.rq"
SUBPROCESS = "subprocess"
SUBPROCESS_WAIT = "subprocess.wait"
SUBPROCESS_COMMUNICATE = "subprocess.communicate"
TEMPLATE_RENDER = "template.render"
VIEW_DJANGO = "view.django"
WEBSOCKET_SERVER = "websocket.server"
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import weakref

from sentry_sdk._compat import reraise
from sentry_sdk.consts import OP
from sentry_sdk.hub import Hub
from sentry_sdk.integrations import Integration, DidNotEnable
from sentry_sdk.integrations.logging import ignore_logger
Expand Down Expand Up @@ -99,7 +100,7 @@ async def sentry_app_handle(self, request, *args, **kwargs):

transaction = Transaction.continue_from_headers(
request.headers,
op="http.server",
op=OP.HTTP_SERVER,
# 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",
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from sentry_sdk._functools import partial
from sentry_sdk._types import MYPY
from sentry_sdk.consts import OP
from sentry_sdk.hub import Hub, _should_send_default_pii
from sentry_sdk.integrations._wsgi_common import _filter_headers
from sentry_sdk.integrations.modules import _get_installed_modules
Expand Down Expand Up @@ -166,7 +167,7 @@ async def _run_app(self, scope, callback):
op="{}.server".format(ty),
)
else:
transaction = Transaction(op="asgi.server")
transaction = Transaction(op=OP.ASGI_SERVER)

transaction.name = _DEFAULT_TRANSACTION_NAME
transaction.source = TRANSACTION_SOURCE_ROUTE
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/aws_lambda.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime, timedelta
from os import environ
import sys
from sentry_sdk.consts import OP

from sentry_sdk.hub import Hub, _should_send_default_pii
from sentry_sdk.tracing import TRANSACTION_SOURCE_COMPONENT, Transaction
Expand Down Expand Up @@ -140,7 +141,7 @@ def sentry_handler(aws_event, aws_context, *args, **kwargs):
headers = {}
transaction = Transaction.continue_from_headers(
headers,
op="serverless.function",
op=OP.FUNCTION_AWS_LAMBDA,
name=aws_context.function_name,
source=TRANSACTION_SOURCE_COMPONENT,
)
Expand Down
5 changes: 3 additions & 2 deletions sentry_sdk/integrations/boto3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import

from sentry_sdk import Hub
from sentry_sdk.consts import OP
from sentry_sdk.integrations import Integration, DidNotEnable
from sentry_sdk.tracing import Span

Expand Down Expand Up @@ -62,7 +63,7 @@ def _sentry_request_created(service_id, request, operation_name, **kwargs):
description = "aws.%s.%s" % (service_id, operation_name)
span = hub.start_span(
hub=hub,
op="aws.request",
op=OP.HTTP_CLIENT,
description=description,
)
span.set_tag("aws.service_id", service_id)
Expand Down Expand Up @@ -92,7 +93,7 @@ def _sentry_after_call(context, parsed, **kwargs):
return

streaming_span = span.start_child(
op="aws.request.stream",
op=OP.HTTP_CLIENT_STREAM,
description=span.description,
)

Expand Down
7 changes: 5 additions & 2 deletions sentry_sdk/integrations/celery.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import

import sys
from sentry_sdk.consts import OP

from sentry_sdk.hub import Hub
from sentry_sdk.tracing import TRANSACTION_SOURCE_TASK
Expand Down Expand Up @@ -103,7 +104,9 @@ def apply_async(*args, **kwargs):
hub = Hub.current
integration = hub.get_integration(CeleryIntegration)
if integration is not None and integration.propagate_traces:
with hub.start_span(op="celery.submit", description=args[0].name) as span:
with hub.start_span(
op=OP.QUEUE_SUBMIT_CELERY, description=args[0].name
) as span:
with capture_internal_exceptions():
headers = dict(hub.iter_trace_propagation_headers(span))

Expand Down Expand Up @@ -156,7 +159,7 @@ def _inner(*args, **kwargs):
with capture_internal_exceptions():
transaction = Transaction.continue_from_headers(
args[3].get("headers") or {},
op="celery.task",
op=OP.QUEUE_TASK_CELERY,
name="unknown celery task",
source=TRANSACTION_SOURCE_TASK,
)
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import weakref

from sentry_sdk._types import MYPY
from sentry_sdk.consts import OP
from sentry_sdk.hub import Hub, _should_send_default_pii
from sentry_sdk.scope import add_global_event_processor
from sentry_sdk.serializer import add_global_repr_processor
Expand Down Expand Up @@ -581,7 +582,7 @@ def connect(self):
with capture_internal_exceptions():
hub.add_breadcrumb(message="connect", category="query")

with hub.start_span(op="db", description="connect"):
with hub.start_span(op=OP.DB, description="connect"):
return real_connect(self)

CursorWrapper.execute = execute
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/django/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from sentry_sdk import Hub, _functools
from sentry_sdk._types import MYPY
from sentry_sdk.consts import OP

from sentry_sdk.integrations.asgi import SentryAsgiMiddleware

Expand Down Expand Up @@ -89,7 +90,7 @@ async def sentry_wrapped_callback(request, *args, **kwargs):
# type: (Any, *Any, **Any) -> Any

with hub.start_span(
op="django.view", description=request.resolver_match.view_name
op=OP.VIEW_DJANGO, description=request.resolver_match.view_name
):
return await callback(request, *args, **kwargs)

Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/django/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from sentry_sdk import Hub
from sentry_sdk._functools import wraps
from sentry_sdk._types import MYPY
from sentry_sdk.consts import OP
from sentry_sdk.utils import (
ContextVar,
transaction_from_function,
Expand Down Expand Up @@ -88,7 +89,7 @@ def _check_middleware_span(old_method):
description = "{}.{}".format(description, function_basename)

middleware_span = hub.start_span(
op="django.middleware", description=description
op=OP.MIDDLEWARE_DJANGO, description=description
)
middleware_span.set_tag("django.function_name", function_name)
middleware_span.set_tag("django.middleware_name", middleware_name)
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/django/signals_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from sentry_sdk import Hub
from sentry_sdk._types import MYPY
from sentry_sdk.consts import OP


if MYPY:
Expand Down Expand Up @@ -50,7 +51,7 @@ def wrapper(*args, **kwargs):
# type: (Any, Any) -> Any
signal_name = _get_receiver_name(receiver)
with hub.start_span(
op="django.signals",
op=OP.EVENT_DJANGO,
description=signal_name,
) as span:
span.set_data("signal", signal_name)
Expand Down
5 changes: 3 additions & 2 deletions sentry_sdk/integrations/django/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from sentry_sdk import _functools, Hub
from sentry_sdk._types import MYPY
from sentry_sdk.consts import OP

if MYPY:
from typing import Any
Expand Down Expand Up @@ -66,7 +67,7 @@ def rendered_content(self):
return real_rendered_content.fget(self)

with hub.start_span(
op="django.template.render",
op=OP.TEMPLATE_RENDER,
description=_get_template_name_description(self.template_name),
) as span:
span.set_data("context", self.context_data)
Expand All @@ -88,7 +89,7 @@ def render(request, template_name, context=None, *args, **kwargs):
return real_render(request, template_name, context, *args, **kwargs)

with hub.start_span(
op="django.template.render",
op=OP.TEMPLATE_RENDER,
description=_get_template_name_description(template_name),
) as span:
span.set_data("context", context)
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/django/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from sentry_sdk.consts import OP
from sentry_sdk.hub import Hub
from sentry_sdk._types import MYPY
from sentry_sdk import _functools
Expand Down Expand Up @@ -62,7 +63,7 @@ def _wrap_sync_view(hub, callback):
def sentry_wrapped_callback(request, *args, **kwargs):
# type: (Any, *Any, **Any) -> Any
with hub.start_span(
op="django.view", description=request.resolver_match.view_name
op=OP.VIEW_DJANGO, description=request.resolver_match.view_name
):
return callback(request, *args, **kwargs)

Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/gcp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime, timedelta
from os import environ
import sys
from sentry_sdk.consts import OP

from sentry_sdk.hub import Hub, _should_send_default_pii
from sentry_sdk.tracing import TRANSACTION_SOURCE_COMPONENT, Transaction
Expand Down Expand Up @@ -82,7 +83,7 @@ def sentry_func(functionhandler, gcp_event, *args, **kwargs):
headers = gcp_event.headers
transaction = Transaction.continue_from_headers(
headers,
op="serverless.function",
op=OP.FUNCTION_GCP,
name=environ.get("FUNCTION_NAME", ""),
source=TRANSACTION_SOURCE_COMPONENT,
)
Expand Down
5 changes: 3 additions & 2 deletions sentry_sdk/integrations/httpx.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from sentry_sdk import Hub
from sentry_sdk.consts import OP
from sentry_sdk.integrations import Integration, DidNotEnable
from sentry_sdk.utils import logger

Expand Down Expand Up @@ -41,7 +42,7 @@ def send(self, request, **kwargs):
return real_send(self, request, **kwargs)

with hub.start_span(
op="http", description="%s %s" % (request.method, request.url)
op=OP.HTTP_CLIENT, description="%s %s" % (request.method, request.url)
) as span:
span.set_data("method", request.method)
span.set_data("url", str(request.url))
Expand Down Expand Up @@ -73,7 +74,7 @@ async def send(self, request, **kwargs):
return await real_send(self, request, **kwargs)

with hub.start_span(
op="http", description="%s %s" % (request.method, request.url)
op=OP.HTTP_CLIENT, description="%s %s" % (request.method, request.url)
) as span:
span.set_data("method", request.method)
span.set_data("url", str(request.url))
Expand Down
7 changes: 5 additions & 2 deletions sentry_sdk/integrations/redis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import

from sentry_sdk import Hub
from sentry_sdk.consts import OP
from sentry_sdk.utils import capture_internal_exceptions, logger
from sentry_sdk.integrations import Integration, DidNotEnable

Expand Down Expand Up @@ -29,7 +30,9 @@ def sentry_patched_execute(self, *args, **kwargs):
if hub.get_integration(RedisIntegration) is None:
return old_execute(self, *args, **kwargs)

with hub.start_span(op="redis", description="redis.pipeline.execute") as span:
with hub.start_span(
op=OP.DB_REDIS, description="redis.pipeline.execute"
) as span:
with capture_internal_exceptions():
span.set_tag("redis.is_cluster", is_cluster)
transaction = self.transaction if not is_cluster else False
Expand Down Expand Up @@ -152,7 +155,7 @@ def sentry_patched_execute_command(self, name, *args, **kwargs):

description = " ".join(description_parts)

with hub.start_span(op="redis", description=description) as span:
with hub.start_span(op=OP.DB_REDIS, description=description) as span:
span.set_tag("redis.is_cluster", is_cluster)
if name:
span.set_tag("redis.command", name)
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/rq.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import

import weakref
from sentry_sdk.consts import OP

from sentry_sdk.hub import Hub
from sentry_sdk.integrations import DidNotEnable, Integration
Expand Down Expand Up @@ -61,7 +62,7 @@ def sentry_patched_perform_job(self, job, *args, **kwargs):

transaction = Transaction.continue_from_headers(
job.meta.get("_sentry_trace_headers") or {},
op="rq.task",
op=OP.QUEUE_TASK_RQ,
name="unknown RQ task",
source=TRANSACTION_SOURCE_TASK,
)
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from sentry_sdk._compat import iteritems
from sentry_sdk._types import MYPY
from sentry_sdk.consts import OP
from sentry_sdk.hub import Hub, _should_send_default_pii
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.integrations._wsgi_common import (
Expand Down Expand Up @@ -91,7 +92,7 @@ async def _create_span_call(*args, **kwargs):
if integration is not None:
middleware_name = args[0].__class__.__name__
with hub.start_span(
op="starlette.middleware", description=middleware_name
op=OP.MIDDLEWARE_STARLETTE, description=middleware_name
) as middleware_span:
middleware_span.set_tag("starlette.middleware_name", middleware_name)

Expand Down
11 changes: 7 additions & 4 deletions sentry_sdk/integrations/stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import subprocess
import sys
import platform
from sentry_sdk.consts import OP

from sentry_sdk.hub import Hub
from sentry_sdk.integrations import Integration
Expand Down Expand Up @@ -78,7 +79,9 @@ def putrequest(self, method, url, *args, **kwargs):
url,
)

span = hub.start_span(op="http", description="%s %s" % (method, real_url))
span = hub.start_span(
op=OP.HTTP_CLIENT, description="%s %s" % (method, real_url)
)

span.set_data("method", method)
span.set_data("url", real_url)
Expand Down Expand Up @@ -183,7 +186,7 @@ def sentry_patched_popen_init(self, *a, **kw):

env = None

with hub.start_span(op="subprocess", description=description) as span:
with hub.start_span(op=OP.SUBPROCESS, description=description) as span:

for k, v in hub.iter_trace_propagation_headers(span):
if env is None:
Expand Down Expand Up @@ -211,7 +214,7 @@ def sentry_patched_popen_wait(self, *a, **kw):
if hub.get_integration(StdlibIntegration) is None:
return old_popen_wait(self, *a, **kw)

with hub.start_span(op="subprocess.wait") as span:
with hub.start_span(op=OP.SUBPROCESS_WAIT) as span:
span.set_tag("subprocess.pid", self.pid)
return old_popen_wait(self, *a, **kw)

Expand All @@ -226,7 +229,7 @@ def sentry_patched_popen_communicate(self, *a, **kw):
if hub.get_integration(StdlibIntegration) is None:
return old_popen_communicate(self, *a, **kw)

with hub.start_span(op="subprocess.communicate") as span:
with hub.start_span(op=OP.SUBPROCESS_COMMUNICATE) as span:
span.set_tag("subprocess.pid", self.pid)
return old_popen_communicate(self, *a, **kw)

Expand Down