Skip to content

capture_statement with pymongo instrumentor does not capture statements for all mongo command types #1951

@shkupferxom

Description

@shkupferxom

Describe your environment

  • Linux (python:3.11.4-debian-11-r39 docker image)
  • Python 3.11.4
  • opentelemetry-api 1.18.0
  • opentelemetry-instrumentation 0.39b0
  • opentelemetry-instrumentation-pymongo 0.39b0
  • pymongo 4.3.3

Steps to reproduce
After setting up a PymongoInstrumentor, running any kind of Mongo command not included in this mapping; an aggregation for example.

import pymongo
from opentelemetry.instrumentation.pymongo import PymongoInstrumentor

PymongoInstrumentor().instrument(capture_statement=True)

client = pymongo.MongoClient(connection_params)
db = client["dbname"]
agg_query = db.mycollection.aggregate(
    [
        {"$match": {"condition": "value"}},
        {"$group": {"_id": "$key", "count": {"$sum": 1}}},
    ]
)
output = list(agg_query)

What is the expected behavior?
The full statement to be output in statement.

What is the actual behavior?
statement is just aggregate.

Additional context
It looks like the problem is that the method that populates statement (here) only appends the full statement when the command is one of the types in this mapping.

I'm mostly interested in getting full statements for aggregate and findAndModify commands, but there may be others as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions