Skip to content

Commit 57db56c

Browse files
feat(pymongo): Set MongoDB tags directly on span data (#3290)
* feat(pymongo): Set MongoDB tags directly on span data Co-authored-by: Daniel Szoke <[email protected]> --------- Co-authored-by: Daniel Szoke <[email protected]>
1 parent 5e1f44b commit 57db56c

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

sentry_sdk/integrations/pymongo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,12 @@ def started(self, event):
163163
)
164164

165165
for tag, value in tags.items():
166+
# set the tag for backwards-compatibility.
167+
# TODO: remove the set_tag call in the next major release!
166168
span.set_tag(tag, value)
167169

170+
span.set_data(tag, value)
171+
168172
for key, value in data.items():
169173
span.set_data(key, value)
170174

tests/integrations/pymongo/test_pymongo.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,28 @@ def test_transactions(sentry_init, capture_events, mongo_server, with_pii):
6262
assert span["data"][SPANDATA.SERVER_PORT] == mongo_server.port
6363
for field, value in common_tags.items():
6464
assert span["tags"][field] == value
65+
assert span["data"][field] == value
6566

6667
assert find["op"] == "db"
6768
assert insert_success["op"] == "db"
6869
assert insert_fail["op"] == "db"
6970

71+
assert find["data"]["db.operation"] == "find"
7072
assert find["tags"]["db.operation"] == "find"
73+
assert insert_success["data"]["db.operation"] == "insert"
7174
assert insert_success["tags"]["db.operation"] == "insert"
75+
assert insert_fail["data"]["db.operation"] == "insert"
7276
assert insert_fail["tags"]["db.operation"] == "insert"
7377

7478
assert find["description"].startswith('{"find')
7579
assert insert_success["description"].startswith('{"insert')
7680
assert insert_fail["description"].startswith('{"insert')
7781

82+
assert find["data"][SPANDATA.DB_MONGODB_COLLECTION] == "test_collection"
7883
assert find["tags"][SPANDATA.DB_MONGODB_COLLECTION] == "test_collection"
84+
assert insert_success["data"][SPANDATA.DB_MONGODB_COLLECTION] == "test_collection"
7985
assert insert_success["tags"][SPANDATA.DB_MONGODB_COLLECTION] == "test_collection"
86+
assert insert_fail["data"][SPANDATA.DB_MONGODB_COLLECTION] == "erroneous"
8087
assert insert_fail["tags"][SPANDATA.DB_MONGODB_COLLECTION] == "erroneous"
8188
if with_pii:
8289
assert "1" in find["description"]

0 commit comments

Comments
 (0)