The integration with MongoDB supports the pymongo library, it can be enabled using the PymongoInstrumentor
.
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
The instrument method accepts the following keyword args:
tracer_provider (TracerProvider) - an optional tracer provider request_hook (Callable) - a function with extra user-defined logic to be performed before querying mongodb this function signature is: def request_hook(span: Span, event: CommandStartedEvent) -> None response_hook (Callable) - a function with extra user-defined logic to be performed after the query returns with a successful response this function signature is: def response_hook(span: Span, event: CommandSucceededEvent) -> None failed_hook (Callable) - a function with extra user-defined logic to be performed after the query returns with a failed response this function signature is: def failed_hook(span: Span, event: CommandFailedEvent) -> None capture_statement (bool) - an optional value to enable capturing the database statement that is being executed
for example:
Bases: CommandListener
Method to handle a pymongo CommandStartedEvent
Method to handle a pymongo CommandSucceededEvent
Method to handle a pymongo CommandFailedEvent
Bases: BaseInstrumentor
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 pyproject.toml.
For example, if an instrumentation instruments requests 1.x, this method should look like: :rtype: Collection
[str
]
- 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.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4