OpenTelemetry pymongo Instrumentation

The integration with MongoDB supports the pymongo library, it can be enabled using the PymongoInstrumentor.

Usage

from pymongo import MongoClient
from opentelemetry.instrumentation.pymongo import PymongoInstrumentor


PymongoInstrumentor().instrument()
client = MongoClient()
db = client["MongoDB_Database"]
collection = db["MongoDB_Collection"]
collection.find_one()

API

class opentelemetry.instrumentation.pymongo.CommandTracer(tracer)[source]

Bases: pymongo.monitoring.CommandListener

started(event)[source]

Method to handle a pymongo CommandStartedEvent

succeeded(event)[source]

Method to handle a pymongo CommandSucceededEvent

failed(event)[source]

Method to handle a pymongo CommandFailedEvent

class opentelemetry.instrumentation.pymongo.PymongoInstrumentor(*args, **kwargs)[source]

Bases: opentelemetry.instrumentation.instrumentor.BaseInstrumentor

instrumentation_dependencies()[source]

Return a list of python packages with versions that the will be instrumented.

The format should be the same as used in requirements.txt or setup.py.

For example, if an instrumentation instruments requests 1.x, this method should look like:

def instrumentation_dependencies(self) -> Collection[str]:

return [‘requests ~= 1.0’]

This will ensure that the instrumentation will only be used when the specified library is present in the environment.

Return type

Collection[str]