Skip to content

feat(pymongo): Send query description as valid JSON #3291

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 3 commits into from
Jul 15, 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
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/pymongo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
import json

import sentry_sdk
from sentry_sdk.consts import SPANSTATUS, SPANDATA, OP
Expand Down Expand Up @@ -154,7 +155,7 @@ def started(self, event):
if not should_send_default_pii():
command = _strip_pii(command)

query = "{}".format(command)
query = json.dumps(command, default=str)
span = sentry_sdk.start_span(
op=OP.DB,
description=query,
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 @@ -71,9 +71,9 @@ def test_transactions(sentry_init, capture_events, mongo_server, with_pii):
assert insert_success["tags"]["db.operation"] == "insert"
assert insert_fail["tags"]["db.operation"] == "insert"

assert find["description"].startswith("{'find")
assert insert_success["description"].startswith("{'insert")
assert insert_fail["description"].startswith("{'insert")
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"
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_breadcrumbs(sentry_init, capture_events, mongo_server, with_pii):
(crumb,) = event["breadcrumbs"]["values"]

assert crumb["category"] == "query"
assert crumb["message"].startswith("{'find")
assert crumb["message"].startswith('{"find')
if with_pii:
assert "1" in crumb["message"]
else:
Expand Down
Loading