Skip to content

Commit

Permalink
ref(pymongo): Change span operation from db.query to db (#3186)
Browse files Browse the repository at this point in the history
* ref(pymongo): Change span operation from `db.query` to `db`

* use op from constants
  • Loading branch information
0Calories authored Jun 24, 2024
1 parent 87f6037 commit ffc4610
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 3 additions & 5 deletions sentry_sdk/integrations/pymongo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import copy

import sentry_sdk
from sentry_sdk.consts import SPANDATA
from sentry_sdk.consts import SPANDATA, OP
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.tracing import Span
Expand Down Expand Up @@ -126,8 +126,6 @@ def started(self, event):
command.pop("$clusterTime", None)
command.pop("$signature", None)

op = "db.query"

tags = {
"db.name": event.database_name,
SPANDATA.DB_SYSTEM: "mongodb",
Expand Down Expand Up @@ -157,7 +155,7 @@ def started(self, event):

query = "{}".format(command)
span = sentry_sdk.start_span(
op=op,
op=OP.DB,
description=query,
origin=PyMongoIntegration.origin,
)
Expand All @@ -170,7 +168,7 @@ def started(self, event):

with capture_internal_exceptions():
sentry_sdk.add_breadcrumb(
message=query, category="query", type=op, data=tags
message=query, category="query", type=OP.DB, data=tags
)

self._ongoing_operations[self._operation_key(event)] = span.__enter__()
Expand Down
8 changes: 4 additions & 4 deletions tests/integrations/pymongo/test_pymongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def test_transactions(sentry_init, capture_events, mongo_server, with_pii):
for field, value in common_tags.items():
assert span["tags"][field] == value

assert find["op"] == "db.query"
assert insert_success["op"] == "db.query"
assert insert_fail["op"] == "db.query"
assert find["op"] == "db"
assert insert_success["op"] == "db"
assert insert_fail["op"] == "db"

assert find["tags"]["db.operation"] == "find"
assert insert_success["tags"]["db.operation"] == "insert"
Expand Down Expand Up @@ -118,7 +118,7 @@ def test_breadcrumbs(sentry_init, capture_events, mongo_server, with_pii):
assert "1" in crumb["message"]
else:
assert "1" not in crumb["message"]
assert crumb["type"] == "db.query"
assert crumb["type"] == "db"
assert crumb["data"] == {
"db.name": "test_db",
"db.system": "mongodb",
Expand Down

0 comments on commit ffc4610

Please sign in to comment.