openlit 1.9.0__tar.gz → 1.10.0__tar.gz
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-1.9.0 → openlit-1.10.0}/PKG-INFO +1 -1
- {openlit-1.9.0 → openlit-1.10.0}/pyproject.toml +1 -1
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/__init__.py +3 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/chroma/chroma.py +23 -21
- openlit-1.10.0/src/openlit/instrumentation/embedchain/__init__.py +55 -0
- openlit-1.10.0/src/openlit/instrumentation/embedchain/embedchain.py +165 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/llamaindex/__init__.py +1 -1
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/qdrant/qdrant.py +5 -5
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/semcov/__init__.py +7 -0
- {openlit-1.9.0 → openlit-1.10.0}/LICENSE +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/README.md +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/__helpers.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/anthropic/__init__.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/anthropic/anthropic.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/anthropic/async_anthropic.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/bedrock/__init__.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/bedrock/bedrock.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/chroma/__init__.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/cohere/__init__.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/cohere/cohere.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/groq/__init__.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/groq/async_groq.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/groq/groq.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/haystack/__init__.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/haystack/haystack.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/langchain/__init__.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/langchain/langchain.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/llamaindex/llamaindex.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/milvus/__init__.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/milvus/milvus.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/mistral/__init__.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/mistral/async_mistral.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/mistral/mistral.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/ollama/__init__.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/ollama/async_ollama.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/ollama/ollama.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/openai/__init__.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/openai/async_azure_openai.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/openai/async_openai.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/openai/azure_openai.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/openai/openai.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/pinecone/__init__.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/pinecone/pinecone.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/qdrant/__init__.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/transformers/__init__.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/transformers/transformers.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/vertexai/__init__.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/vertexai/async_vertexai.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/instrumentation/vertexai/vertexai.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/otel/metrics.py +0 -0
- {openlit-1.9.0 → openlit-1.10.0}/src/openlit/otel/tracing.py +0 -0
@@ -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
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[tool.poetry]
|
2
2
|
name = "openlit"
|
3
|
-
version = "1.
|
3
|
+
version = "1.10.0"
|
4
4
|
description = "OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications, facilitating the integration of observability into your GenAI-driven projects"
|
5
5
|
authors = ["OpenLIT"]
|
6
6
|
repository = "https://github.com/openlit/openlit/tree/main/openlit/python"
|
@@ -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,
|
@@ -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
|
@@ -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"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|