Skip to content

Commit 9c11e27

Browse files
0Caloriesarjenzorgdoc
authored andcommitted
ref(pymongo): Change span operation from db.query to db (getsentry#3186)
* ref(pymongo): Change span operation from `db.query` to `db` * use op from constants
1 parent 0f36dce commit 9c11e27

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

sentry_sdk/integrations/pymongo.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import copy
22

33
import sentry_sdk
4-
from sentry_sdk.consts import SPANDATA
4+
from sentry_sdk.consts import SPANDATA, OP
55
from sentry_sdk.integrations import DidNotEnable, Integration
66
from sentry_sdk.scope import should_send_default_pii
77
from sentry_sdk.tracing import Span
@@ -126,8 +126,6 @@ def started(self, event):
126126
command.pop("$clusterTime", None)
127127
command.pop("$signature", None)
128128

129-
op = "db.query"
130-
131129
tags = {
132130
"db.name": event.database_name,
133131
SPANDATA.DB_SYSTEM: "mongodb",
@@ -157,7 +155,7 @@ def started(self, event):
157155

158156
query = "{}".format(command)
159157
span = sentry_sdk.start_span(
160-
op=op,
158+
op=OP.DB,
161159
description=query,
162160
origin=PyMongoIntegration.origin,
163161
)
@@ -170,7 +168,7 @@ def started(self, event):
170168

171169
with capture_internal_exceptions():
172170
sentry_sdk.add_breadcrumb(
173-
message=query, category="query", type=op, data=tags
171+
message=query, category="query", type=OP.DB, data=tags
174172
)
175173

176174
self._ongoing_operations[self._operation_key(event)] = span.__enter__()

tests/integrations/pymongo/test_pymongo.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ def test_transactions(sentry_init, capture_events, mongo_server, with_pii):
6363
for field, value in common_tags.items():
6464
assert span["tags"][field] == value
6565

66-
assert find["op"] == "db.query"
67-
assert insert_success["op"] == "db.query"
68-
assert insert_fail["op"] == "db.query"
66+
assert find["op"] == "db"
67+
assert insert_success["op"] == "db"
68+
assert insert_fail["op"] == "db"
6969

7070
assert find["tags"]["db.operation"] == "find"
7171
assert insert_success["tags"]["db.operation"] == "insert"
@@ -118,7 +118,7 @@ def test_breadcrumbs(sentry_init, capture_events, mongo_server, with_pii):
118118
assert "1" in crumb["message"]
119119
else:
120120
assert "1" not in crumb["message"]
121-
assert crumb["type"] == "db.query"
121+
assert crumb["type"] == "db"
122122
assert crumb["data"] == {
123123
"db.name": "test_db",
124124
"db.system": "mongodb",

0 commit comments

Comments
 (0)