Skip to content

Commit 9610025

Browse files
chore(pymongo): add additional asserts on resource names and mongodb.query span tag [backport 2.21] (#12438)
Backport 957ebc4 from #12333 to 2.21. In preparation of @ajgajg1134 's #12311, this PR adds additional asserts for the current state of mongodb resource names and mongodb.query. Right now the tests show that there's a diff of `"` and `'` in the current behavior. ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) Co-authored-by: wantsui <[email protected]>
1 parent 4078b09 commit 9610025

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tests/contrib/pymongo/test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,10 @@ def test_insert_find(self):
292292

293293
# confirm query tag for find all
294294
assert spans[-2].get_tag("mongodb.query") is None
295+
assert spans[-2].resource == "find teams"
295296

296297
# confirm query tag find with query criteria on name
298+
assert spans[-1].resource == 'find teams {"name": "?"}'
297299
assert spans[-1].get_tag("mongodb.query") == "{'name': '?'}"
298300

299301
def test_update_ot(self):
@@ -402,6 +404,12 @@ def test_rowcount(self):
402404
one_row_span = spans[2]
403405
two_row_span = spans[3]
404406

407+
# Assert resource names and mongodb.query
408+
assert one_row_span.resource == 'find songs {"name": "?"}'
409+
assert one_row_span.get_tag("mongodb.query") == "{'name': '?'}"
410+
assert two_row_span.resource == 'find songs {"artist": "?"}'
411+
assert two_row_span.get_tag("mongodb.query") == "{'artist': '?'}"
412+
405413
assert one_row_span.name == "pymongo.cmd"
406414
assert one_row_span.get_metric("db.row_count") == 1
407415
assert two_row_span.get_metric("db.row_count") == 2
@@ -426,6 +434,8 @@ def test_patch_pymongo_client_after_import(self):
426434
spans = tracer.pop()
427435
assert len(spans) == 2
428436
assert spans[1].name == "pymongo.cmd"
437+
assert spans[1].resource == "buildinfo 1"
438+
assert spans[1].get_tag("mongodb.query") is None
429439

430440

431441
class TestPymongoPatchDefault(TracerTestCase, PymongoCore):

0 commit comments

Comments
 (0)