Repository: open-telemetry/opentelemetry-python-contrib

Issue:
pymongo is not collecting the property: db.mongodb.collection
According to the [specs](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/database.md#call-level-attributes-for-specific-technologies) - 
mongodb should capture: "The collection being accessed within the database stated in db.name."
and save it in: `db.mongodb.collection`

**Steps to reproduce**
Instrument a client using PymongoInstrumentor().
Send a request to the db.

**What is the expected behavior?**
Produce a span with `db.mongodb.collection` value containing the collection name.

**What is the actual behavior?**
Produce a span without generating `db.mongodb.collection`.

**Example:**
Here is a simple code example:

```
PymongoInstrumentor().instrument()
client = MongoClient()
RECORD = {"test": "123"}
db = client["MongoDB_Database"]
collection = db["MongoDB_Collection"]
collection.find_one(RECORD)
```

and the result is missing the collection:
```
"attributes": {
        "db.system": "mongodb",
        "db.name": "MongoDB_Database",
        "db.statement": "find",
        "net.peer.name": "localhost",
        "net.peer.port": 27017
    }
```

If you can - assign this to me, thanks :)


Discussion:

Resolving patch:
diff --git a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py
--- 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]


Test patch:
diff --git a/tests/opentelemetry-docker-tests/tests/pymongo/test_pymongo_functional.py b/tests/opentelemetry-docker-tests/tests/pymongo/test_pymongo_functional.py
--- 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"""