diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bd207b86c..e1f6b1ef07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `opentelemetry-instrumentation-aws-lambda` Adds an option to configure `disable_aws_context_propagation` by environment variable: `OTEL_LAMBDA_DISABLE_AWS_CONTEXT_PROPAGATION` ([#1507](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1507)) - +- Fix pymongo to collect the property DB_MONGODB_COLLECTION + ([#1555](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1555)) ## Version 1.15.0/0.36b0 (2022-12-10) diff --git a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py index 4e9ae8a14b..65315b2be5 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py @@ -126,6 +126,7 @@ def started(self, event: monitoring.CommandStartedEvent): statement = event.command_name if command: statement += " " + str(command) + collection = event.command.get(event.command_name) try: span = self._tracer.start_span(name, kind=SpanKind.CLIENT) @@ -135,6 +136,10 @@ def started(self, event: monitoring.CommandStartedEvent): ) span.set_attribute(SpanAttributes.DB_NAME, event.database_name) span.set_attribute(SpanAttributes.DB_STATEMENT, statement) + if collection: + span.set_attribute( + SpanAttributes.DB_MONGODB_COLLECTION, collection + ) if event.connection_id is not None: span.set_attribute( SpanAttributes.NET_PEER_NAME, event.connection_id[0] diff --git a/tests/opentelemetry-docker-tests/tests/pymongo/test_pymongo_functional.py b/tests/opentelemetry-docker-tests/tests/pymongo/test_pymongo_functional.py index 92c694953b..e8158c0657 100644 --- a/tests/opentelemetry-docker-tests/tests/pymongo/test_pymongo_functional.py +++ b/tests/opentelemetry-docker-tests/tests/pymongo/test_pymongo_functional.py @@ -68,6 +68,10 @@ def validate_spans(self): self.assertEqual( pymongo_span.attributes[SpanAttributes.NET_PEER_PORT], MONGODB_PORT ) + self.assertEqual( + pymongo_span.attributes[SpanAttributes.DB_MONGODB_COLLECTION], + MONGODB_COLLECTION_NAME, + ) def test_insert(self): """Should create a child span for insert"""