Skip to content

Commit e264852

Browse files
authored
chore(peer.service): add mongodb.db as precursor for mongo (#6225)
This change adds the span tag `mongodb.db` as a precursor for Mongo databases, and ensures that the `peer.service` tag is updated when it is present. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [ ] Title is accurate. - [ ] No unnecessary changes are introduced. - [ ] Description motivates each change. - [ ] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [ ] Testing strategy adequately addresses listed risk(s). - [ ] Change is maintainable (easy to change, telemetry, documentation). - [ ] Release note makes sense to a user of the library. - [ ] Reviewer has explicitly 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)
1 parent 845aa79 commit e264852

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

ddtrace/settings/peer_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class PeerServiceConfig(object):
1111
source_tag_name = "_dd.peer.service.source"
1212
tag_name = "peer.service"
1313
enabled_span_kinds = {SpanKind.CLIENT, SpanKind.PRODUCER}
14-
prioritized_data_sources = ["messaging.kafka.bootstrap.servers", "db.name", "rpc.service", "out.host"]
14+
prioritized_data_sources = ["messaging.kafka.bootstrap.servers", "db.name", "mongodb.db", "rpc.service", "out.host"]
1515

1616
def __init__(self, set_defaults_enabled=None, peer_service_mapping=None):
1717
self._set_defaults_enabled = set_defaults_enabled

tests/contrib/mongoengine/test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,16 @@ def test_span_name_v1_schema(self):
219219
assert len(spans) == 1
220220
assert spans[0].name == "mongodb.query"
221221

222+
@TracerTestCase.run_in_subprocess(env_overrides=dict(DD_TRACE_SPAN_ATTRIBUTE_SCHEMA="v1"))
223+
def test_peer_service_tagging(self):
224+
tracer = self.get_tracer_and_connect()
225+
Artist.drop_collection()
226+
227+
spans = tracer.pop()
228+
assert len(spans) == 1
229+
assert spans[0].get_tag("mongodb.db") == "test"
230+
assert spans[0].get_tag("peer.service") == "test"
231+
222232

223233
class TestMongoEnginePatchConnectDefault(TracerTestCase, MongoEngineCore):
224234
"""Test suite with a global Pin for the connect function with the default configuration"""

tests/contrib/pymongo/test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,21 @@ def test_operation_name_v1_schema(self):
654654
assert len(spans) == 1
655655
assert spans[0].name == "mongodb.query"
656656

657+
@TracerTestCase.run_in_subprocess(env_overrides=dict(DD_TRACE_SPAN_ATTRIBUTE_SCHEMA="v1"))
658+
def test_peer_service_tagging(self):
659+
tracer = DummyTracer()
660+
client = pymongo.MongoClient(port=MONGO_CONFIG["port"])
661+
Pin.get_from(client).clone(tracer=tracer).onto(client)
662+
# We do not wish to trace tcp spans here
663+
Pin.get_from(pymongo.server.Server).remove_from(pymongo.server.Server)
664+
db_name = "testdb"
665+
client[db_name].drop_collection("whatever")
666+
spans = tracer.pop()
667+
assert len(spans) == 1
668+
for span in spans:
669+
assert span.get_tag("mongodb.db") == db_name
670+
assert span.get_tag("peer.service") == db_name
671+
657672
def test_patch_with_disabled_tracer(self):
658673
tracer, client = self.get_tracer_and_client()
659674
tracer.configure(enabled=False)

0 commit comments

Comments
 (0)