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

ref(pymongo): Change span operation from db.query to db #3186

Merged
merged 6 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading