OpenTelemetry pymongo Integration

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

Usage

from pymongo import MongoClient
from opentelemetry import trace
from opentelemetry.trace import TracerProvider
from opentelemetry.ext.pymongo import PymongoInstrumentor

trace.set_tracer_provider(TracerProvider())

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

API

class opentelemetry.ext.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.ext.pymongo.PymongoInstrumentor[source]

Bases: opentelemetry.instrumentation.instrumentor.BaseInstrumentor