openlit 1.1.3__py3-none-any.whl → 1.5.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 +15 -1
- openlit/instrumentation/anthropic/anthropic.py +1 -1
- openlit/instrumentation/anthropic/async_anthropic.py +1 -1
- openlit/instrumentation/chroma/chroma.py +2 -2
- openlit/instrumentation/cohere/cohere.py +1 -1
- openlit/instrumentation/groq/__init__.py +50 -0
- openlit/instrumentation/groq/async_groq.py +331 -0
- openlit/instrumentation/groq/groq.py +331 -0
- openlit/instrumentation/haystack/__init__.py +49 -0
- openlit/instrumentation/haystack/haystack.py +84 -0
- openlit/instrumentation/langchain/langchain.py +1 -1
- openlit/instrumentation/llamaindex/__init__.py +55 -0
- openlit/instrumentation/llamaindex/llamaindex.py +86 -0
- openlit/instrumentation/mistral/async_mistral.py +1 -1
- openlit/instrumentation/mistral/mistral.py +1 -1
- openlit/instrumentation/pinecone/pinecone.py +1 -1
- openlit/instrumentation/qdrant/__init__.py +155 -0
- openlit/instrumentation/qdrant/qdrant.py +258 -0
- openlit/instrumentation/vertexai/__init__.py +147 -0
- openlit/instrumentation/vertexai/async_vertexai.py +1047 -0
- openlit/instrumentation/vertexai/vertexai.py +1047 -0
- openlit/otel/tracing.py +3 -0
- openlit/semcov/__init__.py +14 -3
- {openlit-1.1.3.dist-info → openlit-1.5.0.dist-info}/METADATA +27 -19
- openlit-1.5.0.dist-info/RECORD +44 -0
- openlit-1.1.3.dist-info/RECORD +0 -32
- {openlit-1.1.3.dist-info → openlit-1.5.0.dist-info}/LICENSE +0 -0
- {openlit-1.1.3.dist-info → openlit-1.5.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,155 @@
|
|
1
|
+
# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
|
2
|
+
"""Initializer of Auto Instrumentation of Qdrant 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.qdrant.qdrant import general_wrap
|
9
|
+
|
10
|
+
_instruments = ("qdrant-client >= 1.9.0",)
|
11
|
+
|
12
|
+
WRAPPED_METHODS = [
|
13
|
+
{
|
14
|
+
"package": "qdrant_client",
|
15
|
+
"object": "QdrantClient.create_collection",
|
16
|
+
"endpoint": "qdrant.create_collection",
|
17
|
+
"wrapper": general_wrap,
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"package": "qdrant_client",
|
21
|
+
"object": "QdrantClient.delete_collection",
|
22
|
+
"endpoint": "qdrant.delete_collection",
|
23
|
+
"wrapper": general_wrap,
|
24
|
+
},
|
25
|
+
{
|
26
|
+
"package": "qdrant_client",
|
27
|
+
"object": "QdrantClient.update_collection",
|
28
|
+
"endpoint": "qdrant.update_collection",
|
29
|
+
"wrapper": general_wrap,
|
30
|
+
},
|
31
|
+
{
|
32
|
+
"package": "qdrant_client",
|
33
|
+
"object": "QdrantClient.upload_collection",
|
34
|
+
"endpoint": "qdrant.upload_collection",
|
35
|
+
"wrapper": general_wrap,
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"package": "qdrant_client",
|
39
|
+
"object": "QdrantClient.upsert",
|
40
|
+
"endpoint": "qdrant.upsert",
|
41
|
+
"wrapper": general_wrap,
|
42
|
+
},
|
43
|
+
{
|
44
|
+
"package": "qdrant_client",
|
45
|
+
"object": "QdrantClient.set_payload",
|
46
|
+
"endpoint": "qdrant.set_payload",
|
47
|
+
"wrapper": general_wrap,
|
48
|
+
},
|
49
|
+
{
|
50
|
+
"package": "qdrant_client",
|
51
|
+
"object": "QdrantClient.overwrite_payload",
|
52
|
+
"endpoint": "qdrant.overwrite_payload",
|
53
|
+
"wrapper": general_wrap,
|
54
|
+
},
|
55
|
+
{
|
56
|
+
"package": "qdrant_client",
|
57
|
+
"object": "QdrantClient.clear_payload",
|
58
|
+
"endpoint": "qdrant.clear_payload",
|
59
|
+
"wrapper": general_wrap,
|
60
|
+
},
|
61
|
+
{
|
62
|
+
"package": "qdrant_client",
|
63
|
+
"object": "QdrantClient.delete_payload",
|
64
|
+
"endpoint": "qdrant.delete_payload",
|
65
|
+
"wrapper": general_wrap,
|
66
|
+
},
|
67
|
+
{
|
68
|
+
"package": "qdrant_client",
|
69
|
+
"object": "QdrantClient.upload_points",
|
70
|
+
"endpoint": "qdrant.upload_points",
|
71
|
+
"wrapper": general_wrap,
|
72
|
+
},
|
73
|
+
{
|
74
|
+
"package": "qdrant_client",
|
75
|
+
"object": "QdrantClient.update_vectors",
|
76
|
+
"endpoint": "qdrant.update_vectors",
|
77
|
+
"wrapper": general_wrap,
|
78
|
+
},
|
79
|
+
{
|
80
|
+
"package": "qdrant_client",
|
81
|
+
"object": "QdrantClient.delete_vectors",
|
82
|
+
"endpoint": "qdrant.delete_vectors",
|
83
|
+
"wrapper": general_wrap,
|
84
|
+
},
|
85
|
+
{
|
86
|
+
"package": "qdrant_client",
|
87
|
+
"object": "QdrantClient.delete",
|
88
|
+
"endpoint": "qdrant.delete",
|
89
|
+
"wrapper": general_wrap,
|
90
|
+
},
|
91
|
+
{
|
92
|
+
"package": "qdrant_client",
|
93
|
+
"object": "QdrantClient.retrieve",
|
94
|
+
"endpoint": "qdrant.retrieve",
|
95
|
+
"wrapper": general_wrap,
|
96
|
+
},
|
97
|
+
{
|
98
|
+
"package": "qdrant_client",
|
99
|
+
"object": "QdrantClient.scroll",
|
100
|
+
"endpoint": "qdrant.scroll",
|
101
|
+
"wrapper": general_wrap,
|
102
|
+
},
|
103
|
+
{
|
104
|
+
"package": "qdrant_client",
|
105
|
+
"object": "QdrantClient.search",
|
106
|
+
"endpoint": "qdrant.search",
|
107
|
+
"wrapper": general_wrap,
|
108
|
+
},
|
109
|
+
{
|
110
|
+
"package": "qdrant_client",
|
111
|
+
"object": "QdrantClient.search_groups",
|
112
|
+
"endpoint": "qdrant.search_groups",
|
113
|
+
"wrapper": general_wrap,
|
114
|
+
},
|
115
|
+
{
|
116
|
+
|
117
|
+
"package": "qdrant_client",
|
118
|
+
"object": "QdrantClient.recommend",
|
119
|
+
"endpoint": "qdrant.recommend",
|
120
|
+
"wrapper": general_wrap,
|
121
|
+
}
|
122
|
+
]
|
123
|
+
|
124
|
+
class QdrantInstrumentor(BaseInstrumentor):
|
125
|
+
"""An instrumentor for Qdrant's client library."""
|
126
|
+
|
127
|
+
def instrumentation_dependencies(self) -> Collection[str]:
|
128
|
+
return _instruments
|
129
|
+
|
130
|
+
def _instrument(self, **kwargs):
|
131
|
+
application_name = kwargs.get("application_name")
|
132
|
+
environment = kwargs.get("environment")
|
133
|
+
tracer = kwargs.get("tracer")
|
134
|
+
metrics = kwargs.get("metrics_dict")
|
135
|
+
pricing_info = kwargs.get("pricing_info")
|
136
|
+
trace_content = kwargs.get("trace_content")
|
137
|
+
disable_metrics = kwargs.get("disable_metrics")
|
138
|
+
version = importlib.metadata.version("qdrant-client")
|
139
|
+
|
140
|
+
for wrapped_method in WRAPPED_METHODS:
|
141
|
+
wrap_package = wrapped_method.get("package")
|
142
|
+
wrap_object = wrapped_method.get("object")
|
143
|
+
gen_ai_endpoint = wrapped_method.get("endpoint")
|
144
|
+
wrapper = wrapped_method.get("wrapper")
|
145
|
+
wrap_function_wrapper(
|
146
|
+
wrap_package,
|
147
|
+
wrap_object,
|
148
|
+
wrapper(gen_ai_endpoint, version, environment, application_name,
|
149
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
150
|
+
)
|
151
|
+
|
152
|
+
|
153
|
+
@staticmethod
|
154
|
+
def _uninstrument(self, **kwargs):
|
155
|
+
pass
|
@@ -0,0 +1,258 @@
|
|
1
|
+
# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, possibly-used-before-assignment, too-many-branches
|
2
|
+
"""
|
3
|
+
Module for monitoring Qdrant.
|
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 object_count(obj):
|
16
|
+
"""
|
17
|
+
Counts Length of object if it exists, Else returns None
|
18
|
+
"""
|
19
|
+
try:
|
20
|
+
cnt = len(obj)
|
21
|
+
# pylint: disable=bare-except
|
22
|
+
except:
|
23
|
+
cnt = 0
|
24
|
+
|
25
|
+
return cnt
|
26
|
+
|
27
|
+
def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
28
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics):
|
29
|
+
"""
|
30
|
+
Creates a wrapper around a function call to trace and log its execution metrics.
|
31
|
+
|
32
|
+
This function wraps any given function to measure its execution time,
|
33
|
+
log its operation, and trace its execution using OpenTelemetry.
|
34
|
+
|
35
|
+
Parameters:
|
36
|
+
- gen_ai_endpoint (str): A descriptor or name for the endpoint being traced.
|
37
|
+
- version (str): The version of the Langchain application.
|
38
|
+
- environment (str): The deployment environment (e.g., 'production', 'development').
|
39
|
+
- application_name (str): Name of the Langchain application.
|
40
|
+
- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.
|
41
|
+
- pricing_info (dict): Information about the pricing for internal metrics (currently not used).
|
42
|
+
- trace_content (bool): Flag indicating whether to trace the content of the response.
|
43
|
+
|
44
|
+
Returns:
|
45
|
+
- function: A higher-order function that takes a function 'wrapped' and returns
|
46
|
+
a new function that wraps 'wrapped' with additional tracing and logging.
|
47
|
+
"""
|
48
|
+
|
49
|
+
def wrapper(wrapped, instance, args, kwargs):
|
50
|
+
"""
|
51
|
+
An inner wrapper function that executes the wrapped function, measures execution
|
52
|
+
time, and records trace data using OpenTelemetry.
|
53
|
+
|
54
|
+
Parameters:
|
55
|
+
- wrapped (Callable): The original function that this wrapper will execute.
|
56
|
+
- instance (object): The instance to which the wrapped function belongs. This
|
57
|
+
is used for instance methods. For static and classmethods,
|
58
|
+
this may be None.
|
59
|
+
- args (tuple): Positional arguments passed to the wrapped function.
|
60
|
+
- kwargs (dict): Keyword arguments passed to the wrapped function.
|
61
|
+
|
62
|
+
Returns:
|
63
|
+
- The result of the wrapped function call.
|
64
|
+
|
65
|
+
The wrapper initiates a span with the provided tracer, sets various attributes
|
66
|
+
on the span based on the function's execution and response, and ensures
|
67
|
+
errors are handled and logged appropriately.
|
68
|
+
"""
|
69
|
+
with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
|
70
|
+
response = wrapped(*args, **kwargs)
|
71
|
+
|
72
|
+
try:
|
73
|
+
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
74
|
+
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
|
75
|
+
gen_ai_endpoint)
|
76
|
+
span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
|
77
|
+
environment)
|
78
|
+
span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
|
79
|
+
application_name)
|
80
|
+
span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
|
81
|
+
SemanticConvetion.GEN_AI_TYPE_VECTORDB)
|
82
|
+
span.set_attribute(SemanticConvetion.DB_SYSTEM,
|
83
|
+
SemanticConvetion.DB_SYSTEM_QDRANT)
|
84
|
+
|
85
|
+
if gen_ai_endpoint == "qdrant.create_collection":
|
86
|
+
db_operation = SemanticConvetion.DB_OPERATION_CREATE_COLLECTION
|
87
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
88
|
+
SemanticConvetion.DB_OPERATION_CREATE_COLLECTION)
|
89
|
+
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
90
|
+
kwargs.get("collection_name", ""))
|
91
|
+
|
92
|
+
elif gen_ai_endpoint == "qdrant.upload_collection":
|
93
|
+
db_operation = SemanticConvetion.DB_OPERATION_CREATE_COLLECTION
|
94
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
95
|
+
SemanticConvetion.DB_OPERATION_CREATE_COLLECTION)
|
96
|
+
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
97
|
+
kwargs.get("collection_name", ""))
|
98
|
+
|
99
|
+
elif gen_ai_endpoint == "qdrant.delete_collection":
|
100
|
+
db_operation = SemanticConvetion.DB_OPERATION_DELETE_COLLECTION
|
101
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
102
|
+
SemanticConvetion.DB_OPERATION_DELETE_COLLECTION)
|
103
|
+
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
104
|
+
kwargs.get("collection_name", ""))
|
105
|
+
|
106
|
+
elif gen_ai_endpoint == "qdrant.update_collection":
|
107
|
+
db_operation = SemanticConvetion.DB_OPERATION_UPDATE_COLLECTION
|
108
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
109
|
+
SemanticConvetion.DB_OPERATION_UPDATE_COLLECTION)
|
110
|
+
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
111
|
+
kwargs.get("collection_name", ""))
|
112
|
+
|
113
|
+
elif gen_ai_endpoint == "qdrant.set_payload":
|
114
|
+
db_operation = SemanticConvetion.DB_OPERATION_ADD
|
115
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
116
|
+
SemanticConvetion.DB_OPERATION_ADD)
|
117
|
+
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
118
|
+
kwargs.get("collection_name", ""))
|
119
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_STATUS,
|
120
|
+
response.status)
|
121
|
+
span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
|
122
|
+
object_count(kwargs.get("points")))
|
123
|
+
span.set_attribute(SemanticConvetion.DB_PAYLOAD_COUNT,
|
124
|
+
object_count(kwargs.get("payload")))
|
125
|
+
|
126
|
+
elif gen_ai_endpoint == "qdrant.retrieve":
|
127
|
+
db_operation = SemanticConvetion.DB_OPERATION_QUERY
|
128
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
129
|
+
SemanticConvetion.DB_OPERATION_QUERY)
|
130
|
+
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
131
|
+
kwargs.get("collection_name", ""))
|
132
|
+
span.set_attribute(SemanticConvetion.DB_STATEMENT,
|
133
|
+
str(kwargs.get("ids")))
|
134
|
+
|
135
|
+
elif gen_ai_endpoint == "qdrant.scroll":
|
136
|
+
db_operation = SemanticConvetion.DB_OPERATION_QUERY
|
137
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
138
|
+
SemanticConvetion.DB_OPERATION_QUERY)
|
139
|
+
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
140
|
+
kwargs.get("collection_name", ""))
|
141
|
+
span.set_attribute(SemanticConvetion.DB_STATEMENT,
|
142
|
+
str(kwargs.get("scroll_filter")))
|
143
|
+
|
144
|
+
elif gen_ai_endpoint in ["qdrant.search", "qdrant.search_groups"]:
|
145
|
+
db_operation = SemanticConvetion.DB_OPERATION_QUERY
|
146
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
147
|
+
SemanticConvetion.DB_OPERATION_QUERY)
|
148
|
+
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
149
|
+
kwargs.get("collection_name", ""))
|
150
|
+
span.set_attribute(SemanticConvetion.DB_STATEMENT,
|
151
|
+
str(kwargs.get("query_vector")))
|
152
|
+
|
153
|
+
elif gen_ai_endpoint == "qdrant.recommend":
|
154
|
+
db_operation = SemanticConvetion.DB_OPERATION_QUERY
|
155
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
156
|
+
SemanticConvetion.DB_OPERATION_QUERY)
|
157
|
+
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
158
|
+
kwargs.get("collection_name", ""))
|
159
|
+
span.set_attribute(SemanticConvetion.DB_STATEMENT,
|
160
|
+
"positive:" + str(kwargs.get("positive", "")) +
|
161
|
+
" negative:" + str(kwargs.get("negative", "")))
|
162
|
+
|
163
|
+
elif gen_ai_endpoint == "qdrant.upload_points":
|
164
|
+
db_operation = SemanticConvetion.DB_OPERATION_ADD
|
165
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
166
|
+
SemanticConvetion.DB_OPERATION_ADD)
|
167
|
+
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
168
|
+
kwargs.get("collection_name", ""))
|
169
|
+
span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
|
170
|
+
object_count(kwargs.get("points")))
|
171
|
+
|
172
|
+
elif gen_ai_endpoint == "qdrant.update_vectors":
|
173
|
+
db_operation = SemanticConvetion.DB_OPERATION_UPDATE
|
174
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
175
|
+
SemanticConvetion.DB_OPERATION_UPDATE)
|
176
|
+
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
177
|
+
kwargs.get("collection_name", ""))
|
178
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_STATUS,
|
179
|
+
response.status)
|
180
|
+
span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
|
181
|
+
object_count(kwargs.get("points")))
|
182
|
+
|
183
|
+
elif gen_ai_endpoint == "qdrant.overwrite_payload":
|
184
|
+
db_operation = SemanticConvetion.DB_OPERATION_UPDATE
|
185
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
186
|
+
SemanticConvetion.DB_OPERATION_UPDATE)
|
187
|
+
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
188
|
+
kwargs.get("collection_name", ""))
|
189
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_STATUS,
|
190
|
+
response.status)
|
191
|
+
span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
|
192
|
+
object_count(kwargs.get("points")))
|
193
|
+
span.set_attribute(SemanticConvetion.DB_PAYLOAD_COUNT,
|
194
|
+
object_count(kwargs.get("payload")))
|
195
|
+
|
196
|
+
elif gen_ai_endpoint == "qdrant.upsert":
|
197
|
+
db_operation = SemanticConvetion.DB_OPERATION_UPSERT
|
198
|
+
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
199
|
+
kwargs.get("collection_name", ""))
|
200
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
201
|
+
SemanticConvetion.DB_OPERATION_UPSERT)
|
202
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_STATUS,
|
203
|
+
response.status)
|
204
|
+
span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
|
205
|
+
object_count(kwargs.get("points")))
|
206
|
+
|
207
|
+
elif gen_ai_endpoint in ["qdrant.delete_payload", "qdrant.delete_vectors"]:
|
208
|
+
db_operation = SemanticConvetion.DB_OPERATION_DELETE
|
209
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
210
|
+
SemanticConvetion.DB_OPERATION_DELETE)
|
211
|
+
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
212
|
+
kwargs.get("collection_name", ""))
|
213
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_STATUS,
|
214
|
+
response.status)
|
215
|
+
span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
|
216
|
+
object_count(kwargs.get("points")))
|
217
|
+
|
218
|
+
elif gen_ai_endpoint in ["qdrant.clear_payload", "qdrant.delete"]:
|
219
|
+
db_operation = SemanticConvetion.DB_OPERATION_DELETE
|
220
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
221
|
+
SemanticConvetion.DB_OPERATION_DELETE)
|
222
|
+
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
223
|
+
kwargs.get("collection_name", ""))
|
224
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_STATUS,
|
225
|
+
response.status)
|
226
|
+
span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
|
227
|
+
object_count(kwargs.get("points_selector")))
|
228
|
+
|
229
|
+
span.set_status(Status(StatusCode.OK))
|
230
|
+
|
231
|
+
if disable_metrics is False:
|
232
|
+
attributes = {
|
233
|
+
TELEMETRY_SDK_NAME:
|
234
|
+
"openlit",
|
235
|
+
SemanticConvetion.GEN_AI_APPLICATION_NAME:
|
236
|
+
application_name,
|
237
|
+
SemanticConvetion.DB_SYSTEM:
|
238
|
+
SemanticConvetion.DB_SYSTEM_QDRANT,
|
239
|
+
SemanticConvetion.GEN_AI_ENVIRONMENT:
|
240
|
+
environment,
|
241
|
+
SemanticConvetion.GEN_AI_TYPE:
|
242
|
+
SemanticConvetion.GEN_AI_TYPE_VECTORDB,
|
243
|
+
SemanticConvetion.DB_OPERATION:
|
244
|
+
db_operation
|
245
|
+
}
|
246
|
+
|
247
|
+
metrics["db_requests"].add(1, attributes)
|
248
|
+
|
249
|
+
return response
|
250
|
+
|
251
|
+
except Exception as e:
|
252
|
+
handle_exception(span, e)
|
253
|
+
logger.error("Error in trace creation: %s", e)
|
254
|
+
|
255
|
+
# Return original response
|
256
|
+
return response
|
257
|
+
|
258
|
+
return wrapper
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
|
2
|
+
"""Initializer of Auto Instrumentation of VertexAI 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.vertexai.vertexai import (
|
10
|
+
generate_content, predict, predict_streaming,
|
11
|
+
send_message, start_chat, start_chat_streaming,
|
12
|
+
embeddings
|
13
|
+
)
|
14
|
+
from openlit.instrumentation.vertexai.async_vertexai import (
|
15
|
+
generate_content_async, predict_async,
|
16
|
+
predict_streaming_async,
|
17
|
+
send_message_async,
|
18
|
+
start_chat_async, start_chat_streaming_async,
|
19
|
+
embeddings_async
|
20
|
+
)
|
21
|
+
|
22
|
+
|
23
|
+
_instruments = ("google-cloud-aiplatform >= 1.38.1",)
|
24
|
+
|
25
|
+
class VertexAIInstrumentor(BaseInstrumentor):
|
26
|
+
"""
|
27
|
+
An instrumentor for VertexAI's client library.
|
28
|
+
"""
|
29
|
+
|
30
|
+
def instrumentation_dependencies(self) -> Collection[str]:
|
31
|
+
return _instruments
|
32
|
+
|
33
|
+
def _instrument(self, **kwargs):
|
34
|
+
application_name = kwargs.get("application_name", "default")
|
35
|
+
environment = kwargs.get("environment", "default")
|
36
|
+
tracer = kwargs.get("tracer")
|
37
|
+
metrics = kwargs.get("metrics_dict")
|
38
|
+
pricing_info = kwargs.get("pricing_info", {})
|
39
|
+
trace_content = kwargs.get("trace_content", False)
|
40
|
+
disable_metrics = kwargs.get("disable_metrics")
|
41
|
+
version = importlib.metadata.version("google-cloud-aiplatform")
|
42
|
+
|
43
|
+
#sync
|
44
|
+
wrap_function_wrapper(
|
45
|
+
"vertexai.generative_models",
|
46
|
+
"GenerativeModel.generate_content",
|
47
|
+
generate_content("vertexai.generate_content", version, environment, application_name,
|
48
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
49
|
+
)
|
50
|
+
|
51
|
+
wrap_function_wrapper(
|
52
|
+
"vertexai.generative_models",
|
53
|
+
"ChatSession.send_message",
|
54
|
+
send_message("vertexai.send_message", version, environment, application_name,
|
55
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
56
|
+
)
|
57
|
+
|
58
|
+
wrap_function_wrapper(
|
59
|
+
"vertexai.language_models",
|
60
|
+
"TextGenerationModel.predict",
|
61
|
+
predict("vertexai.predict", version, environment, application_name,
|
62
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
63
|
+
)
|
64
|
+
|
65
|
+
wrap_function_wrapper(
|
66
|
+
"vertexai.language_models",
|
67
|
+
"TextGenerationModel.predict_streaming",
|
68
|
+
predict_streaming("vertexai.predict", version, environment, application_name,
|
69
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
70
|
+
)
|
71
|
+
|
72
|
+
wrap_function_wrapper(
|
73
|
+
"vertexai.language_models",
|
74
|
+
"ChatSession.send_message",
|
75
|
+
start_chat("vertexai.send_message", version, environment, application_name,
|
76
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
77
|
+
)
|
78
|
+
|
79
|
+
wrap_function_wrapper(
|
80
|
+
"vertexai.language_models",
|
81
|
+
"ChatSession.send_message_streaming",
|
82
|
+
start_chat_streaming("vertexai.send_message", version, environment, application_name,
|
83
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
84
|
+
)
|
85
|
+
|
86
|
+
wrap_function_wrapper(
|
87
|
+
"vertexai.language_models",
|
88
|
+
"TextEmbeddingModel.get_embeddings",
|
89
|
+
embeddings("vertexai.get_embeddings", version, environment, application_name,
|
90
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
91
|
+
)
|
92
|
+
|
93
|
+
#async
|
94
|
+
wrap_function_wrapper(
|
95
|
+
"vertexai.generative_models",
|
96
|
+
"GenerativeModel.generate_content_async",
|
97
|
+
generate_content_async("vertexai.generate_content", version, environment,
|
98
|
+
application_name, tracer, pricing_info, trace_content,
|
99
|
+
metrics, disable_metrics),
|
100
|
+
)
|
101
|
+
|
102
|
+
wrap_function_wrapper(
|
103
|
+
"vertexai.generative_models",
|
104
|
+
"ChatSession.send_message_async",
|
105
|
+
send_message_async("vertexai.send_message", version, environment, application_name,
|
106
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
107
|
+
)
|
108
|
+
|
109
|
+
wrap_function_wrapper(
|
110
|
+
"vertexai.language_models",
|
111
|
+
"TextGenerationModel.predict_async",
|
112
|
+
predict_async("vertexai.predict", version, environment, application_name,
|
113
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
114
|
+
)
|
115
|
+
|
116
|
+
wrap_function_wrapper(
|
117
|
+
"vertexai.language_models",
|
118
|
+
"TextGenerationModel.predict_streaming_async",
|
119
|
+
predict_streaming_async("vertexai.predict", version, environment, application_name,
|
120
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
121
|
+
)
|
122
|
+
|
123
|
+
wrap_function_wrapper(
|
124
|
+
"vertexai.language_models",
|
125
|
+
"ChatSession.send_message_async",
|
126
|
+
start_chat_async("vertexai.send_message", version, environment, application_name,
|
127
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
128
|
+
)
|
129
|
+
|
130
|
+
wrap_function_wrapper(
|
131
|
+
"vertexai.language_models",
|
132
|
+
"ChatSession.send_message_streaming_async",
|
133
|
+
start_chat_streaming_async("vertexai.send_message", version, environment,
|
134
|
+
application_name, tracer, pricing_info, trace_content,
|
135
|
+
metrics, disable_metrics),
|
136
|
+
)
|
137
|
+
|
138
|
+
wrap_function_wrapper(
|
139
|
+
"vertexai.language_models",
|
140
|
+
"TextEmbeddingModel.get_embeddings_async",
|
141
|
+
embeddings_async("vertexai.get_embeddings", version, environment, application_name,
|
142
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
143
|
+
)
|
144
|
+
|
145
|
+
def _uninstrument(self, **kwargs):
|
146
|
+
# Proper uninstrumentation logic to revert patched methods
|
147
|
+
pass
|