openlit 1.8.0__py3-none-any.whl → 1.10.0__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 +3 -0
- openlit/instrumentation/chroma/chroma.py +23 -21
- openlit/instrumentation/cohere/cohere.py +4 -3
- openlit/instrumentation/embedchain/__init__.py +55 -0
- openlit/instrumentation/embedchain/embedchain.py +165 -0
- openlit/instrumentation/llamaindex/__init__.py +1 -1
- openlit/instrumentation/qdrant/qdrant.py +5 -5
- openlit/semcov/__init__.py +7 -0
- {openlit-1.8.0.dist-info → openlit-1.10.0.dist-info}/METADATA +72 -56
- {openlit-1.8.0.dist-info → openlit-1.10.0.dist-info}/RECORD +12 -10
- {openlit-1.8.0.dist-info → openlit-1.10.0.dist-info}/LICENSE +0 -0
- {openlit-1.8.0.dist-info → openlit-1.10.0.dist-info}/WHEEL +0 -0
openlit/__init__.py
CHANGED
@@ -24,6 +24,7 @@ from openlit.instrumentation.ollama import OllamaInstrumentor
|
|
24
24
|
from openlit.instrumentation.langchain import LangChainInstrumentor
|
25
25
|
from openlit.instrumentation.llamaindex import LlamaIndexInstrumentor
|
26
26
|
from openlit.instrumentation.haystack import HaystackInstrumentor
|
27
|
+
from openlit.instrumentation.embedchain import EmbedChainInstrumentor
|
27
28
|
from openlit.instrumentation.chroma import ChromaInstrumentor
|
28
29
|
from openlit.instrumentation.pinecone import PineconeInstrumentor
|
29
30
|
from openlit.instrumentation.qdrant import QdrantInstrumentor
|
@@ -163,6 +164,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
|
|
163
164
|
"langchain": "langchain",
|
164
165
|
"llama_index": "llama_index",
|
165
166
|
"haystack": "haystack",
|
167
|
+
"embedchain": "embedchain",
|
166
168
|
"chroma": "chromadb",
|
167
169
|
"pinecone": "pinecone",
|
168
170
|
"qdrant": "qdrant_client",
|
@@ -217,6 +219,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
|
|
217
219
|
"langchain": LangChainInstrumentor(),
|
218
220
|
"llama_index": LlamaIndexInstrumentor(),
|
219
221
|
"haystack": HaystackInstrumentor(),
|
222
|
+
"embedchain": EmbedChainInstrumentor(),
|
220
223
|
"chroma": ChromaInstrumentor(),
|
221
224
|
"pinecone": PineconeInstrumentor(),
|
222
225
|
"qdrant": QdrantInstrumentor(),
|
@@ -16,11 +16,13 @@ def object_count(obj):
|
|
16
16
|
"""
|
17
17
|
Counts Length of object if it exists, Else returns None
|
18
18
|
"""
|
19
|
+
try:
|
20
|
+
cnt = len(obj)
|
21
|
+
# pylint: disable=bare-except
|
22
|
+
except:
|
23
|
+
cnt = 0
|
19
24
|
|
20
|
-
|
21
|
-
return len(obj)
|
22
|
-
|
23
|
-
return None
|
25
|
+
return cnt
|
24
26
|
|
25
27
|
def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
26
28
|
tracer, pricing_info, trace_content, metrics, disable_metrics):
|
@@ -87,24 +89,24 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
87
89
|
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
88
90
|
SemanticConvetion.DB_OPERATION_ADD)
|
89
91
|
span.set_attribute(SemanticConvetion.DB_ID_COUNT,
|
90
|
-
object_count(kwargs.get("ids")))
|
92
|
+
object_count(kwargs.get("ids", [])))
|
91
93
|
span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
|
92
|
-
object_count(kwargs.get("embeddings")))
|
94
|
+
object_count(kwargs.get("embeddings", [])))
|
93
95
|
span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
|
94
|
-
object_count(kwargs.get("metadatas")))
|
96
|
+
object_count(kwargs.get("metadatas", [])))
|
95
97
|
span.set_attribute(SemanticConvetion.DB_DOCUMENTS_COUNT,
|
96
|
-
object_count(kwargs.get("documents")))
|
98
|
+
object_count(kwargs.get("documents", [])))
|
97
99
|
|
98
100
|
elif gen_ai_endpoint == "chroma.get":
|
99
101
|
db_operation = SemanticConvetion.DB_OPERATION_GET
|
100
102
|
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
101
103
|
SemanticConvetion.DB_OPERATION_GET)
|
102
104
|
span.set_attribute(SemanticConvetion.DB_ID_COUNT,
|
103
|
-
object_count(kwargs.get("ids")))
|
105
|
+
object_count(kwargs.get("ids", [])))
|
104
106
|
span.set_attribute(SemanticConvetion.DB_QUERY_LIMIT,
|
105
|
-
kwargs.get("limit"))
|
107
|
+
kwargs.get("limit", ""))
|
106
108
|
span.set_attribute(SemanticConvetion.DB_OFFSET,
|
107
|
-
kwargs.get("offset"))
|
109
|
+
kwargs.get("offset", ""))
|
108
110
|
span.set_attribute(SemanticConvetion.DB_WHERE_DOCUMENT,
|
109
111
|
str(kwargs.get("where_document", "")))
|
110
112
|
|
@@ -113,7 +115,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
113
115
|
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
114
116
|
SemanticConvetion.DB_OPERATION_QUERY)
|
115
117
|
span.set_attribute(SemanticConvetion.DB_STATEMENT,
|
116
|
-
str(kwargs.get("query_texts")))
|
118
|
+
str(kwargs.get("query_texts", "")))
|
117
119
|
span.set_attribute(SemanticConvetion.DB_N_RESULTS,
|
118
120
|
kwargs.get("n_results", ""))
|
119
121
|
span.set_attribute(SemanticConvetion.DB_FILTER,
|
@@ -126,33 +128,33 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
126
128
|
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
127
129
|
SemanticConvetion.DB_OPERATION_UPDATE)
|
128
130
|
span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
|
129
|
-
object_count(kwargs.get("embeddings")))
|
131
|
+
object_count(kwargs.get("embeddings", [])))
|
130
132
|
span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
|
131
|
-
object_count(kwargs.get("metadatas")))
|
133
|
+
object_count(kwargs.get("metadatas", [])))
|
132
134
|
span.set_attribute(SemanticConvetion.DB_ID_COUNT,
|
133
|
-
object_count(kwargs.get("ids")))
|
135
|
+
object_count(kwargs.get("ids", [])))
|
134
136
|
span.set_attribute(SemanticConvetion.DB_DOCUMENTS_COUNT,
|
135
|
-
object_count(kwargs.get("documents")))
|
137
|
+
object_count(kwargs.get("documents", [])))
|
136
138
|
|
137
139
|
elif gen_ai_endpoint == "chroma.upsert":
|
138
140
|
db_operation = SemanticConvetion.DB_OPERATION_UPSERT
|
139
141
|
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
140
142
|
SemanticConvetion.DB_OPERATION_UPSERT)
|
141
143
|
span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
|
142
|
-
object_count(kwargs.get("embeddings")))
|
144
|
+
object_count(kwargs.get("embeddings", [])))
|
143
145
|
span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
|
144
|
-
object_count(kwargs.get("metadatas")))
|
146
|
+
object_count(kwargs.get("metadatas", [])))
|
145
147
|
span.set_attribute(SemanticConvetion.DB_ID_COUNT,
|
146
|
-
object_count(kwargs.get("ids")))
|
148
|
+
object_count(kwargs.get("ids", [])))
|
147
149
|
span.set_attribute(SemanticConvetion.DB_DOCUMENTS_COUNT,
|
148
|
-
object_count(kwargs.get("documents")))
|
150
|
+
object_count(kwargs.get("documents", [])))
|
149
151
|
|
150
152
|
elif gen_ai_endpoint == "chroma.delete":
|
151
153
|
db_operation = SemanticConvetion.DB_OPERATION_DELETE
|
152
154
|
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
153
155
|
SemanticConvetion.DB_OPERATION_DELETE)
|
154
156
|
span.set_attribute(SemanticConvetion.DB_ID_COUNT,
|
155
|
-
object_count(kwargs.get("ids")))
|
157
|
+
object_count(kwargs.get("ids", [])))
|
156
158
|
span.set_attribute(SemanticConvetion.DB_FILTER,
|
157
159
|
str(kwargs.get("where", "")))
|
158
160
|
span.set_attribute(SemanticConvetion.DB_DELETE_ALL,
|
@@ -203,9 +203,9 @@ def chat(gen_ai_endpoint, version, environment, application_name, tracer,
|
|
203
203
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
204
204
|
False)
|
205
205
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
|
206
|
-
response.
|
206
|
+
response.generation_id)
|
207
207
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
208
|
-
response.
|
208
|
+
response.finish_reason)
|
209
209
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
|
210
210
|
response.meta.billed_units.input_tokens)
|
211
211
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
|
@@ -306,10 +306,11 @@ def chat_stream(gen_ai_endpoint, version, environment, application_name,
|
|
306
306
|
# Collect message IDs and aggregated response from events
|
307
307
|
if event.event_type == "stream-end":
|
308
308
|
llmresponse = event.response.text
|
309
|
-
response_id = event.response.response_id
|
310
309
|
prompt_tokens = event.response.meta.billed_units.input_tokens
|
311
310
|
completion_tokens = event.response.meta.billed_units.output_tokens
|
312
311
|
finish_reason = event.finish_reason
|
312
|
+
if event.event_type == "stream-start":
|
313
|
+
response_id = event.generation_id
|
313
314
|
yield event
|
314
315
|
|
315
316
|
# Handling exception ensure observability without disrupting operation
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
|
2
|
+
"""Initializer of Auto Instrumentation of EmbedChain 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.embedchain.embedchain import evaluate, get_data_sources
|
9
|
+
|
10
|
+
_instruments = ("embedchain >= 0.1.104",)
|
11
|
+
|
12
|
+
WRAPPED_METHODS = [
|
13
|
+
{
|
14
|
+
"package": "embedchain",
|
15
|
+
"object": "App.evaluate",
|
16
|
+
"endpoint": "embedchain.evaluate",
|
17
|
+
"wrapper": evaluate,
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"package": "embedchain",
|
21
|
+
"object": "App.get_data_sources",
|
22
|
+
"endpoint": "embedchain.get_data_sources",
|
23
|
+
"wrapper": get_data_sources,
|
24
|
+
},
|
25
|
+
]
|
26
|
+
|
27
|
+
class EmbedChainInstrumentor(BaseInstrumentor):
|
28
|
+
"""An instrumentor for EmbedChain's client library."""
|
29
|
+
|
30
|
+
def instrumentation_dependencies(self) -> Collection[str]:
|
31
|
+
return _instruments
|
32
|
+
|
33
|
+
def _instrument(self, **kwargs):
|
34
|
+
application_name = kwargs.get("application_name")
|
35
|
+
environment = kwargs.get("environment")
|
36
|
+
tracer = kwargs.get("tracer")
|
37
|
+
pricing_info = kwargs.get("pricing_info")
|
38
|
+
trace_content = kwargs.get("trace_content")
|
39
|
+
version = importlib.metadata.version("embedchain")
|
40
|
+
|
41
|
+
for wrapped_method in WRAPPED_METHODS:
|
42
|
+
wrap_package = wrapped_method.get("package")
|
43
|
+
wrap_object = wrapped_method.get("object")
|
44
|
+
gen_ai_endpoint = wrapped_method.get("endpoint")
|
45
|
+
wrapper = wrapped_method.get("wrapper")
|
46
|
+
wrap_function_wrapper(
|
47
|
+
wrap_package,
|
48
|
+
wrap_object,
|
49
|
+
wrapper(gen_ai_endpoint, version, environment, application_name,
|
50
|
+
tracer, pricing_info, trace_content),
|
51
|
+
)
|
52
|
+
|
53
|
+
@staticmethod
|
54
|
+
def _uninstrument(self, **kwargs):
|
55
|
+
pass
|
@@ -0,0 +1,165 @@
|
|
1
|
+
# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument
|
2
|
+
"""
|
3
|
+
Module for monitoring EmbedChain 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 evaluate(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 EmbedChain application.
|
26
|
+
- environment (str): The deployment environment (e.g., 'production', 'development').
|
27
|
+
- application_name (str): Name of the EmbedChain 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_EMBEDCHAIN)
|
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
|
+
span.set_attribute(SemanticConvetion.GEN_AI_EVAL_CONTEXT_RELEVANCY,
|
73
|
+
response["context_relevancy"])
|
74
|
+
span.set_attribute(SemanticConvetion.GEN_AI_EVAL_ANSWER_RELEVANCY,
|
75
|
+
response["answer_relevancy"])
|
76
|
+
span.set_attribute(SemanticConvetion.GEN_AI_EVAL_GROUNDEDNESS,
|
77
|
+
response["groundedness"])
|
78
|
+
|
79
|
+
span.set_status(Status(StatusCode.OK))
|
80
|
+
|
81
|
+
# Return original response
|
82
|
+
return response
|
83
|
+
|
84
|
+
except Exception as e:
|
85
|
+
handle_exception(span, e)
|
86
|
+
logger.error("Error in trace creation: %s", e)
|
87
|
+
|
88
|
+
# Return original response
|
89
|
+
return response
|
90
|
+
|
91
|
+
return wrapper
|
92
|
+
|
93
|
+
def get_data_sources(gen_ai_endpoint, version, environment, application_name,
|
94
|
+
tracer, pricing_info, trace_content):
|
95
|
+
"""
|
96
|
+
Creates a wrapper around a function call to trace and log its execution metrics.
|
97
|
+
|
98
|
+
This function wraps any given function to measure its execution time,
|
99
|
+
log its operation, and trace its execution using OpenTelemetry.
|
100
|
+
|
101
|
+
Parameters:
|
102
|
+
- gen_ai_endpoint (str): A descriptor or name for the endpoint being traced.
|
103
|
+
- version (str): The version of the EmbedChain application.
|
104
|
+
- environment (str): The deployment environment (e.g., 'production', 'development').
|
105
|
+
- application_name (str): Name of the EmbedChain application.
|
106
|
+
- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.
|
107
|
+
- pricing_info (dict): Information about the pricing for internal metrics (currently not used).
|
108
|
+
- trace_content (bool): Flag indicating whether to trace the content of the response.
|
109
|
+
|
110
|
+
Returns:
|
111
|
+
- function: A higher-order function that takes a function 'wrapped' and returns
|
112
|
+
a new function that wraps 'wrapped' with additional tracing and logging.
|
113
|
+
"""
|
114
|
+
|
115
|
+
def wrapper(wrapped, instance, args, kwargs):
|
116
|
+
"""
|
117
|
+
An inner wrapper function that executes the wrapped function, measures execution
|
118
|
+
time, and records trace data using OpenTelemetry.
|
119
|
+
|
120
|
+
Parameters:
|
121
|
+
- wrapped (Callable): The original function that this wrapper will execute.
|
122
|
+
- instance (object): The instance to which the wrapped function belongs. This
|
123
|
+
is used for instance methods. For static and classmethods,
|
124
|
+
this may be None.
|
125
|
+
- args (tuple): Positional arguments passed to the wrapped function.
|
126
|
+
- kwargs (dict): Keyword arguments passed to the wrapped function.
|
127
|
+
|
128
|
+
Returns:
|
129
|
+
- The result of the wrapped function call.
|
130
|
+
|
131
|
+
The wrapper initiates a span with the provided tracer, sets various attributes
|
132
|
+
on the span based on the function's execution and response, and ensures
|
133
|
+
errors are handled and logged appropriately.
|
134
|
+
"""
|
135
|
+
with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
|
136
|
+
response = wrapped(*args, **kwargs)
|
137
|
+
|
138
|
+
try:
|
139
|
+
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
140
|
+
span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
|
141
|
+
SemanticConvetion.GEN_AI_SYSTEM_EMBEDCHAIN)
|
142
|
+
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
|
143
|
+
gen_ai_endpoint)
|
144
|
+
span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
|
145
|
+
environment)
|
146
|
+
span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
|
147
|
+
SemanticConvetion.GEN_AI_TYPE_FRAMEWORK)
|
148
|
+
span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
|
149
|
+
application_name)
|
150
|
+
span.set_attribute(SemanticConvetion.GEN_AI_DATA_SOURCES,
|
151
|
+
len(response))
|
152
|
+
|
153
|
+
span.set_status(Status(StatusCode.OK))
|
154
|
+
|
155
|
+
# Return original response
|
156
|
+
return response
|
157
|
+
|
158
|
+
except Exception as e:
|
159
|
+
handle_exception(span, e)
|
160
|
+
logger.error("Error in trace creation: %s", e)
|
161
|
+
|
162
|
+
# Return original response
|
163
|
+
return response
|
164
|
+
|
165
|
+
return wrapper
|
@@ -25,7 +25,7 @@ WRAPPED_METHODS = [
|
|
25
25
|
]
|
26
26
|
|
27
27
|
class LlamaIndexInstrumentor(BaseInstrumentor):
|
28
|
-
"""An instrumentor for
|
28
|
+
"""An instrumentor for LlamaIndex's client library."""
|
29
29
|
|
30
30
|
def instrumentation_dependencies(self) -> Collection[str]:
|
31
31
|
return _instruments
|
@@ -119,9 +119,9 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
119
119
|
span.set_attribute(SemanticConvetion.DB_OPERATION_STATUS,
|
120
120
|
response.status)
|
121
121
|
span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
|
122
|
-
object_count(kwargs.get("points")))
|
122
|
+
object_count(kwargs.get("points", [])))
|
123
123
|
span.set_attribute(SemanticConvetion.DB_PAYLOAD_COUNT,
|
124
|
-
object_count(kwargs.get("payload")))
|
124
|
+
object_count(kwargs.get("payload", [])))
|
125
125
|
|
126
126
|
elif gen_ai_endpoint == "qdrant.retrieve":
|
127
127
|
db_operation = SemanticConvetion.DB_OPERATION_QUERY
|
@@ -130,7 +130,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
130
130
|
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
131
131
|
kwargs.get("collection_name", ""))
|
132
132
|
span.set_attribute(SemanticConvetion.DB_STATEMENT,
|
133
|
-
str(kwargs.get("ids")))
|
133
|
+
str(kwargs.get("ids", "")))
|
134
134
|
|
135
135
|
elif gen_ai_endpoint == "qdrant.scroll":
|
136
136
|
db_operation = SemanticConvetion.DB_OPERATION_QUERY
|
@@ -139,7 +139,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
139
139
|
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
140
140
|
kwargs.get("collection_name", ""))
|
141
141
|
span.set_attribute(SemanticConvetion.DB_STATEMENT,
|
142
|
-
str(kwargs.get("scroll_filter")))
|
142
|
+
str(kwargs.get("scroll_filter", "")))
|
143
143
|
|
144
144
|
elif gen_ai_endpoint in ["qdrant.search", "qdrant.search_groups"]:
|
145
145
|
db_operation = SemanticConvetion.DB_OPERATION_QUERY
|
@@ -148,7 +148,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
148
148
|
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
149
149
|
kwargs.get("collection_name", ""))
|
150
150
|
span.set_attribute(SemanticConvetion.DB_STATEMENT,
|
151
|
-
str(kwargs.get("query_vector")))
|
151
|
+
str(kwargs.get("query_vector", "")))
|
152
152
|
|
153
153
|
elif gen_ai_endpoint == "qdrant.recommend":
|
154
154
|
db_operation = SemanticConvetion.DB_OPERATION_QUERY
|
openlit/semcov/__init__.py
CHANGED
@@ -26,6 +26,7 @@ class SemanticConvetion:
|
|
26
26
|
GEN_AI_HUB_REPO = "gen_ai.hub.repo"
|
27
27
|
GEN_AI_RETRIEVAL_SOURCE = "gen_ai.retrieval.source"
|
28
28
|
GEN_AI_REQUESTS = "gen_ai.total.requests"
|
29
|
+
GEN_AI_DATA_SOURCES = "gen_ai.data_source_count"
|
29
30
|
|
30
31
|
# GenAI Request
|
31
32
|
GEN_AI_REQUEST_MODEL = "gen_ai.request.model"
|
@@ -71,6 +72,11 @@ class SemanticConvetion:
|
|
71
72
|
GEN_AI_CONTENT_COMPLETION = "gen_ai.content.completion"
|
72
73
|
GEN_AI_CONTENT_REVISED_PROMPT = "gen_ai.content.revised_prompt"
|
73
74
|
|
75
|
+
# GenAI Evaluation Metrics
|
76
|
+
GEN_AI_EVAL_CONTEXT_RELEVANCY = "gen_ai.eval.context_relevancy"
|
77
|
+
GEN_AI_EVAL_ANSWER_RELEVANCY = "gen_ai.eval.answer_relevancy"
|
78
|
+
GEN_AI_EVAL_GROUNDEDNESS = "gen_ai.eval.groundedness"
|
79
|
+
|
74
80
|
GEN_AI_TYPE_CHAT = "chat"
|
75
81
|
GEN_AI_TYPE_EMBEDDING = "embedding"
|
76
82
|
GEN_AI_TYPE_IMAGE = "image"
|
@@ -92,6 +98,7 @@ class SemanticConvetion:
|
|
92
98
|
GEN_AI_SYSTEM_LANGCHAIN = "langchain"
|
93
99
|
GEN_AI_SYSTEM_LLAMAINDEX = "llama_index"
|
94
100
|
GEN_AI_SYSTEM_HAYSTACK = "haystack"
|
101
|
+
GEN_AI_SYSTEM_EMBEDCHAIN = "embedchain"
|
95
102
|
|
96
103
|
# Vector DB
|
97
104
|
DB_REQUESTS = "db.total.requests"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: openlit
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.10.0
|
4
4
|
Summary: OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications, 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
|
@@ -38,6 +38,9 @@ OpenTelemetry Auto-Instrumentation for GenAI & LLM Applications</h1>
|
|
38
38
|
[](https://join.slack.com/t/openlit/shared_invite/zt-2etnfttwg-TjP_7BZXfYg84oAukY8QRQ)
|
39
39
|
[](https://twitter.com/openlit_io)
|
40
40
|
|
41
|
+

|
42
|
+
|
43
|
+
|
41
44
|
</div>
|
42
45
|
|
43
46
|
OpenLIT Python SDK is an **OpenTelemetry-native** Auto instrumentation library for monitoring LLM Applications, facilitating the integration of observability into your GenAI-driven projects. Designed with simplicity and efficiency, OpenLIT offers the ability to embed observability into your GenAI-driven projects effortlessly using just **a single line of code**.
|
@@ -46,31 +49,20 @@ Whether you're directly using LLM Libraries like OpenAI, Anthropic or building c
|
|
46
49
|
|
47
50
|
This project adheres to the [Semantic Conventions](https://github.com/open-telemetry/semantic-conventions/tree/main/docs/gen-ai) proposed by the OpenTelemetry community. You can check out the current definitions [here](src/openlit/semcov/__init__.py).
|
48
51
|
|
49
|
-
##
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
### Vector DBs
|
64
|
-
- [✅ ChromaDB](https://docs.openlit.io/latest/integrations/chromadb)
|
65
|
-
- [✅ Pinecone](https://docs.openlit.io/latest/integrations/pinecone)
|
66
|
-
- [✅ Qdrant](https://docs.openlit.io/latest/integrations/qdrant)
|
67
|
-
- [✅ Milvus](https://docs.openlit.io/latest/integrations/milvus)
|
68
|
-
|
69
|
-
### Frameworks
|
70
|
-
- [✅ Langchain](https://docs.openlit.io/latest/integrations/langchain)
|
71
|
-
- [✅ LiteLLM](https://docs.openlit.io/latest/integrations/litellm)
|
72
|
-
- [✅ LlamaIndex](https://docs.openlit.io/latest/integrations/llama-index)
|
73
|
-
- [✅ Haystack](https://docs.openlit.io/latest/integrations/haystack)
|
52
|
+
## Auto Instrumentation Capabilities
|
53
|
+
|
54
|
+
| LLMs | Vector DBs | Frameworks |
|
55
|
+
|----------------------------------------------------------|----------------------------------------------|----------------------------------------------|
|
56
|
+
| [✅ OpenAI](https://docs.openlit.io/latest/integrations/openai) | [✅ ChromaDB](https://docs.openlit.io/latest/integrations/chromadb) | [✅ Langchain](https://docs.openlit.io/latest/integrations/langchain) |
|
57
|
+
| [✅ Ollama](https://docs.openlit.io/latest/integrations/ollama) | [✅ Pinecone](https://docs.openlit.io/latest/integrations/pinecone) | [✅ LiteLLM](https://docs.openlit.io/latest/integrations/litellm) |
|
58
|
+
| [✅ 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) |
|
59
|
+
| [✅ Cohere](https://docs.openlit.io/latest/integrations/cohere) | [✅ Milvus](https://docs.openlit.io/latest/integrations/milvus) | [✅ Haystack](https://docs.openlit.io/latest/integrations/haystack) |
|
60
|
+
| [✅ Mistral](https://docs.openlit.io/latest/integrations/mistral) | |
|
61
|
+
| [✅ Azure OpenAI](https://docs.openlit.io/latest/integrations/azure-openai) | |
|
62
|
+
| [✅ HuggingFace Transformers](https://docs.openlit.io/latest/integrations/huggingface) | |
|
63
|
+
| [✅ Amazon Bedrock](https://docs.openlit.io/latest/integrations/bedrock) | |
|
64
|
+
| [✅ Vertex AI](https://docs.openlit.io/latest/integrations/vertexai) | |
|
65
|
+
| [✅ Groq](https://docs.openlit.io/latest/integrations/groq) | |
|
74
66
|
|
75
67
|
## Supported Destinations
|
76
68
|
- [✅ OpenTelemetry Collector](https://docs.openlit.io/latest/connections/otelcol)
|
@@ -92,14 +84,16 @@ pip install openlit
|
|
92
84
|
|
93
85
|
## 🚀 Getting Started
|
94
86
|
|
95
|
-
|
87
|
+
### Step 1: Install OpenLIT
|
88
|
+
|
89
|
+
Open your command line or terminal and run:
|
96
90
|
|
97
91
|
```bash
|
98
92
|
pip install openlit
|
99
93
|
```
|
100
94
|
|
101
|
-
### Step 2:
|
102
|
-
Integrating the OpenLIT into LLM applications is straightforward. Start monitoring for your LLM Application with just **
|
95
|
+
### Step 2: Initialize OpenLIT in your Application
|
96
|
+
Integrating the OpenLIT into LLM applications is straightforward. Start monitoring for your LLM Application with just **two lines of code**:
|
103
97
|
|
104
98
|
```python
|
105
99
|
import openlit
|
@@ -107,46 +101,68 @@ import openlit
|
|
107
101
|
openlit.init()
|
108
102
|
```
|
109
103
|
|
110
|
-
|
104
|
+
To forward telemetry data to an HTTP OTLP endpoint, such as the OpenTelemetry Collector, set the `otlp_endpoint` parameter with the desired endpoint. Alternatively, you can configure the endpoint by setting the `OTEL_EXPORTER_OTLP_ENDPOINT` environment variable as recommended in the OpenTelemetry documentation.
|
105
|
+
|
106
|
+
> 💡 Info: If you dont provide `otlp_endpoint` function argument or set the `OTEL_EXPORTER_OTLP_ENDPOINT` environment variable, OpenLIT directs the trace directly to your console, which can be useful during development.
|
111
107
|
|
112
108
|
To send telemetry to OpenTelemetry backends requiring authentication, set the `otlp_headers` parameter with its desired value. Alternatively, you can configure the endpoint by setting the `OTEL_EXPORTER_OTLP_HEADERS` environment variable as recommended in the OpenTelemetry documentation.
|
113
109
|
|
114
110
|
#### Example
|
115
111
|
|
116
|
-
|
112
|
+
---
|
117
113
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
)
|
123
|
-
```
|
114
|
+
<details>
|
115
|
+
<summary>Initialize using Function Arguments</summary>
|
116
|
+
|
117
|
+
---
|
124
118
|
|
125
|
-
|
119
|
+
Add the following two lines to your application code:
|
120
|
+
|
121
|
+
```python
|
122
|
+
import openlit
|
123
|
+
|
124
|
+
openlit.init(
|
125
|
+
otlp_endpoint="YOUR_OTEL_ENDPOINT",
|
126
|
+
otlp_headers ="YOUR_OTEL_ENDPOINT_AUTH"
|
127
|
+
)
|
128
|
+
```
|
126
129
|
|
127
|
-
|
128
|
-
openlit.init()
|
129
|
-
```
|
130
|
+
</details>
|
130
131
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
132
|
+
---
|
133
|
+
|
134
|
+
<details>
|
135
|
+
|
136
|
+
<summary>Initialize using Environment Variables</summary>
|
137
|
+
|
138
|
+
---
|
139
|
+
|
140
|
+
Add the following two lines to your application code:
|
141
|
+
|
142
|
+
```python
|
143
|
+
import openlit
|
144
|
+
|
145
|
+
openlit.init()
|
146
|
+
```
|
147
|
+
|
148
|
+
Then, configure the your OTLP endpoint using environment variable:
|
149
|
+
|
150
|
+
```env
|
151
|
+
export OTEL_EXPORTER_OTLP_ENDPOINT = "YOUR_OTEL_ENDPOINT"
|
152
|
+
export OTEL_EXPORTER_OTLP_HEADERS = "YOUR_OTEL_ENDPOINT_AUTH"
|
153
|
+
```
|
154
|
+
</details>
|
155
|
+
|
156
|
+
---
|
135
157
|
|
136
158
|
### Step 3: Visualize and Optimize!
|
137
|
-
With the LLM Observability data now being collected and sent to
|
159
|
+
With the LLM Observability data now being collected and sent to OpenLIT, the next step is to visualize and analyze this data to get insights into your LLM application’s performance, behavior, and identify areas of improvement.
|
138
160
|
|
139
|
-
|
140
|
-
- At the top, ensure the correct Tempo data source is selected from the dropdown menu.
|
141
|
-
- Use the **Query** field to specify any particular traces you are interested in, or leave it empty to browse through all the available traces.
|
142
|
-
- You can adjust the time range to focus on specific periods of interest.
|
143
|
-
- Hit **Run Query** to fetch your trace data. You'll see a visual representation of your traces along with detailed information on particular spans when clicked.
|
161
|
+
To begin exploring your LLM Application's performance data within the OpenLIT UI, please see the [Quickstart Guide](https://docs.openlit.io/latest/quickstart).
|
144
162
|
|
145
|
-
|
163
|
+
If you want to integrate and send metrics and traces to your existing observability tools, refer to our [Connections Guide](https://docs.openlit.io/latest/connections/intro) for detailed instructions.
|
146
164
|
|
147
|
-
|
148
|
-
- **Set Alerts:** Grafana also allows you to set up alerts based on specific thresholds. This feature can be invaluable in proactively managing your application's health by notifying you of potential issues before they impact users.
|
149
|
-
- **Iterate and Optimize:** Use the insights gained from your observability data to make informed decisions on optimizing your LLM application. This might involve refining model parameters, adjusting scaling strategies, or identifying and resolving bottlenecks.
|
165
|
+

|
150
166
|
|
151
167
|
|
152
168
|
### Configuration
|
@@ -163,7 +179,7 @@ Below is a detailed overview of the configuration options available, allowing yo
|
|
163
179
|
| `otlp_headers` | Defines headers for the OTLP exporter, useful for backends requiring authentication. | `None` | No |
|
164
180
|
| `disable_batch` | A flag to disable batch span processing, favoring immediate dispatch. | `False` | No |
|
165
181
|
| `trace_content` | Enables tracing of content for deeper insights. | `True` | No |
|
166
|
-
| `disabled_instrumentors`| List of instrumentors to disable.
|
182
|
+
| `disabled_instrumentors`| List of instrumentors to disable. | `None` | No |
|
167
183
|
| `disable_metrics` | If set, disables the collection of metrics. | `False` | No |
|
168
184
|
| `pricing_json` | URL or file path of the pricing JSON file. | `https://github.com/openlit/openlit/blob/main/assets/pricing.json` | No |
|
169
185
|
|
@@ -1,14 +1,16 @@
|
|
1
1
|
openlit/__helpers.py,sha256=lrn4PBs9owDudiCY2NBoVbAi7AU_HtUpyOj0oqPBsPY,5545
|
2
|
-
openlit/__init__.py,sha256=
|
2
|
+
openlit/__init__.py,sha256=rKjXPouODce9nDeysIwf5k8YWA27Fpnr8J6PDCg4k4Q,10299
|
3
3
|
openlit/instrumentation/anthropic/__init__.py,sha256=oaU53BOPyfUKbEzYvLr1DPymDluurSnwo4Hernf2XdU,1955
|
4
4
|
openlit/instrumentation/anthropic/anthropic.py,sha256=CYBui5eEfWdSfFF0xtCQjh1xO-gCVJc_V9Hli0szVZE,16026
|
5
5
|
openlit/instrumentation/anthropic/async_anthropic.py,sha256=NW84kTQ3BkUx1zZuMRps_J7zTYkmq5BxOrqSjqWInBs,16068
|
6
6
|
openlit/instrumentation/bedrock/__init__.py,sha256=QPvDMQde6Meodu5JvosHdZsnyExS19lcoP5Li4YrOkw,1540
|
7
7
|
openlit/instrumentation/bedrock/bedrock.py,sha256=Q5t5283LGEvhyrUCr9ofEQF22JTkc1UvT2_6u7e7gmA,22278
|
8
8
|
openlit/instrumentation/chroma/__init__.py,sha256=61lFpHlUEQUobsUJZHXdvOViKwsOH8AOvSfc4VgCmiM,3253
|
9
|
-
openlit/instrumentation/chroma/chroma.py,sha256=
|
9
|
+
openlit/instrumentation/chroma/chroma.py,sha256=E80j_41UeZi8RzTsHbpvi1izOA_n-0-3_VdrA68AJPA,10531
|
10
10
|
openlit/instrumentation/cohere/__init__.py,sha256=PC5T1qIg9pwLNocBP_WjG5B_6p_z019s8quk_fNLAMs,1920
|
11
|
-
openlit/instrumentation/cohere/cohere.py,sha256=
|
11
|
+
openlit/instrumentation/cohere/cohere.py,sha256=GvxIp55TJIu4YyG0_FwLBDHvAMUlAXyvMNIFhl2CQP4,20437
|
12
|
+
openlit/instrumentation/embedchain/__init__.py,sha256=8TYk1OEbz46yF19dr-gB_x80VZMagU3kJ8-QihPXTeA,1929
|
13
|
+
openlit/instrumentation/embedchain/embedchain.py,sha256=SLlr7qieT3kp4M6OYSRy8FaVCXQ2t3oPyIiE99ioNE4,7892
|
12
14
|
openlit/instrumentation/groq/__init__.py,sha256=uW_0G6HSanQyK2dIXYhzR604pDiyPQfybzc37DsfSew,1911
|
13
15
|
openlit/instrumentation/groq/async_groq.py,sha256=WQwHpC-NJoyEf-jAJlxEcdnpd5jmlfAsDtEBRJ47CxA,19084
|
14
16
|
openlit/instrumentation/groq/groq.py,sha256=4uiEFUjxJ0q-c3GlgPAMc4NijG1YLgQp7o3wcwFrxeg,19048
|
@@ -16,7 +18,7 @@ openlit/instrumentation/haystack/__init__.py,sha256=QK6XxxZUHX8vMv2Crk7rNBOc64iO
|
|
16
18
|
openlit/instrumentation/haystack/haystack.py,sha256=oQIZiDhdp3gnJnhYQ1OouJMc9YT0pQ-_31cmNuopa68,3891
|
17
19
|
openlit/instrumentation/langchain/__init__.py,sha256=TW1ZR7I1i9Oig-wDWp3j1gmtQFO76jNBXQRBGGKzoOo,2531
|
18
20
|
openlit/instrumentation/langchain/langchain.py,sha256=G66UytYwWW0DdvChomzkc5_MJ-sjupuDwlxe4KqlGhY,7639
|
19
|
-
openlit/instrumentation/llamaindex/__init__.py,sha256=
|
21
|
+
openlit/instrumentation/llamaindex/__init__.py,sha256=vPtK65G6b-TwJERowVRUVl7f_nBSlFdwPBtpg8dOGos,1977
|
20
22
|
openlit/instrumentation/llamaindex/llamaindex.py,sha256=uiIigbwhonSbJWA7LpgOVI1R4kxxPODS1K5wyHIQ4hM,4048
|
21
23
|
openlit/instrumentation/milvus/__init__.py,sha256=qi1yfmMrvkDtnrN_6toW8qC9BRL78bq7ayWpObJ8Bq4,2961
|
22
24
|
openlit/instrumentation/milvus/milvus.py,sha256=qhKIoggBAJhRctRrBYz69AcvXH-eh7oBn_l9WfxpAjI,9121
|
@@ -34,7 +36,7 @@ openlit/instrumentation/openai/openai.py,sha256=VVl0fuQfxitH-V4hVeP5VxB31-yWMI74
|
|
34
36
|
openlit/instrumentation/pinecone/__init__.py,sha256=Mv9bElqNs07_JQkYyNnO0wOM3hdbprmw7sttdMeKC7g,2526
|
35
37
|
openlit/instrumentation/pinecone/pinecone.py,sha256=0EhLmtOuvwWVvAKh3e56wyd8wzQq1oaLOmF15SVHxVE,8765
|
36
38
|
openlit/instrumentation/qdrant/__init__.py,sha256=OJIg17-IGmBEvBYVKjCHcJ0hFXuEL7XV_jzUTqkolN8,4799
|
37
|
-
openlit/instrumentation/qdrant/qdrant.py,sha256=
|
39
|
+
openlit/instrumentation/qdrant/qdrant.py,sha256=4uHKYGvWQtRAEVLUWo3o4joJw7hFm2NxVuBu5YKZKiI,14456
|
38
40
|
openlit/instrumentation/transformers/__init__.py,sha256=9-KLjq-aPTh13gTBYsWltV6hokGwt3mP4759SwsaaCk,1478
|
39
41
|
openlit/instrumentation/transformers/transformers.py,sha256=peT0BGskYt7AZ0b93TZ7qECXfZRgDQMasUeamexYdZI,7592
|
40
42
|
openlit/instrumentation/vertexai/__init__.py,sha256=N3E9HtzefD-zC0fvmfGYiDmSqssoavp_i59wfuYLyMw,6079
|
@@ -42,8 +44,8 @@ openlit/instrumentation/vertexai/async_vertexai.py,sha256=PMHYyLf1J4gZpC_-KZ_ZVx
|
|
42
44
|
openlit/instrumentation/vertexai/vertexai.py,sha256=UvpNKBHPoV9idVMfGigZnmWuEQiyqSwZn0zK9-U7Lzw,52125
|
43
45
|
openlit/otel/metrics.py,sha256=O7NoaDz0bY19mqpE4-0PcKwEe-B-iJFRgOCaanAuZAc,4291
|
44
46
|
openlit/otel/tracing.py,sha256=vL1ifMbARPBpqK--yXYsCM6y5dSu5LFIKqkhZXtYmUc,3712
|
45
|
-
openlit/semcov/__init__.py,sha256=
|
46
|
-
openlit-1.
|
47
|
-
openlit-1.
|
48
|
-
openlit-1.
|
49
|
-
openlit-1.
|
47
|
+
openlit/semcov/__init__.py,sha256=sjbSzGH2p25cLrdm3OZxHxxv2gF2eh9Ij1hPamQtMdM,6649
|
48
|
+
openlit-1.10.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
49
|
+
openlit-1.10.0.dist-info/METADATA,sha256=0oJJupg32D01gTLE2_YTna8zgf4TOF5hxpHJC2d3_Wk,12841
|
50
|
+
openlit-1.10.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
51
|
+
openlit-1.10.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|