Skip to content

Commit c0ef3d0

Browse files
authored
Unified naming for span ops (#1661)
* Unified naming for span ops.
1 parent ec98b3e commit c0ef3d0

32 files changed

+160
-82
lines changed

CHANGELOG.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
# Changelog
22

3+
## 1.9.11
4+
5+
### Various fixes & improvements
6+
7+
- Unified naming of span "op"s (#1643) by @antonpirker
8+
9+
We have unified the strings of our span operations. See https://develop.sentry.dev/sdk/performance/span-operations/
10+
11+
**WARNING:** If you have dashboards defined that use `transaction.op` in their fields, conditions, aggregates or columns please check them before updating to this version of the SDK.
12+
13+
Here a list of all the changes:
14+
15+
| Old operation (`op`) | New Operation (`op`) |
16+
| ------------------------ | ---------------------- |
17+
| `asgi.server` | `http.server` |
18+
| `aws.request` | `http.client` |
19+
| `aws.request.stream` | `http.client.stream` |
20+
| `celery.submit` | `queue.submit.celery` |
21+
| `celery.task` | `queue.task.celery` |
22+
| `django.middleware` | `middleware.django` |
23+
| `django.signals` | `event.django` |
24+
| `django.template.render` | `template.render` |
25+
| `django.view` | `view.render` |
26+
| `http` | `http.client` |
27+
| `redis` | `db.redis` |
28+
| `rq.task` | `queue.task.rq` |
29+
| `serverless.function` | `function.aws` |
30+
| `serverless.function` | `function.gcp` |
31+
| `starlette.middleware` | `middleware.starlette` |
32+
333
## 1.9.10
434

535
### Various fixes & improvements
@@ -158,7 +188,7 @@ We can do better and in the future we will do our best to not break your code ag
158188

159189
- fix: avoid sending empty Baggage header (#1507) by @intgr
160190
- fix: properly freeze Baggage object (#1508) by @intgr
161-
- docs: fix simple typo, collecter -> collector (#1505) by @timgates42
191+
- docs: fix simple typo, collecter | collector (#1505) by @timgates42
162192

163193
## 1.7.2
164194

sentry_sdk/consts.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,25 @@ def _get_default_options():
110110
"version": VERSION,
111111
"packages": [{"name": "pypi:sentry-sdk", "version": VERSION}],
112112
}
113+
114+
115+
class OP:
116+
DB = "db"
117+
DB_REDIS = "db.redis"
118+
EVENT_DJANGO = "event.django"
119+
FUNCTION_AWS = "function.aws"
120+
FUNCTION_GCP = "function.gcp"
121+
HTTP_CLIENT = "http.client"
122+
HTTP_CLIENT_STREAM = "http.client.stream"
123+
HTTP_SERVER = "http.server"
124+
MIDDLEWARE_DJANGO = "middleware.django"
125+
MIDDLEWARE_STARLETTE = "middleware.starlette"
126+
QUEUE_SUBMIT_CELERY = "queue.submit.celery"
127+
QUEUE_TASK_CELERY = "queue.task.celery"
128+
QUEUE_TASK_RQ = "queue.task.rq"
129+
SUBPROCESS = "subprocess"
130+
SUBPROCESS_WAIT = "subprocess.wait"
131+
SUBPROCESS_COMMUNICATE = "subprocess.communicate"
132+
TEMPLATE_RENDER = "template.render"
133+
VIEW_RENDER = "view.render"
134+
WEBSOCKET_SERVER = "websocket.server"

sentry_sdk/integrations/aiohttp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import weakref
33

44
from sentry_sdk._compat import reraise
5+
from sentry_sdk.consts import OP
56
from sentry_sdk.hub import Hub
67
from sentry_sdk.integrations import Integration, DidNotEnable
78
from sentry_sdk.integrations.logging import ignore_logger
@@ -101,7 +102,7 @@ async def sentry_app_handle(self, request, *args, **kwargs):
101102

102103
transaction = Transaction.continue_from_headers(
103104
request.headers,
104-
op="http.server",
105+
op=OP.HTTP_SERVER,
105106
# If this transaction name makes it to the UI, AIOHTTP's
106107
# URL resolver did not find a route or died trying.
107108
name="generic AIOHTTP request",

sentry_sdk/integrations/asgi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from sentry_sdk._functools import partial
1212
from sentry_sdk._types import MYPY
13+
from sentry_sdk.consts import OP
1314
from sentry_sdk.hub import Hub, _should_send_default_pii
1415
from sentry_sdk.integrations._wsgi_common import _filter_headers
1516
from sentry_sdk.integrations.modules import _get_installed_modules
@@ -166,7 +167,7 @@ async def _run_app(self, scope, callback):
166167
op="{}.server".format(ty),
167168
)
168169
else:
169-
transaction = Transaction(op="asgi.server")
170+
transaction = Transaction(op=OP.HTTP_SERVER)
170171

171172
transaction.name = _DEFAULT_TRANSACTION_NAME
172173
transaction.source = TRANSACTION_SOURCE_ROUTE

sentry_sdk/integrations/aws_lambda.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import datetime, timedelta
22
from os import environ
33
import sys
4+
from sentry_sdk.consts import OP
45

56
from sentry_sdk.hub import Hub, _should_send_default_pii
67
from sentry_sdk.tracing import TRANSACTION_SOURCE_COMPONENT, Transaction
@@ -140,7 +141,7 @@ def sentry_handler(aws_event, aws_context, *args, **kwargs):
140141
headers = {}
141142
transaction = Transaction.continue_from_headers(
142143
headers,
143-
op="serverless.function",
144+
op=OP.FUNCTION_AWS,
144145
name=aws_context.function_name,
145146
source=TRANSACTION_SOURCE_COMPONENT,
146147
)

sentry_sdk/integrations/boto3.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import absolute_import
22

33
from sentry_sdk import Hub
4+
from sentry_sdk.consts import OP
45
from sentry_sdk.integrations import Integration, DidNotEnable
56
from sentry_sdk.tracing import Span
67

@@ -62,7 +63,7 @@ def _sentry_request_created(service_id, request, operation_name, **kwargs):
6263
description = "aws.%s.%s" % (service_id, operation_name)
6364
span = hub.start_span(
6465
hub=hub,
65-
op="aws.request",
66+
op=OP.HTTP_CLIENT,
6667
description=description,
6768
)
6869
span.set_tag("aws.service_id", service_id)
@@ -92,7 +93,7 @@ def _sentry_after_call(context, parsed, **kwargs):
9293
return
9394

9495
streaming_span = span.start_child(
95-
op="aws.request.stream",
96+
op=OP.HTTP_CLIENT_STREAM,
9697
description=span.description,
9798
)
9899

sentry_sdk/integrations/celery.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import absolute_import
22

33
import sys
4+
from sentry_sdk.consts import OP
45

56
from sentry_sdk.hub import Hub
67
from sentry_sdk.tracing import TRANSACTION_SOURCE_TASK
@@ -103,7 +104,9 @@ def apply_async(*args, **kwargs):
103104
hub = Hub.current
104105
integration = hub.get_integration(CeleryIntegration)
105106
if integration is not None and integration.propagate_traces:
106-
with hub.start_span(op="celery.submit", description=args[0].name) as span:
107+
with hub.start_span(
108+
op=OP.QUEUE_SUBMIT_CELERY, description=args[0].name
109+
) as span:
107110
with capture_internal_exceptions():
108111
headers = dict(hub.iter_trace_propagation_headers(span))
109112

@@ -156,7 +159,7 @@ def _inner(*args, **kwargs):
156159
with capture_internal_exceptions():
157160
transaction = Transaction.continue_from_headers(
158161
args[3].get("headers") or {},
159-
op="celery.task",
162+
op=OP.QUEUE_TASK_CELERY,
160163
name="unknown celery task",
161164
source=TRANSACTION_SOURCE_TASK,
162165
)

sentry_sdk/integrations/django/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import weakref
77

88
from sentry_sdk._types import MYPY
9+
from sentry_sdk.consts import OP
910
from sentry_sdk.hub import Hub, _should_send_default_pii
1011
from sentry_sdk.scope import add_global_event_processor
1112
from sentry_sdk.serializer import add_global_repr_processor
@@ -581,7 +582,7 @@ def connect(self):
581582
with capture_internal_exceptions():
582583
hub.add_breadcrumb(message="connect", category="query")
583584

584-
with hub.start_span(op="db", description="connect"):
585+
with hub.start_span(op=OP.DB, description="connect"):
585586
return real_connect(self)
586587

587588
CursorWrapper.execute = execute

sentry_sdk/integrations/django/asgi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from sentry_sdk import Hub, _functools
1212
from sentry_sdk._types import MYPY
13+
from sentry_sdk.consts import OP
1314

1415
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
1516

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

9192
with hub.start_span(
92-
op="django.view", description=request.resolver_match.view_name
93+
op=OP.VIEW_RENDER, description=request.resolver_match.view_name
9394
):
9495
return await callback(request, *args, **kwargs)
9596

sentry_sdk/integrations/django/middleware.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from sentry_sdk import Hub
88
from sentry_sdk._functools import wraps
99
from sentry_sdk._types import MYPY
10+
from sentry_sdk.consts import OP
1011
from sentry_sdk.utils import (
1112
ContextVar,
1213
transaction_from_function,
@@ -88,7 +89,7 @@ def _check_middleware_span(old_method):
8889
description = "{}.{}".format(description, function_basename)
8990

9091
middleware_span = hub.start_span(
91-
op="django.middleware", description=description
92+
op=OP.MIDDLEWARE_DJANGO, description=description
9293
)
9394
middleware_span.set_tag("django.function_name", function_name)
9495
middleware_span.set_tag("django.middleware_name", middleware_name)

sentry_sdk/integrations/django/signals_handlers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from sentry_sdk import Hub
77
from sentry_sdk._types import MYPY
8+
from sentry_sdk.consts import OP
89

910

1011
if MYPY:
@@ -50,7 +51,7 @@ def wrapper(*args, **kwargs):
5051
# type: (Any, Any) -> Any
5152
signal_name = _get_receiver_name(receiver)
5253
with hub.start_span(
53-
op="django.signals",
54+
op=OP.EVENT_DJANGO,
5455
description=signal_name,
5556
) as span:
5657
span.set_data("signal", signal_name)

sentry_sdk/integrations/django/templates.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from sentry_sdk import _functools, Hub
55
from sentry_sdk._types import MYPY
6+
from sentry_sdk.consts import OP
67

78
if MYPY:
89
from typing import Any
@@ -66,7 +67,7 @@ def rendered_content(self):
6667
return real_rendered_content.fget(self)
6768

6869
with hub.start_span(
69-
op="django.template.render",
70+
op=OP.TEMPLATE_RENDER,
7071
description=_get_template_name_description(self.template_name),
7172
) as span:
7273
span.set_data("context", self.context_data)
@@ -88,7 +89,7 @@ def render(request, template_name, context=None, *args, **kwargs):
8889
return real_render(request, template_name, context, *args, **kwargs)
8990

9091
with hub.start_span(
91-
op="django.template.render",
92+
op=OP.TEMPLATE_RENDER,
9293
description=_get_template_name_description(template_name),
9394
) as span:
9495
span.set_data("context", context)

sentry_sdk/integrations/django/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from sentry_sdk.consts import OP
12
from sentry_sdk.hub import Hub
23
from sentry_sdk._types import MYPY
34
from sentry_sdk import _functools
@@ -62,7 +63,7 @@ def _wrap_sync_view(hub, callback):
6263
def sentry_wrapped_callback(request, *args, **kwargs):
6364
# type: (Any, *Any, **Any) -> Any
6465
with hub.start_span(
65-
op="django.view", description=request.resolver_match.view_name
66+
op=OP.VIEW_RENDER, description=request.resolver_match.view_name
6667
):
6768
return callback(request, *args, **kwargs)
6869

sentry_sdk/integrations/gcp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import datetime, timedelta
22
from os import environ
33
import sys
4+
from sentry_sdk.consts import OP
45

56
from sentry_sdk.hub import Hub, _should_send_default_pii
67
from sentry_sdk.tracing import TRANSACTION_SOURCE_COMPONENT, Transaction
@@ -82,7 +83,7 @@ def sentry_func(functionhandler, gcp_event, *args, **kwargs):
8283
headers = gcp_event.headers
8384
transaction = Transaction.continue_from_headers(
8485
headers,
85-
op="serverless.function",
86+
op=OP.FUNCTION_GCP,
8687
name=environ.get("FUNCTION_NAME", ""),
8788
source=TRANSACTION_SOURCE_COMPONENT,
8889
)

sentry_sdk/integrations/httpx.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from sentry_sdk import Hub
2+
from sentry_sdk.consts import OP
23
from sentry_sdk.integrations import Integration, DidNotEnable
34
from sentry_sdk.utils import logger
45

@@ -41,7 +42,7 @@ def send(self, request, **kwargs):
4142
return real_send(self, request, **kwargs)
4243

4344
with hub.start_span(
44-
op="http", description="%s %s" % (request.method, request.url)
45+
op=OP.HTTP_CLIENT, description="%s %s" % (request.method, request.url)
4546
) as span:
4647
span.set_data("method", request.method)
4748
span.set_data("url", str(request.url))
@@ -73,7 +74,7 @@ async def send(self, request, **kwargs):
7374
return await real_send(self, request, **kwargs)
7475

7576
with hub.start_span(
76-
op="http", description="%s %s" % (request.method, request.url)
77+
op=OP.HTTP_CLIENT, description="%s %s" % (request.method, request.url)
7778
) as span:
7879
span.set_data("method", request.method)
7980
span.set_data("url", str(request.url))

sentry_sdk/integrations/redis.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import absolute_import
22

33
from sentry_sdk import Hub
4+
from sentry_sdk.consts import OP
45
from sentry_sdk.utils import capture_internal_exceptions, logger
56
from sentry_sdk.integrations import Integration, DidNotEnable
67

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

32-
with hub.start_span(op="redis", description="redis.pipeline.execute") as span:
33+
with hub.start_span(
34+
op=OP.DB_REDIS, description="redis.pipeline.execute"
35+
) as span:
3336
with capture_internal_exceptions():
3437
span.set_tag("redis.is_cluster", is_cluster)
3538
transaction = self.transaction if not is_cluster else False
@@ -152,7 +155,7 @@ def sentry_patched_execute_command(self, name, *args, **kwargs):
152155

153156
description = " ".join(description_parts)
154157

155-
with hub.start_span(op="redis", description=description) as span:
158+
with hub.start_span(op=OP.DB_REDIS, description=description) as span:
156159
span.set_tag("redis.is_cluster", is_cluster)
157160
if name:
158161
span.set_tag("redis.command", name)

sentry_sdk/integrations/rq.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import absolute_import
22

33
import weakref
4+
from sentry_sdk.consts import OP
45

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

6263
transaction = Transaction.continue_from_headers(
6364
job.meta.get("_sentry_trace_headers") or {},
64-
op="rq.task",
65+
op=OP.QUEUE_TASK_RQ,
6566
name="unknown RQ task",
6667
source=TRANSACTION_SOURCE_TASK,
6768
)

sentry_sdk/integrations/starlette.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from sentry_sdk._compat import iteritems
77
from sentry_sdk._types import MYPY
8+
from sentry_sdk.consts import OP
89
from sentry_sdk.hub import Hub, _should_send_default_pii
910
from sentry_sdk.integrations import DidNotEnable, Integration
1011
from sentry_sdk.integrations._wsgi_common import (
@@ -91,7 +92,7 @@ async def _create_span_call(*args, **kwargs):
9192
if integration is not None:
9293
middleware_name = args[0].__class__.__name__
9394
with hub.start_span(
94-
op="starlette.middleware", description=middleware_name
95+
op=OP.MIDDLEWARE_STARLETTE, description=middleware_name
9596
) as middleware_span:
9697
middleware_span.set_tag("starlette.middleware_name", middleware_name)
9798

0 commit comments

Comments
 (0)