open-telemetry / open-telemetry/opentelemetry-python-contrib
capture_statement with pymongo instrumentor does not capture statements for all mongo command types
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 1.1k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 16
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/init.py at the statement-population method, then inspect utils.py and its command mapping. Run the provided aggregate reproduction and compare it with mapped commands. Done means capture_statement emits the full statement for aggregate, findAndModify, and other relevant Mongo command types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- databases, observability
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100