Skip to content
Merged
7 changes: 7 additions & 0 deletions sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ class SPANDATA:
Example: postgresql
"""

DB_MONGODB_COLLECTION = "db.mongodb.collection"
"""
The MongoDB collection being accessed within the database.
See: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/mongodb.md#attributes
Example: public.users; customers
"""

CACHE_HIT = "cache.hit"
"""
A boolean indicating whether the requested data was found in the cache.
Expand Down
1 change: 1 addition & 0 deletions sentry_sdk/integrations/pymongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def started(self, event):
"db.name": event.database_name,
SPANDATA.DB_SYSTEM: "mongodb",
SPANDATA.DB_OPERATION: event.command_name,
SPANDATA.DB_MONGODB_COLLECTION: command.get(event.command_name),
}

try:
Expand Down
5 changes: 5 additions & 0 deletions tests/integrations/pymongo/test_pymongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def test_transactions(sentry_init, capture_events, mongo_server, with_pii):
assert find["description"].startswith("{'find")
assert insert_success["description"].startswith("{'insert")
assert insert_fail["description"].startswith("{'insert")

assert find["tags"][SPANDATA.DB_MONGODB_COLLECTION] == "test_collection"
assert insert_success["tags"][SPANDATA.DB_MONGODB_COLLECTION] == "test_collection"
assert insert_fail["tags"][SPANDATA.DB_MONGODB_COLLECTION] == "erroneous"
if with_pii:
assert "1" in find["description"]
assert "2" in insert_success["description"]
Expand Down Expand Up @@ -125,6 +129,7 @@ def test_breadcrumbs(sentry_init, capture_events, mongo_server, with_pii):
"db.operation": "find",
"net.peer.name": mongo_server.host,
"net.peer.port": str(mongo_server.port),
"db.mongodb.collection": "test_collection",
}


Expand Down