openlit 1.31.1__py3-none-any.whl → 1.32.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openlit/__init__.py +15 -0
- openlit/instrumentation/crewai/crewai.py +2 -0
- openlit/instrumentation/julep/__init__.py +80 -0
- openlit/instrumentation/julep/async_julep.py +111 -0
- openlit/instrumentation/julep/julep.py +112 -0
- openlit/instrumentation/mem0/__init__.py +79 -0
- openlit/instrumentation/mem0/mem0.py +115 -0
- openlit/instrumentation/multion/__init__.py +80 -0
- openlit/instrumentation/multion/async_multion.py +131 -0
- openlit/instrumentation/multion/multion.py +131 -0
- openlit/instrumentation/premai/__init__.py +51 -0
- openlit/instrumentation/premai/premai.py +507 -0
- openlit/instrumentation/reka/__init__.py +54 -0
- openlit/instrumentation/reka/async_reka.py +159 -0
- openlit/instrumentation/reka/reka.py +159 -0
- openlit/semcov/__init__.py +9 -0
- {openlit-1.31.1.dist-info → openlit-1.32.2.dist-info}/METADATA +11 -5
- {openlit-1.31.1.dist-info → openlit-1.32.2.dist-info}/RECORD +20 -7
- {openlit-1.31.1.dist-info → openlit-1.32.2.dist-info}/LICENSE +0 -0
- {openlit-1.31.1.dist-info → openlit-1.32.2.dist-info}/WHEEL +0 -0
openlit/__init__.py
CHANGED
@@ -36,11 +36,14 @@ from openlit.instrumentation.gpt4all import GPT4AllInstrumentor
|
|
36
36
|
from openlit.instrumentation.elevenlabs import ElevenLabsInstrumentor
|
37
37
|
from openlit.instrumentation.vllm import VLLMInstrumentor
|
38
38
|
from openlit.instrumentation.google_ai_studio import GoogleAIStudioInstrumentor
|
39
|
+
from openlit.instrumentation.reka import RekaInstrumentor
|
40
|
+
from openlit.instrumentation.premai import PremAIInstrumentor
|
39
41
|
from openlit.instrumentation.azure_ai_inference import AzureAIInferenceInstrumentor
|
40
42
|
from openlit.instrumentation.langchain import LangChainInstrumentor
|
41
43
|
from openlit.instrumentation.llamaindex import LlamaIndexInstrumentor
|
42
44
|
from openlit.instrumentation.haystack import HaystackInstrumentor
|
43
45
|
from openlit.instrumentation.embedchain import EmbedChainInstrumentor
|
46
|
+
from openlit.instrumentation.mem0 import Mem0Instrumentor
|
44
47
|
from openlit.instrumentation.chroma import ChromaInstrumentor
|
45
48
|
from openlit.instrumentation.pinecone import PineconeInstrumentor
|
46
49
|
from openlit.instrumentation.qdrant import QdrantInstrumentor
|
@@ -49,8 +52,10 @@ from openlit.instrumentation.transformers import TransformersInstrumentor
|
|
49
52
|
from openlit.instrumentation.litellm import LiteLLMInstrumentor
|
50
53
|
from openlit.instrumentation.crewai import CrewAIInstrumentor
|
51
54
|
from openlit.instrumentation.ag2 import AG2Instrumentor
|
55
|
+
from openlit.instrumentation.multion import MultiOnInstrumentor
|
52
56
|
from openlit.instrumentation.dynamiq import DynamiqInstrumentor
|
53
57
|
from openlit.instrumentation.phidata import PhidataInstrumentor
|
58
|
+
from openlit.instrumentation.julep import JulepInstrumentor
|
54
59
|
from openlit.instrumentation.gpu import GPUInstrumentor
|
55
60
|
import openlit.guard
|
56
61
|
import openlit.evals
|
@@ -228,6 +233,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
|
|
228
233
|
"llama_index": "llama_index",
|
229
234
|
"haystack": "haystack",
|
230
235
|
"embedchain": "embedchain",
|
236
|
+
"mem0": "mem0",
|
231
237
|
"chroma": "chromadb",
|
232
238
|
"pinecone": "pinecone",
|
233
239
|
"qdrant": "qdrant_client",
|
@@ -238,8 +244,12 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
|
|
238
244
|
"ag2": "ag2",
|
239
245
|
"autogen": "autogen",
|
240
246
|
"pyautogen": "pyautogen",
|
247
|
+
"multion": "multion",
|
241
248
|
"dynamiq": "dynamiq",
|
242
249
|
"phidata": "phi",
|
250
|
+
"reka-api": "reka",
|
251
|
+
"premai": "premai",
|
252
|
+
"julep": "julep",
|
243
253
|
}
|
244
254
|
|
245
255
|
invalid_instrumentors = [
|
@@ -312,6 +322,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
|
|
312
322
|
"llama_index": LlamaIndexInstrumentor(),
|
313
323
|
"haystack": HaystackInstrumentor(),
|
314
324
|
"embedchain": EmbedChainInstrumentor(),
|
325
|
+
"mem0": Mem0Instrumentor(),
|
315
326
|
"chroma": ChromaInstrumentor(),
|
316
327
|
"pinecone": PineconeInstrumentor(),
|
317
328
|
"qdrant": QdrantInstrumentor(),
|
@@ -320,10 +331,14 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
|
|
320
331
|
"litellm": LiteLLMInstrumentor(),
|
321
332
|
"crewai": CrewAIInstrumentor(),
|
322
333
|
"ag2": AG2Instrumentor(),
|
334
|
+
"multion": MultiOnInstrumentor(),
|
323
335
|
"autogen": AG2Instrumentor(),
|
324
336
|
"pyautogen": AG2Instrumentor(),
|
325
337
|
"dynamiq": DynamiqInstrumentor(),
|
326
338
|
"phidata": PhidataInstrumentor(),
|
339
|
+
"reka-api": RekaInstrumentor(),
|
340
|
+
"premai": PremAIInstrumentor(),
|
341
|
+
"julep": JulepInstrumentor(),
|
327
342
|
}
|
328
343
|
|
329
344
|
# Initialize and instrument only the enabled instrumentors
|
@@ -75,6 +75,8 @@ def crew_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
75
75
|
SemanticConvetion.GEN_AI_TYPE_AGENT)
|
76
76
|
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
|
77
77
|
gen_ai_endpoint)
|
78
|
+
span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
|
79
|
+
application_name)
|
78
80
|
|
79
81
|
instance_class = instance.__class__.__name__
|
80
82
|
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
|
2
|
+
"""Initializer of Auto Instrumentation of Juelp Functions"""
|
3
|
+
|
4
|
+
from typing import Collection
|
5
|
+
import importlib.metadata
|
6
|
+
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
7
|
+
from wrapt import wrap_function_wrapper
|
8
|
+
|
9
|
+
from openlit.instrumentation.julep.julep import (
|
10
|
+
wrap_julep
|
11
|
+
)
|
12
|
+
|
13
|
+
from openlit.instrumentation.julep.async_julep import (
|
14
|
+
async_wrap_julep
|
15
|
+
)
|
16
|
+
|
17
|
+
_instruments = ("julep >= 1.42.0",)
|
18
|
+
|
19
|
+
class JulepInstrumentor(BaseInstrumentor):
|
20
|
+
"""
|
21
|
+
An instrumentor for Julep's client library.
|
22
|
+
"""
|
23
|
+
|
24
|
+
def instrumentation_dependencies(self) -> Collection[str]:
|
25
|
+
return _instruments
|
26
|
+
|
27
|
+
def _instrument(self, **kwargs):
|
28
|
+
application_name = kwargs.get("application_name", "default_application")
|
29
|
+
environment = kwargs.get("environment", "default_environment")
|
30
|
+
tracer = kwargs.get("tracer")
|
31
|
+
metrics = kwargs.get("metrics_dict")
|
32
|
+
pricing_info = kwargs.get("pricing_info", {})
|
33
|
+
trace_content = kwargs.get("trace_content", False)
|
34
|
+
disable_metrics = kwargs.get("disable_metrics")
|
35
|
+
version = importlib.metadata.version("julep")
|
36
|
+
|
37
|
+
# sync
|
38
|
+
wrap_function_wrapper(
|
39
|
+
"julep.resources.agents.agents",
|
40
|
+
"AgentsResource.create",
|
41
|
+
wrap_julep("julep.agents_create", version, environment, application_name,
|
42
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
43
|
+
)
|
44
|
+
wrap_function_wrapper(
|
45
|
+
"julep.resources.tasks",
|
46
|
+
"TasksResource.create",
|
47
|
+
wrap_julep("julep.task_create", version, environment, application_name,
|
48
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
49
|
+
)
|
50
|
+
wrap_function_wrapper(
|
51
|
+
"julep.resources.executions.executions",
|
52
|
+
"ExecutionsResource.create",
|
53
|
+
wrap_julep("julep.execution_create", version, environment, application_name,
|
54
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
55
|
+
)
|
56
|
+
|
57
|
+
# async
|
58
|
+
wrap_function_wrapper(
|
59
|
+
"julep.resources.agents.agents",
|
60
|
+
"AsyncAgentsResource.create",
|
61
|
+
async_wrap_julep("julep.agents_create", version, environment, application_name,
|
62
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
63
|
+
)
|
64
|
+
wrap_function_wrapper(
|
65
|
+
"julep.resources.tasks",
|
66
|
+
"AsyncTasksResource.create",
|
67
|
+
async_wrap_julep("julep.task_create", version, environment, application_name,
|
68
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
69
|
+
)
|
70
|
+
wrap_function_wrapper(
|
71
|
+
"julep.resources.executions.executions",
|
72
|
+
"AsyncExecutionsResource.create",
|
73
|
+
async_wrap_julep("julep.execution_create", version, environment, application_name,
|
74
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
75
|
+
)
|
76
|
+
|
77
|
+
|
78
|
+
def _uninstrument(self, **kwargs):
|
79
|
+
# Proper uninstrumentation logic to revert patched methods
|
80
|
+
pass
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument
|
2
|
+
"""
|
3
|
+
Module for monitoring Julep.
|
4
|
+
"""
|
5
|
+
|
6
|
+
import logging
|
7
|
+
from opentelemetry.trace import SpanKind, Status, StatusCode
|
8
|
+
from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
|
9
|
+
from openlit.__helpers import handle_exception
|
10
|
+
from openlit.semcov import SemanticConvetion
|
11
|
+
|
12
|
+
# Initialize logger for logging potential issues and operations
|
13
|
+
logger = logging.getLogger(__name__)
|
14
|
+
|
15
|
+
def async_wrap_julep(gen_ai_endpoint, version, environment, application_name,
|
16
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics):
|
17
|
+
"""
|
18
|
+
Creates a wrapper around a function call to trace and log its execution metrics.
|
19
|
+
|
20
|
+
This function wraps any given function to measure its execution time,
|
21
|
+
log its operation, and trace its execution using OpenTelemetry.
|
22
|
+
|
23
|
+
Parameters:
|
24
|
+
- gen_ai_endpoint (str): A descriptor or name for the endpoint being traced.
|
25
|
+
- version (str): The version of the application.
|
26
|
+
- environment (str): The deployment environment (e.g., 'production', 'development').
|
27
|
+
- application_name (str): Name of the application.
|
28
|
+
- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.
|
29
|
+
- pricing_info (dict): Information about the pricing for internal metrics (currently not used).
|
30
|
+
- trace_content (bool): Flag indicating whether to trace the content of the response.
|
31
|
+
|
32
|
+
Returns:
|
33
|
+
- function: A higher-order function that takes a function 'wrapped' and returns
|
34
|
+
a new function that wraps 'wrapped' with additional tracing and logging.
|
35
|
+
"""
|
36
|
+
|
37
|
+
async def wrapper(wrapped, instance, args, kwargs):
|
38
|
+
"""
|
39
|
+
An inner wrapper function that executes the wrapped function, measures execution
|
40
|
+
time, and records trace data using OpenTelemetry.
|
41
|
+
|
42
|
+
Parameters:
|
43
|
+
- wrapped (Callable): The original function that this wrapper will execute.
|
44
|
+
- instance (object): The instance to which the wrapped function belongs. This
|
45
|
+
is used for instance methods. For static and classmethods,
|
46
|
+
this may be None.
|
47
|
+
- args (tuple): Positional arguments passed to the wrapped function.
|
48
|
+
- kwargs (dict): Keyword arguments passed to the wrapped function.
|
49
|
+
|
50
|
+
Returns:
|
51
|
+
- The result of the wrapped function call.
|
52
|
+
|
53
|
+
The wrapper initiates a span with the provided tracer, sets various attributes
|
54
|
+
on the span based on the function's execution and response, and ensures
|
55
|
+
errors are handled and logged appropriately.
|
56
|
+
"""
|
57
|
+
|
58
|
+
with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
|
59
|
+
response = await wrapped(*args, **kwargs)
|
60
|
+
|
61
|
+
try:
|
62
|
+
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
63
|
+
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
|
64
|
+
gen_ai_endpoint)
|
65
|
+
span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
|
66
|
+
SemanticConvetion.GEN_AI_SYSTEM_JULEP)
|
67
|
+
span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
|
68
|
+
environment)
|
69
|
+
span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
|
70
|
+
application_name)
|
71
|
+
span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
|
72
|
+
SemanticConvetion.GEN_AI_TYPE_AGENT)
|
73
|
+
|
74
|
+
if gen_ai_endpoint == "julep.agents_create":
|
75
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ID,
|
76
|
+
response.id)
|
77
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ROLE,
|
78
|
+
kwargs.get("name", ""))
|
79
|
+
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
|
80
|
+
kwargs.get("model", "gpt-4-turbo"))
|
81
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_CONTEXT,
|
82
|
+
kwargs.get("about", ""))
|
83
|
+
|
84
|
+
elif gen_ai_endpoint == "julep.task_create":
|
85
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TOOLS,
|
86
|
+
str(kwargs.get("tools", "")))
|
87
|
+
|
88
|
+
elif gen_ai_endpoint == "julep.execution_create":
|
89
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TASK_ID,
|
90
|
+
kwargs.get("task_id", ""))
|
91
|
+
if trace_content:
|
92
|
+
span.add_event(
|
93
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
94
|
+
attributes={
|
95
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT:str(kwargs.get("input", "")),
|
96
|
+
},
|
97
|
+
)
|
98
|
+
|
99
|
+
span.set_status(Status(StatusCode.OK))
|
100
|
+
|
101
|
+
# Return original response
|
102
|
+
return response
|
103
|
+
|
104
|
+
except Exception as e:
|
105
|
+
handle_exception(span, e)
|
106
|
+
logger.error("Error in trace creation: %s", e)
|
107
|
+
|
108
|
+
# Return original response
|
109
|
+
return response
|
110
|
+
|
111
|
+
return wrapper
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument
|
2
|
+
"""
|
3
|
+
Module for monitoring Julep.
|
4
|
+
"""
|
5
|
+
|
6
|
+
import logging
|
7
|
+
from opentelemetry.trace import SpanKind, Status, StatusCode
|
8
|
+
from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
|
9
|
+
from openlit.__helpers import handle_exception
|
10
|
+
from openlit.semcov import SemanticConvetion
|
11
|
+
|
12
|
+
# Initialize logger for logging potential issues and operations
|
13
|
+
logger = logging.getLogger(__name__)
|
14
|
+
|
15
|
+
def wrap_julep(gen_ai_endpoint, version, environment, application_name,
|
16
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics):
|
17
|
+
"""
|
18
|
+
Creates a wrapper around a function call to trace and log its execution metrics.
|
19
|
+
|
20
|
+
This function wraps any given function to measure its execution time,
|
21
|
+
log its operation, and trace its execution using OpenTelemetry.
|
22
|
+
|
23
|
+
Parameters:
|
24
|
+
- gen_ai_endpoint (str): A descriptor or name for the endpoint being traced.
|
25
|
+
- version (str): The version of the Langchain application.
|
26
|
+
- environment (str): The deployment environment (e.g., 'production', 'development').
|
27
|
+
- application_name (str): Name of the Langchain application.
|
28
|
+
- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.
|
29
|
+
- pricing_info (dict): Information about the pricing for internal metrics (currently not used).
|
30
|
+
- trace_content (bool): Flag indicating whether to trace the content of the response.
|
31
|
+
|
32
|
+
Returns:
|
33
|
+
- function: A higher-order function that takes a function 'wrapped' and returns
|
34
|
+
a new function that wraps 'wrapped' with additional tracing and logging.
|
35
|
+
"""
|
36
|
+
|
37
|
+
def wrapper(wrapped, instance, args, kwargs):
|
38
|
+
"""
|
39
|
+
An inner wrapper function that executes the wrapped function, measures execution
|
40
|
+
time, and records trace data using OpenTelemetry.
|
41
|
+
|
42
|
+
Parameters:
|
43
|
+
- wrapped (Callable): The original function that this wrapper will execute.
|
44
|
+
- instance (object): The instance to which the wrapped function belongs. This
|
45
|
+
is used for instance methods. For static and classmethods,
|
46
|
+
this may be None.
|
47
|
+
- args (tuple): Positional arguments passed to the wrapped function.
|
48
|
+
- kwargs (dict): Keyword arguments passed to the wrapped function.
|
49
|
+
|
50
|
+
Returns:
|
51
|
+
- The result of the wrapped function call.
|
52
|
+
|
53
|
+
The wrapper initiates a span with the provided tracer, sets various attributes
|
54
|
+
on the span based on the function's execution and response, and ensures
|
55
|
+
errors are handled and logged appropriately.
|
56
|
+
"""
|
57
|
+
|
58
|
+
with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
|
59
|
+
response = wrapped(*args, **kwargs)
|
60
|
+
|
61
|
+
try:
|
62
|
+
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
63
|
+
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
|
64
|
+
gen_ai_endpoint)
|
65
|
+
span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
|
66
|
+
SemanticConvetion.GEN_AI_SYSTEM_JULEP)
|
67
|
+
span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
|
68
|
+
environment)
|
69
|
+
span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
|
70
|
+
application_name)
|
71
|
+
span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
|
72
|
+
SemanticConvetion.GEN_AI_TYPE_AGENT)
|
73
|
+
|
74
|
+
if gen_ai_endpoint == "julep.agents_create":
|
75
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ID,
|
76
|
+
response.id)
|
77
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ROLE,
|
78
|
+
kwargs.get("name", ""))
|
79
|
+
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
|
80
|
+
kwargs.get("model", "gpt-4-turbo"))
|
81
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_CONTEXT,
|
82
|
+
kwargs.get("about", ""))
|
83
|
+
|
84
|
+
elif gen_ai_endpoint == "julep.task_create":
|
85
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TOOLS,
|
86
|
+
str(kwargs.get("tools", "")))
|
87
|
+
|
88
|
+
elif gen_ai_endpoint == "julep.execution_create":
|
89
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TASK_ID,
|
90
|
+
kwargs.get("task_id", ""))
|
91
|
+
if trace_content:
|
92
|
+
span.add_event(
|
93
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
94
|
+
attributes={
|
95
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT:str(kwargs.get("input", "")),
|
96
|
+
},
|
97
|
+
)
|
98
|
+
|
99
|
+
|
100
|
+
span.set_status(Status(StatusCode.OK))
|
101
|
+
|
102
|
+
# Return original response
|
103
|
+
return response
|
104
|
+
|
105
|
+
except Exception as e:
|
106
|
+
handle_exception(span, e)
|
107
|
+
logger.error("Error in trace creation: %s", e)
|
108
|
+
|
109
|
+
# Return original response
|
110
|
+
return response
|
111
|
+
|
112
|
+
return wrapper
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
|
2
|
+
"""Initializer of Auto Instrumentation of mem0 Functions"""
|
3
|
+
from typing import Collection
|
4
|
+
import importlib.metadata
|
5
|
+
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
6
|
+
from wrapt import wrap_function_wrapper
|
7
|
+
|
8
|
+
from openlit.instrumentation.mem0.mem0 import mem0_wrap
|
9
|
+
|
10
|
+
_instruments = ("mem0ai >= 0.1.32",)
|
11
|
+
|
12
|
+
WRAPPED_METHODS = [
|
13
|
+
{
|
14
|
+
"package": "mem0",
|
15
|
+
"object": "Memory.add",
|
16
|
+
"endpoint": "mem0.memory_add",
|
17
|
+
"wrapper": mem0_wrap,
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"package": "mem0",
|
21
|
+
"object": "Memory.get_all",
|
22
|
+
"endpoint": "mem0.memory_get_all",
|
23
|
+
"wrapper": mem0_wrap,
|
24
|
+
},
|
25
|
+
{
|
26
|
+
"package": "mem0",
|
27
|
+
"object": "Memory.get",
|
28
|
+
"endpoint": "mem0.memory_get",
|
29
|
+
"wrapper": mem0_wrap,
|
30
|
+
},
|
31
|
+
{
|
32
|
+
"package": "mem0",
|
33
|
+
"object": "Memory.search",
|
34
|
+
"endpoint": "mem0.memory_search",
|
35
|
+
"wrapper": mem0_wrap,
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"package": "mem0",
|
39
|
+
"object": "Memory.update",
|
40
|
+
"endpoint": "mem0.memory_update",
|
41
|
+
"wrapper": mem0_wrap,
|
42
|
+
},
|
43
|
+
{
|
44
|
+
"package": "mem0",
|
45
|
+
"object": "Memory.update",
|
46
|
+
"endpoint": "mem0.memory_update",
|
47
|
+
"wrapper": mem0_wrap,
|
48
|
+
},
|
49
|
+
]
|
50
|
+
|
51
|
+
class Mem0Instrumentor(BaseInstrumentor):
|
52
|
+
"""An instrumentor for mem0's client library."""
|
53
|
+
|
54
|
+
def instrumentation_dependencies(self) -> Collection[str]:
|
55
|
+
return _instruments
|
56
|
+
|
57
|
+
def _instrument(self, **kwargs):
|
58
|
+
application_name = kwargs.get("application_name")
|
59
|
+
environment = kwargs.get("environment")
|
60
|
+
tracer = kwargs.get("tracer")
|
61
|
+
pricing_info = kwargs.get("pricing_info")
|
62
|
+
trace_content = kwargs.get("trace_content")
|
63
|
+
version = importlib.metadata.version("mem0ai")
|
64
|
+
|
65
|
+
for wrapped_method in WRAPPED_METHODS:
|
66
|
+
wrap_package = wrapped_method.get("package")
|
67
|
+
wrap_object = wrapped_method.get("object")
|
68
|
+
gen_ai_endpoint = wrapped_method.get("endpoint")
|
69
|
+
wrapper = wrapped_method.get("wrapper")
|
70
|
+
wrap_function_wrapper(
|
71
|
+
wrap_package,
|
72
|
+
wrap_object,
|
73
|
+
wrapper(gen_ai_endpoint, version, environment, application_name,
|
74
|
+
tracer, pricing_info, trace_content),
|
75
|
+
)
|
76
|
+
|
77
|
+
@staticmethod
|
78
|
+
def _uninstrument(self, **kwargs):
|
79
|
+
pass
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument
|
2
|
+
"""
|
3
|
+
Module for monitoring mem0 applications.
|
4
|
+
"""
|
5
|
+
|
6
|
+
import logging
|
7
|
+
from opentelemetry.trace import SpanKind, Status, StatusCode
|
8
|
+
from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
|
9
|
+
from openlit.__helpers import handle_exception
|
10
|
+
from openlit.semcov import SemanticConvetion
|
11
|
+
|
12
|
+
# Initialize logger for logging potential issues and operations
|
13
|
+
logger = logging.getLogger(__name__)
|
14
|
+
|
15
|
+
def mem0_wrap(gen_ai_endpoint, version, environment, application_name,
|
16
|
+
tracer, pricing_info, trace_content):
|
17
|
+
"""
|
18
|
+
Creates a wrapper around a function call to trace and log its execution metrics.
|
19
|
+
|
20
|
+
This function wraps any given function to measure its execution time,
|
21
|
+
log its operation, and trace its execution using OpenTelemetry.
|
22
|
+
|
23
|
+
Parameters:
|
24
|
+
- gen_ai_endpoint (str): A descriptor or name for the endpoint being traced.
|
25
|
+
- version (str): The version of the mem0 application.
|
26
|
+
- environment (str): The deployment environment (e.g., 'production', 'development').
|
27
|
+
- application_name (str): Name of the mem0 application.
|
28
|
+
- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.
|
29
|
+
- pricing_info (dict): Information about the pricing for internal metrics (currently not used).
|
30
|
+
- trace_content (bool): Flag indicating whether to trace the content of the response.
|
31
|
+
|
32
|
+
Returns:
|
33
|
+
- function: A higher-order function that takes a function 'wrapped' and returns
|
34
|
+
a new function that wraps 'wrapped' with additional tracing and logging.
|
35
|
+
"""
|
36
|
+
|
37
|
+
def wrapper(wrapped, instance, args, kwargs):
|
38
|
+
"""
|
39
|
+
An inner wrapper function that executes the wrapped function, measures execution
|
40
|
+
time, and records trace data using OpenTelemetry.
|
41
|
+
|
42
|
+
Parameters:
|
43
|
+
- wrapped (Callable): The original function that this wrapper will execute.
|
44
|
+
- instance (object): The instance to which the wrapped function belongs. This
|
45
|
+
is used for instance methods. For static and classmethods,
|
46
|
+
this may be None.
|
47
|
+
- args (tuple): Positional arguments passed to the wrapped function.
|
48
|
+
- kwargs (dict): Keyword arguments passed to the wrapped function.
|
49
|
+
|
50
|
+
Returns:
|
51
|
+
- The result of the wrapped function call.
|
52
|
+
|
53
|
+
The wrapper initiates a span with the provided tracer, sets various attributes
|
54
|
+
on the span based on the function's execution and response, and ensures
|
55
|
+
errors are handled and logged appropriately.
|
56
|
+
"""
|
57
|
+
with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
|
58
|
+
response = wrapped(*args, **kwargs)
|
59
|
+
|
60
|
+
try:
|
61
|
+
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
62
|
+
span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
|
63
|
+
SemanticConvetion.GEN_AI_SYSTEM_MEM0)
|
64
|
+
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
|
65
|
+
gen_ai_endpoint)
|
66
|
+
span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
|
67
|
+
environment)
|
68
|
+
span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
|
69
|
+
SemanticConvetion.GEN_AI_TYPE_FRAMEWORK)
|
70
|
+
span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
|
71
|
+
application_name)
|
72
|
+
|
73
|
+
if gen_ai_endpoint == "mem0.memory_add":
|
74
|
+
span.set_attribute(SemanticConvetion.DB_METADATA,
|
75
|
+
str(kwargs.get('metadata', '')))
|
76
|
+
if response:
|
77
|
+
span.set_attribute(SemanticConvetion.GEN_AI_DATA_SOURCES,
|
78
|
+
len(response))
|
79
|
+
|
80
|
+
elif gen_ai_endpoint == "mem0.memory_get_all":
|
81
|
+
if response:
|
82
|
+
span.set_attribute(SemanticConvetion.GEN_AI_DATA_SOURCES,
|
83
|
+
len(response))
|
84
|
+
|
85
|
+
elif gen_ai_endpoint == "mem0.memory_get":
|
86
|
+
if response:
|
87
|
+
span.set_attribute(SemanticConvetion.GEN_AI_DATA_SOURCES,
|
88
|
+
len(response))
|
89
|
+
|
90
|
+
elif gen_ai_endpoint == "mem0.memory_search":
|
91
|
+
span.set_attribute(SemanticConvetion.DB_STATEMENT,
|
92
|
+
kwargs.get("query", ""))
|
93
|
+
|
94
|
+
elif gen_ai_endpoint == "mem0.memory_update":
|
95
|
+
span.set_attribute(SemanticConvetion.DB_UPDATE_ID,
|
96
|
+
kwargs.get("memory_id", ""))
|
97
|
+
|
98
|
+
elif gen_ai_endpoint == "mem0.memory_delete":
|
99
|
+
span.set_attribute(SemanticConvetion.DB_DELETE_ID,
|
100
|
+
kwargs.get("memory_id", ""))
|
101
|
+
|
102
|
+
|
103
|
+
span.set_status(Status(StatusCode.OK))
|
104
|
+
|
105
|
+
# Return original response
|
106
|
+
return response
|
107
|
+
|
108
|
+
except Exception as e:
|
109
|
+
handle_exception(span, e)
|
110
|
+
logger.error("Error in trace creation: %s", e)
|
111
|
+
|
112
|
+
# Return original response
|
113
|
+
return response
|
114
|
+
|
115
|
+
return wrapper
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
|
2
|
+
"""Initializer of Auto Instrumentation of MultiOn Functions"""
|
3
|
+
|
4
|
+
from typing import Collection
|
5
|
+
import importlib.metadata
|
6
|
+
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
7
|
+
from wrapt import wrap_function_wrapper
|
8
|
+
|
9
|
+
from openlit.instrumentation.multion.multion import (
|
10
|
+
multion_wrap
|
11
|
+
)
|
12
|
+
|
13
|
+
from openlit.instrumentation.multion.async_multion import (
|
14
|
+
async_multion_wrap
|
15
|
+
)
|
16
|
+
|
17
|
+
_instruments = ("multion >= 1.3.8",)
|
18
|
+
|
19
|
+
class MultiOnInstrumentor(BaseInstrumentor):
|
20
|
+
"""
|
21
|
+
An instrumentor for multion's client library.
|
22
|
+
"""
|
23
|
+
|
24
|
+
def instrumentation_dependencies(self) -> Collection[str]:
|
25
|
+
return _instruments
|
26
|
+
|
27
|
+
def _instrument(self, **kwargs):
|
28
|
+
application_name = kwargs.get("application_name", "default_application")
|
29
|
+
environment = kwargs.get("environment", "default_environment")
|
30
|
+
tracer = kwargs.get("tracer")
|
31
|
+
metrics = kwargs.get("metrics_dict")
|
32
|
+
pricing_info = kwargs.get("pricing_info", {})
|
33
|
+
trace_content = kwargs.get("trace_content", False)
|
34
|
+
disable_metrics = kwargs.get("disable_metrics")
|
35
|
+
version = importlib.metadata.version("multion")
|
36
|
+
|
37
|
+
# Synchronus
|
38
|
+
wrap_function_wrapper(
|
39
|
+
"multion.client",
|
40
|
+
"MultiOn.browse",
|
41
|
+
multion_wrap("multion.browse", version, environment, application_name,
|
42
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
43
|
+
)
|
44
|
+
wrap_function_wrapper(
|
45
|
+
"multion.client",
|
46
|
+
"MultiOn.retrieve",
|
47
|
+
multion_wrap("multion.retrieve", version, environment, application_name,
|
48
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
49
|
+
)
|
50
|
+
wrap_function_wrapper(
|
51
|
+
"multion.sessions.client",
|
52
|
+
"SessionsClient.create",
|
53
|
+
multion_wrap("multion.sessions.create", version, environment, application_name,
|
54
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
55
|
+
)
|
56
|
+
|
57
|
+
# Asynchronus
|
58
|
+
wrap_function_wrapper(
|
59
|
+
"multion.client",
|
60
|
+
"AsyncMultiOn.browse",
|
61
|
+
async_multion_wrap("multion.browse", version, environment, application_name,
|
62
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
63
|
+
)
|
64
|
+
wrap_function_wrapper(
|
65
|
+
"multion.client",
|
66
|
+
"AsyncMultiOn.retrieve",
|
67
|
+
async_multion_wrap("multion.retrieve", version, environment, application_name,
|
68
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
69
|
+
)
|
70
|
+
wrap_function_wrapper(
|
71
|
+
"multion.sessions.client",
|
72
|
+
"AsyncSessionsClient.create",
|
73
|
+
async_multion_wrap("multion.sessions.create", version, environment, application_name,
|
74
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
75
|
+
)
|
76
|
+
|
77
|
+
|
78
|
+
def _uninstrument(self, **kwargs):
|
79
|
+
# Proper uninstrumentation logic to revert patched methods
|
80
|
+
pass
|