Skip to content

Add db.system to the span data for mongo db. #2042

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

Merged
merged 12 commits into from
Apr 27, 2023
4 changes: 3 additions & 1 deletion sentry_sdk/integrations/pymongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import copy

from sentry_sdk import Hub
from sentry_sdk.consts import SPANDATA
from sentry_sdk.hub import _should_send_default_pii
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.tracing import Span
Expand Down Expand Up @@ -119,10 +120,11 @@ def started(self, event):
except TypeError:
pass

data = {"operation_ids": {}} # type: Dict[str, Dict[str, Any]]
data = {"operation_ids": {}} # type: Dict[str, Any]

data["operation_ids"]["operation"] = event.operation_id
data["operation_ids"]["request"] = event.request_id
data[SPANDATA.DB_SYSTEM] = "mongodb"

try:
lsid = command.pop("lsid")["id"]
Expand Down
2 changes: 2 additions & 0 deletions tests/integrations/pymongo/test_pymongo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from sentry_sdk import capture_message, start_transaction
from sentry_sdk.consts import SPANDATA
from sentry_sdk.integrations.pymongo import PyMongoIntegration, _strip_pii

from mockupdb import MockupDB, OpQuery
Expand Down Expand Up @@ -55,6 +56,7 @@ def test_transactions(sentry_init, capture_events, mongo_server, with_pii):
"net.peer.port": str(mongo_server.port),
}
for span in find, insert_success, insert_fail:
assert span["data"][SPANDATA.DB_SYSTEM] == "mongodb"
for field, value in common_tags.items():
assert span["tags"][field] == value

Expand Down