openlit 1.30.5__py3-none-any.whl → 1.31.1__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 +13 -0
- openlit/instrumentation/ag2/__init__.py +50 -0
- openlit/instrumentation/ag2/ag2.py +98 -0
- openlit/instrumentation/dynamiq/__init__.py +64 -0
- openlit/instrumentation/dynamiq/dynamiq.py +108 -0
- openlit/instrumentation/phidata/__init__.py +42 -0
- openlit/instrumentation/phidata/phidata.py +98 -0
- openlit/semcov/__init__.py +8 -0
- {openlit-1.30.5.dist-info → openlit-1.31.1.dist-info}/METADATA +7 -7
- {openlit-1.30.5.dist-info → openlit-1.31.1.dist-info}/RECORD +12 -6
- {openlit-1.30.5.dist-info → openlit-1.31.1.dist-info}/LICENSE +0 -0
- {openlit-1.30.5.dist-info → openlit-1.31.1.dist-info}/WHEEL +0 -0
openlit/__init__.py
CHANGED
@@ -48,6 +48,9 @@ from openlit.instrumentation.milvus import MilvusInstrumentor
|
|
48
48
|
from openlit.instrumentation.transformers import TransformersInstrumentor
|
49
49
|
from openlit.instrumentation.litellm import LiteLLMInstrumentor
|
50
50
|
from openlit.instrumentation.crewai import CrewAIInstrumentor
|
51
|
+
from openlit.instrumentation.ag2 import AG2Instrumentor
|
52
|
+
from openlit.instrumentation.dynamiq import DynamiqInstrumentor
|
53
|
+
from openlit.instrumentation.phidata import PhidataInstrumentor
|
51
54
|
from openlit.instrumentation.gpu import GPUInstrumentor
|
52
55
|
import openlit.guard
|
53
56
|
import openlit.evals
|
@@ -232,6 +235,11 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
|
|
232
235
|
"transformers": "transformers",
|
233
236
|
"litellm": "litellm",
|
234
237
|
"crewai": "crewai",
|
238
|
+
"ag2": "ag2",
|
239
|
+
"autogen": "autogen",
|
240
|
+
"pyautogen": "pyautogen",
|
241
|
+
"dynamiq": "dynamiq",
|
242
|
+
"phidata": "phi",
|
235
243
|
}
|
236
244
|
|
237
245
|
invalid_instrumentors = [
|
@@ -311,6 +319,11 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
|
|
311
319
|
"transformers": TransformersInstrumentor(),
|
312
320
|
"litellm": LiteLLMInstrumentor(),
|
313
321
|
"crewai": CrewAIInstrumentor(),
|
322
|
+
"ag2": AG2Instrumentor(),
|
323
|
+
"autogen": AG2Instrumentor(),
|
324
|
+
"pyautogen": AG2Instrumentor(),
|
325
|
+
"dynamiq": DynamiqInstrumentor(),
|
326
|
+
"phidata": PhidataInstrumentor(),
|
314
327
|
}
|
315
328
|
|
316
329
|
# Initialize and instrument only the enabled instrumentors
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
|
2
|
+
"""Initializer of Auto Instrumentation of AG2 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.ag2.ag2 import (
|
10
|
+
wrap_ag2
|
11
|
+
)
|
12
|
+
|
13
|
+
_instruments = ("ag2 >= 0.3.2",)
|
14
|
+
|
15
|
+
class AG2Instrumentor(BaseInstrumentor):
|
16
|
+
"""
|
17
|
+
An instrumentor for AG2's client library.
|
18
|
+
"""
|
19
|
+
|
20
|
+
def instrumentation_dependencies(self) -> Collection[str]:
|
21
|
+
return _instruments
|
22
|
+
|
23
|
+
def _instrument(self, **kwargs):
|
24
|
+
application_name = kwargs.get("application_name", "default_application")
|
25
|
+
environment = kwargs.get("environment", "default_environment")
|
26
|
+
tracer = kwargs.get("tracer")
|
27
|
+
metrics = kwargs.get("metrics_dict")
|
28
|
+
pricing_info = kwargs.get("pricing_info", {})
|
29
|
+
trace_content = kwargs.get("trace_content", False)
|
30
|
+
disable_metrics = kwargs.get("disable_metrics")
|
31
|
+
version = importlib.metadata.version("ag2")
|
32
|
+
|
33
|
+
wrap_function_wrapper(
|
34
|
+
"autogen.agentchat.conversable_agent",
|
35
|
+
"ConversableAgent.initiate_chat",
|
36
|
+
wrap_ag2("ag2.initiate_chat", version, environment, application_name,
|
37
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
38
|
+
)
|
39
|
+
|
40
|
+
wrap_function_wrapper(
|
41
|
+
"autogen.agentchat.conversable_agent",
|
42
|
+
"ConversableAgent.generate_reply",
|
43
|
+
wrap_ag2("ag2.generate_reply", version, environment, application_name,
|
44
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
45
|
+
)
|
46
|
+
|
47
|
+
|
48
|
+
def _uninstrument(self, **kwargs):
|
49
|
+
# Proper uninstrumentation logic to revert patched methods
|
50
|
+
pass
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument
|
2
|
+
"""
|
3
|
+
Module for monitoring AG2.
|
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_ag2(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
|
+
if isinstance(instance.__dict__.get('llm_config'), dict):
|
62
|
+
llm_model = instance.__dict__['llm_config'].get('model', 'gpt-4')
|
63
|
+
else:
|
64
|
+
# Fallback to default if 'llm_config' is not a dictionary
|
65
|
+
llm_model = None
|
66
|
+
|
67
|
+
try:
|
68
|
+
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
69
|
+
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
|
70
|
+
gen_ai_endpoint)
|
71
|
+
span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
|
72
|
+
SemanticConvetion.GEN_AI_SYSTEM_AG2)
|
73
|
+
span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
|
74
|
+
environment)
|
75
|
+
span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
|
76
|
+
application_name)
|
77
|
+
span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
|
78
|
+
SemanticConvetion.GEN_AI_TYPE_AGENT)
|
79
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ROLE,
|
80
|
+
instance.name)
|
81
|
+
if llm_model:
|
82
|
+
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
|
83
|
+
llm_model)
|
84
|
+
|
85
|
+
|
86
|
+
span.set_status(Status(StatusCode.OK))
|
87
|
+
|
88
|
+
# Return original response
|
89
|
+
return response
|
90
|
+
|
91
|
+
except Exception as e:
|
92
|
+
handle_exception(span, e)
|
93
|
+
logger.error("Error in trace creation: %s", e)
|
94
|
+
|
95
|
+
# Return original response
|
96
|
+
return response
|
97
|
+
|
98
|
+
return wrapper
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
|
2
|
+
"""Initializer of Auto Instrumentation of Dynamiq 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.dynamiq.dynamiq import (
|
10
|
+
dynamiq_wrap
|
11
|
+
)
|
12
|
+
|
13
|
+
_instruments = ("dynamiq >= 0.4.0",)
|
14
|
+
|
15
|
+
class DynamiqInstrumentor(BaseInstrumentor):
|
16
|
+
"""
|
17
|
+
An instrumentor for dynamiq's client library.
|
18
|
+
"""
|
19
|
+
|
20
|
+
def instrumentation_dependencies(self) -> Collection[str]:
|
21
|
+
return _instruments
|
22
|
+
|
23
|
+
def _instrument(self, **kwargs):
|
24
|
+
application_name = kwargs.get("application_name", "default_application")
|
25
|
+
environment = kwargs.get("environment", "default_environment")
|
26
|
+
tracer = kwargs.get("tracer")
|
27
|
+
metrics = kwargs.get("metrics_dict")
|
28
|
+
pricing_info = kwargs.get("pricing_info", {})
|
29
|
+
trace_content = kwargs.get("trace_content", False)
|
30
|
+
disable_metrics = kwargs.get("disable_metrics")
|
31
|
+
version = importlib.metadata.version("dynamiq")
|
32
|
+
|
33
|
+
wrap_function_wrapper(
|
34
|
+
"dynamiq.nodes.agents.base",
|
35
|
+
"Agent.run",
|
36
|
+
dynamiq_wrap("dynamiq.agent_run", version, environment, application_name,
|
37
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
38
|
+
)
|
39
|
+
|
40
|
+
wrap_function_wrapper(
|
41
|
+
"dynamiq",
|
42
|
+
"Workflow.run",
|
43
|
+
dynamiq_wrap("dynamiq.workflow_run", version, environment, application_name,
|
44
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
45
|
+
)
|
46
|
+
|
47
|
+
wrap_function_wrapper(
|
48
|
+
"dynamiq.memory",
|
49
|
+
"Memory.add",
|
50
|
+
dynamiq_wrap("dynamiq.memory_add", version, environment, application_name,
|
51
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
52
|
+
)
|
53
|
+
|
54
|
+
wrap_function_wrapper(
|
55
|
+
"dynamiq.memory",
|
56
|
+
"Memory.search",
|
57
|
+
dynamiq_wrap("dynamiq.memory_search", version, environment, application_name,
|
58
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
59
|
+
)
|
60
|
+
|
61
|
+
|
62
|
+
def _uninstrument(self, **kwargs):
|
63
|
+
# Proper uninstrumentation logic to revert patched methods
|
64
|
+
pass
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument
|
2
|
+
"""
|
3
|
+
Module for monitoring Dynamiq calls.
|
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 (
|
10
|
+
handle_exception,
|
11
|
+
)
|
12
|
+
from openlit.semcov import SemanticConvetion
|
13
|
+
|
14
|
+
# Initialize logger for logging potential issues and operations
|
15
|
+
logger = logging.getLogger(__name__)
|
16
|
+
|
17
|
+
def dynamiq_wrap(gen_ai_endpoint, version, environment, application_name,
|
18
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics):
|
19
|
+
"""
|
20
|
+
Generates a telemetry wrapper for chat completions to collect metrics.
|
21
|
+
|
22
|
+
Args:
|
23
|
+
gen_ai_endpoint: Endpoint identifier for logging and tracing.
|
24
|
+
version: Version of the monitoring package.
|
25
|
+
environment: Deployment environment (e.g., production, staging).
|
26
|
+
application_name: Name of the application using the dynamiq Agent.
|
27
|
+
tracer: OpenTelemetry tracer for creating spans.
|
28
|
+
pricing_info: Information used for calculating the cost of dynamiq usage.
|
29
|
+
trace_content: Flag indicating whether to trace the actual content.
|
30
|
+
|
31
|
+
Returns:
|
32
|
+
A function that wraps the chat completions method to add telemetry.
|
33
|
+
"""
|
34
|
+
|
35
|
+
def wrapper(wrapped, instance, args, kwargs):
|
36
|
+
"""
|
37
|
+
Wraps the 'chat.completions' API call to add telemetry.
|
38
|
+
|
39
|
+
This collects metrics such as execution time, cost, and token usage, and handles errors
|
40
|
+
gracefully, adding details to the trace for observability.
|
41
|
+
|
42
|
+
Args:
|
43
|
+
wrapped: The original 'chat.completions' method to be wrapped.
|
44
|
+
instance: The instance of the class where the original method is defined.
|
45
|
+
args: Positional arguments for the 'chat.completions' method.
|
46
|
+
kwargs: Keyword arguments for the 'chat.completions' method.
|
47
|
+
|
48
|
+
Returns:
|
49
|
+
The response from the original 'chat.completions' method.
|
50
|
+
"""
|
51
|
+
|
52
|
+
# pylint: disable=line-too-long
|
53
|
+
with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
|
54
|
+
response = wrapped(*args, **kwargs)
|
55
|
+
|
56
|
+
try:
|
57
|
+
# Set base span attribues
|
58
|
+
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
59
|
+
span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
|
60
|
+
SemanticConvetion.GEN_AI_SYSTEM_DYNAMIQ)
|
61
|
+
span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
|
62
|
+
SemanticConvetion.GEN_AI_TYPE_AGENT)
|
63
|
+
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
|
64
|
+
gen_ai_endpoint)
|
65
|
+
span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
|
66
|
+
application_name)
|
67
|
+
|
68
|
+
if gen_ai_endpoint == "dynamiq.agent_run":
|
69
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ID,
|
70
|
+
getattr(instance, 'id', '') or '')
|
71
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ROLE,
|
72
|
+
getattr(instance, 'name', '') or '')
|
73
|
+
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
|
74
|
+
getattr(getattr(instance, 'llm', None), 'model', '') or '')
|
75
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TYPE,
|
76
|
+
str(getattr(instance, 'type', '')) or '')
|
77
|
+
|
78
|
+
elif gen_ai_endpoint == "dynamiq.workflow_run":
|
79
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ID,
|
80
|
+
getattr(instance, 'id', '') or '')
|
81
|
+
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
|
82
|
+
getattr(getattr(instance.flow, 'nodes', [None])[0], 'model', 'default_model'))
|
83
|
+
|
84
|
+
elif gen_ai_endpoint == "dynamiq.memory_add":
|
85
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
86
|
+
SemanticConvetion.DB_OPERATION_ADD)
|
87
|
+
span.set_attribute(SemanticConvetion.DB_METADATA, str(kwargs.get('metadata', '')))
|
88
|
+
|
89
|
+
elif gen_ai_endpoint == "dynamiq.memory_search":
|
90
|
+
query_value = kwargs.get('query', '') or (args[0] if args else '')
|
91
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
92
|
+
SemanticConvetion.DB_OPERATION_GET)
|
93
|
+
span.set_attribute(SemanticConvetion.DB_FILTER, str(kwargs.get('filters', '')))
|
94
|
+
span.set_attribute(SemanticConvetion.DB_STATEMENT, query_value)
|
95
|
+
|
96
|
+
span.set_status(Status(StatusCode.OK))
|
97
|
+
|
98
|
+
# Return original response
|
99
|
+
return response
|
100
|
+
|
101
|
+
except Exception as e:
|
102
|
+
handle_exception(span, e)
|
103
|
+
logger.error("Error in trace creation: %s", e)
|
104
|
+
|
105
|
+
# Return original response
|
106
|
+
return response
|
107
|
+
|
108
|
+
return wrapper
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
|
2
|
+
"""Initializer of Auto Instrumentation of Phidata 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.phidata.phidata import (
|
10
|
+
phidata_wrap
|
11
|
+
)
|
12
|
+
|
13
|
+
_instruments = ("phidata >= 2.5.32",)
|
14
|
+
|
15
|
+
class PhidataInstrumentor(BaseInstrumentor):
|
16
|
+
"""
|
17
|
+
An instrumentor for Phidata's client library.
|
18
|
+
"""
|
19
|
+
|
20
|
+
def instrumentation_dependencies(self) -> Collection[str]:
|
21
|
+
return _instruments
|
22
|
+
|
23
|
+
def _instrument(self, **kwargs):
|
24
|
+
application_name = kwargs.get("application_name", "default_application")
|
25
|
+
environment = kwargs.get("environment", "default_environment")
|
26
|
+
tracer = kwargs.get("tracer")
|
27
|
+
metrics = kwargs.get("metrics_dict")
|
28
|
+
pricing_info = kwargs.get("pricing_info", {})
|
29
|
+
trace_content = kwargs.get("trace_content", False)
|
30
|
+
disable_metrics = kwargs.get("disable_metrics")
|
31
|
+
version = importlib.metadata.version("phidata")
|
32
|
+
|
33
|
+
wrap_function_wrapper(
|
34
|
+
"phi.agent",
|
35
|
+
"Agent.print_response",
|
36
|
+
phidata_wrap("phidata.print_response", version, environment, application_name,
|
37
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
38
|
+
)
|
39
|
+
|
40
|
+
def _uninstrument(self, **kwargs):
|
41
|
+
# Proper uninstrumentation logic to revert patched methods
|
42
|
+
pass
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument
|
2
|
+
"""
|
3
|
+
Module for monitoring Phidata calls.
|
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 (
|
10
|
+
handle_exception,
|
11
|
+
)
|
12
|
+
from openlit.semcov import SemanticConvetion
|
13
|
+
|
14
|
+
# Initialize logger for logging potential issues and operations
|
15
|
+
logger = logging.getLogger(__name__)
|
16
|
+
|
17
|
+
def phidata_wrap(gen_ai_endpoint, version, environment, application_name,
|
18
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics):
|
19
|
+
"""
|
20
|
+
Generates a telemetry wrapper for chat completions to collect metrics.
|
21
|
+
|
22
|
+
Args:
|
23
|
+
gen_ai_endpoint: Endpoint identifier for logging and tracing.
|
24
|
+
version: Version of the monitoring package.
|
25
|
+
environment: Deployment environment (e.g., production, staging).
|
26
|
+
application_name: Name of the application using the Phidata Agent.
|
27
|
+
tracer: OpenTelemetry tracer for creating spans.
|
28
|
+
pricing_info: Information used for calculating the cost of Phidata usage.
|
29
|
+
trace_content: Flag indicating whether to trace the actual content.
|
30
|
+
|
31
|
+
Returns:
|
32
|
+
A function that wraps the chat completions method to add telemetry.
|
33
|
+
"""
|
34
|
+
|
35
|
+
def wrapper(wrapped, instance, args, kwargs):
|
36
|
+
"""
|
37
|
+
Wraps the 'chat.completions' API call to add telemetry.
|
38
|
+
|
39
|
+
This collects metrics such as execution time, cost, and token usage, and handles errors
|
40
|
+
gracefully, adding details to the trace for observability.
|
41
|
+
|
42
|
+
Args:
|
43
|
+
wrapped: The original 'chat.completions' method to be wrapped.
|
44
|
+
instance: The instance of the class where the original method is defined.
|
45
|
+
args: Positional arguments for the 'chat.completions' method.
|
46
|
+
kwargs: Keyword arguments for the 'chat.completions' method.
|
47
|
+
|
48
|
+
Returns:
|
49
|
+
The response from the original 'chat.completions' method.
|
50
|
+
"""
|
51
|
+
|
52
|
+
# pylint: disable=line-too-long
|
53
|
+
with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
|
54
|
+
response = wrapped(*args, **kwargs)
|
55
|
+
|
56
|
+
try:
|
57
|
+
# Set base span attribues
|
58
|
+
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
59
|
+
span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
|
60
|
+
SemanticConvetion.GEN_AI_SYSTEM_PHIDATA)
|
61
|
+
span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
|
62
|
+
SemanticConvetion.GEN_AI_TYPE_AGENT)
|
63
|
+
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
|
64
|
+
gen_ai_endpoint)
|
65
|
+
span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
|
66
|
+
application_name)
|
67
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ID,
|
68
|
+
getattr(instance, 'agent_id', '') or '')
|
69
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ROLE,
|
70
|
+
getattr(instance, 'name', '') or '')
|
71
|
+
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
|
72
|
+
getattr(getattr(instance, 'model', None), 'id', '') or '')
|
73
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TOOLS,
|
74
|
+
str(getattr(instance, 'tools', '')) or '')
|
75
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_CONTEXT,
|
76
|
+
str(getattr(instance, 'knowledge', '')) or '')
|
77
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TASK,
|
78
|
+
str(getattr(instance, 'task', '')) or '')
|
79
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_INSTRUCTIONS,
|
80
|
+
str(getattr(instance, 'instructions', '')) or '')
|
81
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_STORAGE,
|
82
|
+
str(getattr(instance, 'storage', '')) or '')
|
83
|
+
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ENABLE_HISTORY,
|
84
|
+
str(getattr(instance, 'add_history_to_messages', '')) or '')
|
85
|
+
|
86
|
+
span.set_status(Status(StatusCode.OK))
|
87
|
+
|
88
|
+
# Return original response
|
89
|
+
return response
|
90
|
+
|
91
|
+
except Exception as e:
|
92
|
+
handle_exception(span, e)
|
93
|
+
logger.error("Error in trace creation: %s", e)
|
94
|
+
|
95
|
+
# Return original response
|
96
|
+
return response
|
97
|
+
|
98
|
+
return wrapper
|
openlit/semcov/__init__.py
CHANGED
@@ -111,6 +111,9 @@ class SemanticConvetion:
|
|
111
111
|
GEN_AI_SYSTEM_EMBEDCHAIN = "embedchain"
|
112
112
|
GEN_AI_SYSTEM_LITELLM = "litellm"
|
113
113
|
GEN_AI_SYSTEM_CREWAI = "crewai"
|
114
|
+
GEN_AI_SYSTEM_AG2 = "ag2"
|
115
|
+
GEN_AI_SYSTEM_DYNAMIQ = "dynamiq"
|
116
|
+
GEN_AI_SYSTEM_PHIDATA = "phidata"
|
114
117
|
|
115
118
|
# Vector DB
|
116
119
|
DB_REQUESTS = "db.total.requests"
|
@@ -132,6 +135,7 @@ class SemanticConvetion:
|
|
132
135
|
DB_OPERATION_PEEK = "peek"
|
133
136
|
DB_ID_COUNT = "db.ids_count"
|
134
137
|
DB_VECTOR_COUNT = "db.vector_count"
|
138
|
+
DB_METADATA = "db.metadata"
|
135
139
|
DB_METADATA_COUNT = "db.metadatas_count"
|
136
140
|
DB_DOCUMENTS_COUNT = "db.documents_count"
|
137
141
|
DB_PAYLOAD_COUNT = "db.payload_count"
|
@@ -159,17 +163,21 @@ class SemanticConvetion:
|
|
159
163
|
|
160
164
|
# Agents
|
161
165
|
GEN_AI_AGENT_ID = "gen_ai.agent.id"
|
166
|
+
GEN_AI_AGENT_TYPE = "gen_ai.agent.type"
|
162
167
|
GEN_AI_AGENT_TASK_ID = "gen_ai.agent.task.id"
|
163
168
|
GEN_AI_AGENT_ROLE = "gen_ai.agent.role"
|
164
169
|
GEN_AI_AGENT_GOAL = "gen_ai.agent.goal"
|
165
170
|
GEN_AI_AGENT_CONTEXT = "gen_ai.agent.context"
|
166
171
|
GEN_AI_AGENT_ENABLE_CACHE = "gen_ai.agent.enable_cache"
|
172
|
+
GEN_AI_AGENT_ENABLE_HISTORY = "gen_ai.agent.enable_history"
|
167
173
|
GEN_AI_AGENT_ALLOW_DELEGATION = "gen_ai.agent.allow_delegation"
|
168
174
|
GEN_AI_AGENT_ALLOW_CODE_EXECUTION = "gen_ai.agent.allow_code_execution"
|
169
175
|
GEN_AI_AGENT_MAX_RETRY_LIMIT = "gen_ai.agent.max_retry_limit"
|
170
176
|
GEN_AI_AGENT_TOOLS = "gen_ai.agent.tools"
|
171
177
|
GEN_AI_AGENT_TOOL_RESULTS = "gen_ai.agent.tool_results"
|
172
178
|
GEN_AI_AGENT_TASK = "gen_ai.agent.task"
|
179
|
+
GEN_AI_AGENT_INSTRUCTIONS = "gen_ai.agent.instructions"
|
180
|
+
GEN_AI_AGENT_STORAGE = "gen_ai.agent.storage"
|
173
181
|
GEN_AI_AGENT_EXPECTED_OUTPUT = "gen_ai.agent.expected_output"
|
174
182
|
GEN_AI_AGENT_ACTUAL_OUTPUT = "gen_ai.agent.actual_output"
|
175
183
|
GEN_AI_AGENT_HUMAN_INPUT = "gen_ai.agent.human_input"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: openlit
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.31.1
|
4
4
|
Summary: OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications and GPUs, facilitating the integration of observability into your GenAI-driven projects
|
5
5
|
Home-page: https://github.com/openlit/openlit/tree/main/openlit/python
|
6
6
|
Keywords: OpenTelemetry,otel,otlp,llm,tracing,openai,anthropic,claude,cohere,llm monitoring,observability,monitoring,gpt,Generative AI,chatGPT,gpu
|
@@ -66,16 +66,16 @@ This project proudly follows and maintains the [Semantic Conventions](https://gi
|
|
66
66
|
| LLMs | Vector DBs | Frameworks | GPUs |
|
67
67
|
|--------------------------------------------------------------------------|----------------------------------------------|-------------------------------------------------|---------------|
|
68
68
|
| [✅ OpenAI](https://docs.openlit.io/latest/integrations/openai) | [✅ ChromaDB](https://docs.openlit.io/latest/integrations/chromadb) | [✅ Langchain](https://docs.openlit.io/latest/integrations/langchain) | [✅ NVIDIA](https://docs.openlit.io/latest/integrations/nvidia-gpu) |
|
69
|
-
| [✅ Ollama](https://docs.openlit.io/latest/integrations/ollama) | [✅ Pinecone](https://docs.openlit.io/latest/integrations/pinecone) | [✅ LiteLLM](https://docs.openlit.io/latest/integrations/litellm) | [✅ AMD](
|
69
|
+
| [✅ Ollama](https://docs.openlit.io/latest/integrations/ollama) | [✅ Pinecone](https://docs.openlit.io/latest/integrations/pinecone) | [✅ LiteLLM](https://docs.openlit.io/latest/integrations/litellm) | [✅ AMD](https://docs.openlit.io/latest/integrations/amd-gpu) |
|
70
70
|
| [✅ Anthropic](https://docs.openlit.io/latest/integrations/anthropic) | [✅ Qdrant](https://docs.openlit.io/latest/integrations/qdrant) | [✅ LlamaIndex](https://docs.openlit.io/latest/integrations/llama-index) | |
|
71
71
|
| [✅ GPT4All](https://docs.openlit.io/latest/integrations/gpt4all) | [✅ Milvus](https://docs.openlit.io/latest/integrations/milvus) | [✅ Haystack](https://docs.openlit.io/latest/integrations/haystack) | |
|
72
72
|
| [✅ Cohere](https://docs.openlit.io/latest/integrations/cohere) | | [✅ EmbedChain](https://docs.openlit.io/latest/integrations/embedchain) | |
|
73
73
|
| [✅ Mistral](https://docs.openlit.io/latest/integrations/mistral) | | [✅ Guardrails](https://docs.openlit.io/latest/integrations/guardrails) | |
|
74
74
|
| [✅ Azure OpenAI](https://docs.openlit.io/latest/integrations/azure-openai) | | [✅ CrewAI](https://docs.openlit.io/latest/integrations/crewai) | |
|
75
|
-
| [✅ Azure AI Inference](https://docs.openlit.io/latest/integrations/azure-ai-inference) | | [✅ DSPy](https://docs.openlit.io/latest/integrations/dspy)
|
76
|
-
| [✅ GitHub AI Models](https://docs.openlit.io/latest/integrations/github-models) | |
|
77
|
-
| [✅ HuggingFace Transformers](https://docs.openlit.io/latest/integrations/huggingface) | |
|
78
|
-
| [✅ Amazon Bedrock](https://docs.openlit.io/latest/integrations/bedrock) | |
|
75
|
+
| [✅ Azure AI Inference](https://docs.openlit.io/latest/integrations/azure-ai-inference) | | [✅ DSPy](https://docs.openlit.io/latest/integrations/dspy) | |
|
76
|
+
| [✅ GitHub AI Models](https://docs.openlit.io/latest/integrations/github-models) | | [✅ AG2](https://docs.openlit.io/latest/integrations/ag2) | |
|
77
|
+
| [✅ HuggingFace Transformers](https://docs.openlit.io/latest/integrations/huggingface) | | [✅ Dynamiq](https://docs.openlit.io/latest/integrations/dynamiq) | |
|
78
|
+
| [✅ Amazon Bedrock](https://docs.openlit.io/latest/integrations/bedrock) | | [✅ Phidata](https://docs.openlit.io/latest/integrations/phidata) | |
|
79
79
|
| [✅ Vertex AI](https://docs.openlit.io/latest/integrations/vertexai) | | | |
|
80
80
|
| [✅ Groq](https://docs.openlit.io/latest/integrations/groq) | | | |
|
81
81
|
| [✅ ElevenLabs](https://docs.openlit.io/latest/integrations/elevenlabs) | | | |
|
@@ -84,7 +84,6 @@ This project proudly follows and maintains the [Semantic Conventions](https://gi
|
|
84
84
|
| [✅ Google AI Studio](https://docs.openlit.io/latest/integrations/google-ai-studio) | | | |
|
85
85
|
| [✅ NVIDIA NIM](https://docs.openlit.io/latest/integrations/nvidia-nim) | | | |
|
86
86
|
|
87
|
-
|
88
87
|
## Supported Destinations
|
89
88
|
- [✅ OpenTelemetry Collector](https://docs.openlit.io/latest/connections/otelcol)
|
90
89
|
- [✅ Prometheus + Tempo](https://docs.openlit.io/latest/connections/prometheus-tempo)
|
@@ -92,6 +91,7 @@ This project proudly follows and maintains the [Semantic Conventions](https://gi
|
|
92
91
|
- [✅ Grafana Cloud](https://docs.openlit.io/latest/connections/grafanacloud)
|
93
92
|
- [✅ New Relic](https://docs.openlit.io/latest/connections/new-relic)
|
94
93
|
- [✅ Elastic](https://docs.openlit.io/latest/connections/elastic)
|
94
|
+
- [✅ Middleware.io](https://docs.openlit.io/latest/connections/middleware)
|
95
95
|
- [✅ HyperDX](https://docs.openlit.io/latest/connections/hyperdx)
|
96
96
|
- [✅ DataDog](https://docs.openlit.io/latest/connections/datadog)
|
97
97
|
- [✅ SigNoz](https://docs.openlit.io/latest/connections/signoz)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
openlit/__helpers.py,sha256=2OkGKOdsd9Hc011WxR70OqDlO6c4mZcu6McGuW1uAdA,6316
|
2
|
-
openlit/__init__.py,sha256=
|
2
|
+
openlit/__init__.py,sha256=WgRRoCn_FeqLJ67AQIVgNwuhsThaS3_mF92AAWIcGgk,20216
|
3
3
|
openlit/evals/__init__.py,sha256=nJe99nuLo1b5rf7pt9U9BCdSDedzbVi2Fj96cgl7msM,380
|
4
4
|
openlit/evals/all.py,sha256=oWrue3PotE-rB5WePG3MRYSA-ro6WivkclSHjYlAqGs,7154
|
5
5
|
openlit/evals/bias_detection.py,sha256=mCdsfK7x1vX7S3psC3g641IMlZ-7df3h-V6eiICj5N8,8154
|
@@ -12,6 +12,8 @@ openlit/guard/prompt_injection.py,sha256=3e4DKxB7QDzM-xPCpwEuureiH_2s_OTJ9BSckkn
|
|
12
12
|
openlit/guard/restrict_topic.py,sha256=KTuWa7XeMsV4oXxOrD1CYZV0wXWxTfA0H3p_6q_IOsk,6444
|
13
13
|
openlit/guard/sensitive_topic.py,sha256=RgVw_laFERv0nNdzBsAd2_3yLomMOK-gVq-P7oj1bTk,5552
|
14
14
|
openlit/guard/utils.py,sha256=x0-_hAtNa_ogYR2GfnwiBF1rlqaXtaJ-rJeGguTDe-Q,7663
|
15
|
+
openlit/instrumentation/ag2/__init__.py,sha256=Nf9cDoXB16NYgZisvVQduFYJ5fpU90CNlMrIF4pSH-Y,1827
|
16
|
+
openlit/instrumentation/ag2/ag2.py,sha256=_ncg8RqUH-wXMYfaOYx2bcQOrOrDMVVm0EZAEkWdBn0,4444
|
15
17
|
openlit/instrumentation/anthropic/__init__.py,sha256=oaU53BOPyfUKbEzYvLr1DPymDluurSnwo4Hernf2XdU,1955
|
16
18
|
openlit/instrumentation/anthropic/anthropic.py,sha256=y7CEGhKOGHWt8G_5Phr4qPJTfPGRJIAr9Yk6nM3CcvM,16775
|
17
19
|
openlit/instrumentation/anthropic/async_anthropic.py,sha256=Zz1KRKIG9wGn0quOoLvjORC-49IvHQpJ6GBdB-4PfCQ,16816
|
@@ -26,6 +28,8 @@ openlit/instrumentation/cohere/__init__.py,sha256=PC5T1qIg9pwLNocBP_WjG5B_6p_z01
|
|
26
28
|
openlit/instrumentation/cohere/cohere.py,sha256=62-P2K39v6pIJme6vTVViLJ9PP8q_UWkTv2l3Wa2gHA,21217
|
27
29
|
openlit/instrumentation/crewai/__init__.py,sha256=cETkkwnKYEMAKlMrHbZ9-RvcRUPYaSNqNIhy2-vCDK8,1794
|
28
30
|
openlit/instrumentation/crewai/crewai.py,sha256=V0ZAlNf6vPL6nZs_XvQYG2DqpgfbX_37yMnScAu3dsk,6917
|
31
|
+
openlit/instrumentation/dynamiq/__init__.py,sha256=2uIHHxFWca0g2YLO2RBfi2Al6uWUYvVZBfDiPOHCdpQ,2331
|
32
|
+
openlit/instrumentation/dynamiq/dynamiq.py,sha256=ymEctNepwQ_9YGSoR_Sf1NwmSLwmGnFfWJZe3FZAE9M,5128
|
29
33
|
openlit/instrumentation/elevenlabs/__init__.py,sha256=BZjAe-kzFJpKxT0tKksXVfZgirvgEp8qM3SfegWU5co,2631
|
30
34
|
openlit/instrumentation/elevenlabs/async_elevenlabs.py,sha256=yMYACh95SFr5EYklKnXw2DrPFa3iIgM4qQMWjO1itMU,5690
|
31
35
|
openlit/instrumentation/elevenlabs/elevenlabs.py,sha256=mFnD7sgT47OxaXJz0Vc1nrNjXEpcGQDj5run3gA48Lw,6089
|
@@ -62,6 +66,8 @@ openlit/instrumentation/openai/async_azure_openai.py,sha256=XbST1UE_zXzNL6RX2XwC
|
|
62
66
|
openlit/instrumentation/openai/async_openai.py,sha256=XFsfN81mbmdgRON2dwmt8pypqoTnlrNWer1eit7wZbQ,50176
|
63
67
|
openlit/instrumentation/openai/azure_openai.py,sha256=dZUc5MtCwg_sZJWiruG6exYGhPAm-339sqs3sKZNRPU,48761
|
64
68
|
openlit/instrumentation/openai/openai.py,sha256=qP3ahUyMGjmq2ZB8apqnERal7kz49uW5DaxDU9FBQdk,50005
|
69
|
+
openlit/instrumentation/phidata/__init__.py,sha256=rfPCXYOIsJbxChee2p269UzkJ1Z-pvQbii7Fgrw1v2g,1527
|
70
|
+
openlit/instrumentation/phidata/phidata.py,sha256=9Aza2bLgeq688Ahyy7ekbxpSh4RTD7FFKtLmv4TNbrw,4667
|
65
71
|
openlit/instrumentation/pinecone/__init__.py,sha256=Mv9bElqNs07_JQkYyNnO0wOM3hdbprmw7sttdMeKC7g,2526
|
66
72
|
openlit/instrumentation/pinecone/pinecone.py,sha256=0EhLmtOuvwWVvAKh3e56wyd8wzQq1oaLOmF15SVHxVE,8765
|
67
73
|
openlit/instrumentation/qdrant/__init__.py,sha256=GMlZgRBKoQMgrL4cFbAKwytfdTHLzJEIuTQMxp0uZO0,8940
|
@@ -76,8 +82,8 @@ openlit/instrumentation/vllm/__init__.py,sha256=OVWalQ1dXvip1DUsjUGaHX4J-2FrSp-T
|
|
76
82
|
openlit/instrumentation/vllm/vllm.py,sha256=lDzM7F5pgxvh8nKL0dcKB4TD0Mc9wXOWeXOsOGN7Wd8,6527
|
77
83
|
openlit/otel/metrics.py,sha256=y7SQDTyfLakMrz0V4DThN-WAeap7YZzyndeYGSP6nVg,4516
|
78
84
|
openlit/otel/tracing.py,sha256=fG3vl-flSZ30whCi7rrG25PlkIhhr8PhnfJYCkZzCD0,3895
|
79
|
-
openlit/semcov/__init__.py,sha256=
|
80
|
-
openlit-1.
|
81
|
-
openlit-1.
|
82
|
-
openlit-1.
|
83
|
-
openlit-1.
|
85
|
+
openlit/semcov/__init__.py,sha256=DpZ690Tp-ks6QunvHCOV42gnedKkJRk-U7ZnCtJmavY,9493
|
86
|
+
openlit-1.31.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
87
|
+
openlit-1.31.1.dist-info/METADATA,sha256=mdzQDsOaxfPqVUIb7F_VrYcJD2fB_XPM7g7hvezVXG8,21122
|
88
|
+
openlit-1.31.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
89
|
+
openlit-1.31.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|