Skip to content

Commit

Permalink
chore(pymongo): add additional asserts on resource names and mongodb.…
Browse files Browse the repository at this point in the history
…query span tag (#12333)

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)
  • Loading branch information
wantsui authored Feb 14, 2025
1 parent 1151323 commit 957ebc4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/contrib/pymongo/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,10 @@ def test_insert_find(self):

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

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

def test_update_ot(self):
Expand Down Expand Up @@ -402,6 +404,12 @@ def test_rowcount(self):
one_row_span = spans[2]
two_row_span = spans[3]

# Assert resource names and mongodb.query
assert one_row_span.resource == 'find songs {"name": "?"}'
assert one_row_span.get_tag("mongodb.query") == "{'name': '?'}"
assert two_row_span.resource == 'find songs {"artist": "?"}'
assert two_row_span.get_tag("mongodb.query") == "{'artist': '?'}"

assert one_row_span.name == "pymongo.cmd"
assert one_row_span.get_metric("db.row_count") == 1
assert two_row_span.get_metric("db.row_count") == 2
Expand All @@ -426,6 +434,8 @@ def test_patch_pymongo_client_after_import(self):
spans = tracer.pop()
assert len(spans) == 2
assert spans[1].name == "pymongo.cmd"
assert spans[1].resource == "buildinfo 1"
assert spans[1].get_tag("mongodb.query") is None


class TestPymongoPatchDefault(TracerTestCase, PymongoCore):
Expand Down

0 comments on commit 957ebc4

Please sign in to comment.