diff --git a/elasticapm/instrumentation/packages/pymongo.py b/elasticapm/instrumentation/packages/pymongo.py index d19036b6a..c7ca3faa9 100644 --- a/elasticapm/instrumentation/packages/pymongo.py +++ b/elasticapm/instrumentation/packages/pymongo.py @@ -132,7 +132,8 @@ def call(self, module, method, wrapped, instance, args, kwargs): span_type="db", span_subtype="mongodb", span_action="query", - extra={"destination": {}}, + extra=context, + leaf=True, ) as span: response = wrapped(*args, **kwargs) if span.context and instance.address: diff --git a/tests/instrumentation/pymongo_tests.py b/tests/instrumentation/pymongo_tests.py index 10d68628e..d93b3401d 100644 --- a/tests/instrumentation/pymongo_tests.py +++ b/tests/instrumentation/pymongo_tests.py @@ -99,7 +99,7 @@ def test_collection_count(instrument, elasticapm_client, mongo_database): assert span["context"]["destination"] == { "address": os.environ.get("MONGODB_HOST", "localhost"), "port": int(os.environ.get("MONGODB_PORT", 27017)), - "service": {"name": "", "resource": "mongodb", "type": ""}, + "service": {"name": "", "resource": "mongodb/elasticapm_test", "type": ""}, } @@ -258,7 +258,7 @@ def test_collection_find(instrument, elasticapm_client, mongo_database): assert span["context"]["destination"] == { "address": os.environ.get("MONGODB_HOST", "localhost"), "port": int(os.environ.get("MONGODB_PORT", 27017)), - "service": {"name": "", "resource/elasticapm_test": "mongodb", "type": ""}, + "service": {"name": "", "resource": "mongodb/elasticapm_test", "type": ""}, }