Skip to content

Commit 2e864e7

Browse files
committed
add pymongo methods to instrument
1 parent 15267a2 commit 2e864e7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
APIS = {
2+
"AGGREGATE": {
3+
"METHOD": "aggregate",
4+
"OPERATION": "aggregate",
5+
},
6+
}

src/langtrace_python_sdk/instrumentation/pymongo/instrumentation.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from importlib_metadata import version as v
2222
from wrapt import wrap_function_wrapper as _W
2323
from .patch import generic_patch
24+
from langtrace_python_sdk.constants.instrumentation.pymongo import APIS
2425

2526

2627
class PyMongoInstrumentation(BaseInstrumentor):
@@ -32,7 +33,15 @@ def instrumentation_dependencies(self) -> Collection[str]:
3233
return ["pymongo >= 4.0.0"]
3334

3435
def _instrument(self, **kwargs):
35-
pass
36+
tracer_provider = kwargs.get("tracer_provider")
37+
tracer = get_tracer(__name__, "", tracer_provider)
38+
version = v("pymongo")
39+
for api in APIS.values():
40+
_W(
41+
module="pymongo.collection",
42+
name=f"Collection.{api['METHOD']}",
43+
wrapper=generic_patch(version, tracer),
44+
)
3645

3746
def _uninstrument(self, **kwargs):
3847
pass

0 commit comments

Comments
 (0)