|
| 1 | +""" |
| 2 | +Copyright (c) 2024 Scale3 Labs |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +""" |
| 16 | + |
| 17 | +from opentelemetry.instrumentation.instrumentor import BaseInstrumentor |
| 18 | +from opentelemetry.trace import get_tracer |
| 19 | + |
| 20 | +from typing import Collection |
| 21 | +from importlib_metadata import version as v |
| 22 | +from wrapt import wrap_function_wrapper as _W |
| 23 | +from .patch import generic_patch |
| 24 | + |
| 25 | + |
| 26 | +class PyMongoInstrumentation(BaseInstrumentor): |
| 27 | + """ |
| 28 | + The PyMongoInstrumentation class represents the PyMongo instrumentation |
| 29 | + """ |
| 30 | + |
| 31 | + def instrumentation_dependencies(self) -> Collection[str]: |
| 32 | + return ["pymongo >= 4.0.0"] |
| 33 | + |
| 34 | + def _instrument(self, **kwargs): |
| 35 | + tracer_provider = kwargs.get("tracer_provider") |
| 36 | + tracer = get_tracer(__name__, "", tracer_provider) |
| 37 | + version = v("pymongo") |
| 38 | + _W( |
| 39 | + module="pymongo.collection", |
| 40 | + name="Collection.find", |
| 41 | + wrapper=generic_patch(version, tracer), |
| 42 | + ) |
| 43 | + |
| 44 | + def _uninstrument(self, **kwargs): |
| 45 | + pass |
0 commit comments