openlit 1.33.14__py3-none-any.whl → 1.33.16__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/astra/__init__.py +82 -83
- openlit/instrumentation/astra/astra.py +26 -207
- openlit/instrumentation/astra/async_astra.py +27 -208
- openlit/instrumentation/astra/utils.py +102 -0
- openlit/instrumentation/chroma/chroma.py +10 -10
- openlit/instrumentation/dynamiq/dynamiq.py +2 -2
- openlit/instrumentation/milvus/milvus.py +10 -10
- openlit/instrumentation/openai/__init__.py +18 -2
- openlit/instrumentation/openai/async_openai.py +405 -0
- openlit/instrumentation/openai/openai.py +405 -0
- openlit/instrumentation/openai_agents/__init__.py +42 -0
- openlit/instrumentation/openai_agents/openai_agents.py +65 -0
- openlit/instrumentation/pinecone/pinecone.py +8 -8
- openlit/instrumentation/qdrant/async_qdrant.py +19 -19
- openlit/instrumentation/qdrant/qdrant.py +20 -20
- openlit/otel/metrics.py +18 -0
- openlit/semcov/__init__.py +26 -13
- {openlit-1.33.14.dist-info → openlit-1.33.16.dist-info}/METADATA +1 -1
- {openlit-1.33.14.dist-info → openlit-1.33.16.dist-info}/RECORD +22 -19
- {openlit-1.33.14.dist-info → openlit-1.33.16.dist-info}/LICENSE +0 -0
- {openlit-1.33.14.dist-info → openlit-1.33.16.dist-info}/WHEEL +0 -0
@@ -1,226 +1,45 @@
|
|
1
|
-
# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, possibly-used-before-assignment, too-many-branches
|
2
1
|
"""
|
3
2
|
Module for monitoring AstraDB.
|
4
3
|
"""
|
5
4
|
|
6
|
-
import
|
7
|
-
from opentelemetry.trace import SpanKind
|
8
|
-
from
|
9
|
-
|
5
|
+
import time
|
6
|
+
from opentelemetry.trace import SpanKind
|
7
|
+
from openlit.instrumentation.astra.utils import (
|
8
|
+
DB_OPERATION_MAP,
|
9
|
+
process_db_operations
|
10
|
+
)
|
10
11
|
from openlit.semcov import SemanticConvetion
|
11
12
|
|
12
|
-
|
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
|
-
|
20
|
-
return len(obj) if obj else None
|
21
|
-
|
22
|
-
def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
13
|
+
def async_general_wrap(gen_ai_endpoint, version, environment, application_name,
|
23
14
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics):
|
24
15
|
"""
|
25
|
-
|
26
|
-
|
27
|
-
This function is intended to wrap around AstraDB operations in order to
|
28
|
-
measure their execution time, log relevant information, and trace the execution
|
29
|
-
using OpenTelemetry. This helps in monitoring and debugging operations within
|
30
|
-
the AstraDB space.
|
31
|
-
|
32
|
-
Parameters:
|
33
|
-
- operation (str): The specific AstraDB operation being monitored.
|
34
|
-
Examples include 'create_index', 'query', 'upsert', etc.
|
35
|
-
- version (str): The version of the application interfacing with AstraDB.
|
36
|
-
- environment (str): The deployment environment, such as 'production' or 'development'.
|
37
|
-
- application_name (str): The name of the application performing the AstraDB operation.
|
38
|
-
- tracer (opentelemetry.trace.Tracer): An object used for OpenTelemetry tracing.
|
39
|
-
- pricing_info (dict): Information about pricing, not used in current implementation.
|
40
|
-
- capture_message_content (bool): A flag indicating whether the content of responses should be traced.
|
41
|
-
|
42
|
-
Returns:
|
43
|
-
- function: A decorator function that, when applied, wraps the target function with
|
44
|
-
additional functionality for tracing and logging AstraDB operations.
|
16
|
+
Generates a telemetry wrapper for VectorDB function call
|
45
17
|
"""
|
46
18
|
|
47
19
|
async def wrapper(wrapped, instance, args, kwargs):
|
48
20
|
"""
|
49
|
-
|
50
|
-
|
51
|
-
This inner wrapper function captures the execution of AstraDB operations,
|
52
|
-
annotating the operation with relevant metrics and tracing information, and
|
53
|
-
ensuring any exceptions are caught and logged appropriately.
|
54
|
-
|
55
|
-
Parameters:
|
56
|
-
- wrapped (Callable): The AstraDB operation to be wrapped and executed.
|
57
|
-
- instance (object): The instance on which the operation is called (for class methods).
|
58
|
-
- args (tuple): Positional arguments for the AstraDB operation.
|
59
|
-
- kwargs (dict): Keyword arguments for the AstraDB operation.
|
60
|
-
|
61
|
-
Returns:
|
62
|
-
- Any: The result of executing the wrapped AstraDB operation.
|
21
|
+
Wraps the VectorDB function call.
|
63
22
|
"""
|
64
23
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
try:
|
69
|
-
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
70
|
-
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
|
71
|
-
gen_ai_endpoint)
|
72
|
-
span.set_attribute(DEPLOYMENT_ENVIRONMENT,
|
73
|
-
environment)
|
74
|
-
span.set_attribute(SERVICE_NAME,
|
75
|
-
application_name)
|
76
|
-
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
|
77
|
-
SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB)
|
78
|
-
span.set_attribute(SemanticConvetion.DB_SYSTEM,
|
79
|
-
SemanticConvetion.DB_SYSTEM_ASTRA)
|
80
|
-
|
81
|
-
if gen_ai_endpoint == "astra.create_collection":
|
82
|
-
db_operation = SemanticConvetion.DB_OPERATION_CREATE_COLLECTION
|
83
|
-
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
84
|
-
db_operation)
|
85
|
-
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
86
|
-
response.name)
|
87
|
-
span.set_attribute(SemanticConvetion.DB_INDEX_DIMENSION,
|
88
|
-
kwargs.get("dimension", ""))
|
89
|
-
span.set_attribute(SemanticConvetion.DB_INDEX_METRIC,
|
90
|
-
str(kwargs.get("metric", "")))
|
91
|
-
span.set_attribute(SemanticConvetion.DB_OPERATION_API_ENDPOINT,
|
92
|
-
instance.api_endpoint)
|
24
|
+
db_operation = DB_OPERATION_MAP.get(gen_ai_endpoint, "UNKNOWN")
|
25
|
+
if db_operation == SemanticConvetion.DB_OPERATION_REPLACE and kwargs.get('upsert'):
|
26
|
+
db_operation = SemanticConvetion.DB_OPERATION_UPSERT
|
93
27
|
|
94
|
-
|
95
|
-
db_operation = SemanticConvetion.DB_OPERATION_DELETE_COLLECTION
|
96
|
-
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
97
|
-
db_operation)
|
98
|
-
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
99
|
-
kwargs.get("name_or_collection", ""))
|
100
|
-
span.set_attribute(SemanticConvetion.DB_OPERATION_API_ENDPOINT,
|
101
|
-
instance.api_endpoint)
|
28
|
+
span_name = f"{db_operation} {instance.name}"
|
102
29
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
db_operation = SemanticConvetion.DB_OPERATION_INSERT
|
118
|
-
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
119
|
-
db_operation)
|
120
|
-
span.set_attribute(SemanticConvetion.DB_DOCUMENTS_COUNT,
|
121
|
-
object_count(args[0]))
|
122
|
-
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
123
|
-
instance.name)
|
124
|
-
span.set_attribute(SemanticConvetion.DB_OPERATION_API_ENDPOINT,
|
125
|
-
instance.database.api_endpoint)
|
126
|
-
|
127
|
-
elif gen_ai_endpoint in ["astra.update_one", "astra.update_many"]:
|
128
|
-
db_operation = SemanticConvetion.DB_OPERATION_UPDATE
|
129
|
-
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
130
|
-
db_operation)
|
131
|
-
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
132
|
-
instance.name)
|
133
|
-
span.set_attribute(SemanticConvetion.DB_OPERATION_API_ENDPOINT,
|
134
|
-
instance.database.api_endpoint)
|
135
|
-
span.set_attribute(SemanticConvetion.DB_DOCUMENTS_COUNT,
|
136
|
-
response.update_info.get("nModified", 0))
|
137
|
-
|
138
|
-
elif gen_ai_endpoint == "astra.find_one_and_update":
|
139
|
-
db_operation = SemanticConvetion.DB_OPERATION_UPDATE
|
140
|
-
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
141
|
-
db_operation)
|
142
|
-
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
143
|
-
instance.name)
|
144
|
-
span.set_attribute(SemanticConvetion.DB_OPERATION_API_ENDPOINT,
|
145
|
-
instance.database.api_endpoint)
|
146
|
-
|
147
|
-
elif gen_ai_endpoint == "astra.find":
|
148
|
-
db_operation = SemanticConvetion.DB_OPERATION_QUERY
|
149
|
-
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
150
|
-
db_operation)
|
151
|
-
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
152
|
-
instance.name)
|
153
|
-
span.set_attribute(SemanticConvetion.DB_OPERATION_API_ENDPOINT,
|
154
|
-
instance.database.api_endpoint)
|
155
|
-
span.set_attribute(SemanticConvetion.DB_STATEMENT,
|
156
|
-
str(args))
|
157
|
-
|
158
|
-
elif gen_ai_endpoint == "astra.replace_one":
|
159
|
-
if kwargs.get("upsert") is True:
|
160
|
-
db_operation = SemanticConvetion.DB_OPERATION_UPSERT
|
161
|
-
else:
|
162
|
-
db_operation = SemanticConvetion.DB_OPERATION_REPLACE
|
163
|
-
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
164
|
-
db_operation)
|
165
|
-
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
166
|
-
instance.name)
|
167
|
-
span.set_attribute(SemanticConvetion.DB_OPERATION_API_ENDPOINT,
|
168
|
-
instance.database.api_endpoint)
|
169
|
-
span.set_attribute(SemanticConvetion.DB_STATEMENT,
|
170
|
-
str(args))
|
171
|
-
|
172
|
-
elif gen_ai_endpoint in ["astra.delete_one", "astra.delete_many"]:
|
173
|
-
db_operation = SemanticConvetion.DB_OPERATION_DELETE
|
174
|
-
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
175
|
-
db_operation)
|
176
|
-
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
177
|
-
instance.name)
|
178
|
-
span.set_attribute(SemanticConvetion.DB_OPERATION_API_ENDPOINT,
|
179
|
-
instance.database.api_endpoint)
|
180
|
-
span.set_attribute(SemanticConvetion.DB_STATEMENT,
|
181
|
-
str(args))
|
182
|
-
span.set_attribute(SemanticConvetion.DB_DOCUMENTS_COUNT,
|
183
|
-
response.deleted_count)
|
184
|
-
|
185
|
-
elif gen_ai_endpoint == "astra.find_one_and_delete":
|
186
|
-
db_operation = SemanticConvetion.DB_OPERATION_DELETE
|
187
|
-
span.set_attribute(SemanticConvetion.DB_OPERATION,
|
188
|
-
db_operation)
|
189
|
-
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
190
|
-
instance.name)
|
191
|
-
span.set_attribute(SemanticConvetion.DB_OPERATION_API_ENDPOINT,
|
192
|
-
instance.database.api_endpoint)
|
193
|
-
span.set_attribute(SemanticConvetion.DB_STATEMENT,
|
194
|
-
str(args))
|
195
|
-
|
196
|
-
span.set_status(Status(StatusCode.OK))
|
197
|
-
|
198
|
-
if disable_metrics is False:
|
199
|
-
attributes = {
|
200
|
-
TELEMETRY_SDK_NAME:
|
201
|
-
"openlit",
|
202
|
-
SERVICE_NAME:
|
203
|
-
application_name,
|
204
|
-
SemanticConvetion.DB_SYSTEM:
|
205
|
-
SemanticConvetion.DB_SYSTEM_ASTRA,
|
206
|
-
DEPLOYMENT_ENVIRONMENT:
|
207
|
-
environment,
|
208
|
-
SemanticConvetion.GEN_AI_OPERATION:
|
209
|
-
SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB,
|
210
|
-
SemanticConvetion.DB_OPERATION:
|
211
|
-
db_operation
|
212
|
-
}
|
213
|
-
|
214
|
-
metrics["db_requests"].add(1, attributes)
|
215
|
-
|
216
|
-
# Return original response
|
217
|
-
return response
|
218
|
-
|
219
|
-
except Exception as e:
|
220
|
-
handle_exception(span, e)
|
221
|
-
logger.error("Error in trace creation: %s", e)
|
222
|
-
|
223
|
-
# Return original response
|
224
|
-
return response
|
30
|
+
with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
|
31
|
+
start_time = time.time()
|
32
|
+
response = await wrapped(*args, **kwargs)
|
33
|
+
server_address = getattr(getattr(instance, 'database', instance), 'api_endpoint', '')
|
34
|
+
server_port = 443
|
35
|
+
collection_name = instance.name
|
36
|
+
response = process_db_operations(
|
37
|
+
response, span, start_time, gen_ai_endpoint,
|
38
|
+
version, environment, application_name, capture_message_content,
|
39
|
+
metrics, disable_metrics, server_address, server_port,
|
40
|
+
collection_name, db_operation, kwargs, args
|
41
|
+
)
|
42
|
+
|
43
|
+
return response
|
225
44
|
|
226
45
|
return wrapper
|
@@ -0,0 +1,102 @@
|
|
1
|
+
"""
|
2
|
+
Astra OpenTelemetry instrumentation utility functions
|
3
|
+
"""
|
4
|
+
|
5
|
+
import time
|
6
|
+
import logging
|
7
|
+
from opentelemetry.trace import Status, StatusCode
|
8
|
+
from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
|
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
|
+
"""Counts Length of object if it exists, Else returns None."""
|
17
|
+
return len(obj) if isinstance(obj, list) else 1
|
18
|
+
|
19
|
+
DB_OPERATION_MAP = {
|
20
|
+
'astra.create_collection': SemanticConvetion.DB_OPERATION_CREATE_COLLECTION,
|
21
|
+
'astra.drop_collection': SemanticConvetion.DB_OPERATION_DELETE_COLLECTION,
|
22
|
+
'astra.insert': SemanticConvetion.DB_OPERATION_INSERT,
|
23
|
+
'astra.update': SemanticConvetion.DB_OPERATION_UPDATE,
|
24
|
+
'astra.find': SemanticConvetion.DB_OPERATION_SELECT,
|
25
|
+
'astra.find_one_and_update': SemanticConvetion.DB_OPERATION_REPLACE,
|
26
|
+
'astra.replace_one': SemanticConvetion.DB_OPERATION_REPLACE,
|
27
|
+
'astra.delete': SemanticConvetion.DB_OPERATION_DELETE,
|
28
|
+
'astra.find_one_and_delete': SemanticConvetion.DB_OPERATION_FIND_AND_DELETE
|
29
|
+
}
|
30
|
+
|
31
|
+
def process_db_operations(response, span, start_time, gen_ai_endpoint,
|
32
|
+
version, environment, application_name,
|
33
|
+
capture_message_content, metrics, disable_metrics, server_address,
|
34
|
+
server_port, collection_name, db_operation, kwargs, args):
|
35
|
+
"""
|
36
|
+
Process DB operation and generate Telemetry
|
37
|
+
"""
|
38
|
+
|
39
|
+
end_time = time.time()
|
40
|
+
|
41
|
+
try:
|
42
|
+
span.set_attribute(TELEMETRY_SDK_NAME, 'openlit')
|
43
|
+
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION, SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB)
|
44
|
+
span.set_attribute(SemanticConvetion.DB_SYSTEM_NAME, SemanticConvetion.DB_SYSTEM_ASTRA)
|
45
|
+
span.set_attribute(SemanticConvetion.DB_CLIENT_OPERATION_DURATION, end_time - start_time)
|
46
|
+
span.set_attribute(SemanticConvetion.SERVER_ADDRESS, server_address)
|
47
|
+
span.set_attribute(SemanticConvetion.SERVER_PORT, server_port)
|
48
|
+
span.set_attribute(DEPLOYMENT_ENVIRONMENT, environment)
|
49
|
+
span.set_attribute(SERVICE_NAME, application_name)
|
50
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_NAME, db_operation)
|
51
|
+
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME, collection_name)
|
52
|
+
span.set_attribute(SemanticConvetion.DB_SDK_VERSION, version)
|
53
|
+
|
54
|
+
if db_operation == SemanticConvetion.DB_OPERATION_CREATE_COLLECTION:
|
55
|
+
span.set_attribute(SemanticConvetion.DB_NAMESPACE, response.keyspace)
|
56
|
+
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME, response.name)
|
57
|
+
span.set_attribute(SemanticConvetion.DB_INDEX_DIMENSION, kwargs.get('dimension', ''))
|
58
|
+
span.set_attribute(SemanticConvetion.DB_INDEX_METRIC, str(kwargs.get('metric', '')))
|
59
|
+
|
60
|
+
if db_operation == SemanticConvetion.DB_OPERATION_INSERT:
|
61
|
+
span.set_attribute(SemanticConvetion.DB_DOCUMENTS_COUNT, object_count(args[0]))
|
62
|
+
span.set_attribute(SemanticConvetion.DB_QUERY_TEXT, str(args[0] or kwargs.get('documents', {})))
|
63
|
+
|
64
|
+
elif db_operation == SemanticConvetion.DB_OPERATION_UPDATE:
|
65
|
+
span.set_attribute(SemanticConvetion.DB_RESPONSE_RETURNED_ROWS, response.update_info.get('nModified', 0))
|
66
|
+
span.set_attribute(SemanticConvetion.DB_QUERY_TEXT, str(args[1] or kwargs.get('update', {})))
|
67
|
+
|
68
|
+
elif db_operation == SemanticConvetion.DB_OPERATION_DELETE:
|
69
|
+
span.set_attribute(SemanticConvetion.DB_RESPONSE_RETURNED_ROWS, response.deleted_count)
|
70
|
+
span.set_attribute(SemanticConvetion.DB_QUERY_TEXT, str(args[0] or kwargs.get('filter', {})))
|
71
|
+
|
72
|
+
elif db_operation in [
|
73
|
+
SemanticConvetion.DB_OPERATION_SELECT,
|
74
|
+
SemanticConvetion.DB_OPERATION_FIND_AND_DELETE,
|
75
|
+
SemanticConvetion.DB_OPERATION_REPLACE
|
76
|
+
]:
|
77
|
+
span.set_attribute(SemanticConvetion.DB_QUERY_TEXT, str(args or kwargs.get('filter', {})))
|
78
|
+
|
79
|
+
span.set_status(Status(StatusCode.OK))
|
80
|
+
|
81
|
+
if not disable_metrics:
|
82
|
+
attributes = {
|
83
|
+
TELEMETRY_SDK_NAME: 'openlit',
|
84
|
+
SERVICE_NAME: application_name,
|
85
|
+
SemanticConvetion.DB_SYSTEM_NAME: SemanticConvetion.DB_SYSTEM_ASTRA,
|
86
|
+
DEPLOYMENT_ENVIRONMENT: environment,
|
87
|
+
SemanticConvetion.GEN_AI_OPERATION: SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB,
|
88
|
+
SemanticConvetion.DB_OPERATION_NAME: db_operation
|
89
|
+
}
|
90
|
+
|
91
|
+
metrics['db_requests'].add(1, attributes)
|
92
|
+
metrics['db_client_operation_duration'].record(end_time - start_time, attributes)
|
93
|
+
|
94
|
+
# Return original response
|
95
|
+
return response
|
96
|
+
|
97
|
+
except Exception as e:
|
98
|
+
handle_exception(span, e)
|
99
|
+
logger.error('Error in trace creation: %s', e)
|
100
|
+
|
101
|
+
# Return original response
|
102
|
+
return response
|
@@ -79,14 +79,14 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
79
79
|
application_name)
|
80
80
|
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
|
81
81
|
SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB)
|
82
|
-
span.set_attribute(SemanticConvetion.
|
82
|
+
span.set_attribute(SemanticConvetion.DB_SYSTEM_NAME,
|
83
83
|
SemanticConvetion.DB_SYSTEM_CHROMA)
|
84
84
|
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
85
85
|
instance.name)
|
86
86
|
|
87
87
|
if gen_ai_endpoint == "chroma.add":
|
88
88
|
db_operation = SemanticConvetion.DB_OPERATION_ADD
|
89
|
-
span.set_attribute(SemanticConvetion.
|
89
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_NAME,
|
90
90
|
SemanticConvetion.DB_OPERATION_ADD)
|
91
91
|
span.set_attribute(SemanticConvetion.DB_ID_COUNT,
|
92
92
|
object_count(kwargs.get("ids", [])))
|
@@ -99,7 +99,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
99
99
|
|
100
100
|
elif gen_ai_endpoint == "chroma.get":
|
101
101
|
db_operation = SemanticConvetion.DB_OPERATION_GET
|
102
|
-
span.set_attribute(SemanticConvetion.
|
102
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_NAME,
|
103
103
|
SemanticConvetion.DB_OPERATION_GET)
|
104
104
|
span.set_attribute(SemanticConvetion.DB_ID_COUNT,
|
105
105
|
object_count(kwargs.get("ids", [])))
|
@@ -112,7 +112,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
112
112
|
|
113
113
|
elif gen_ai_endpoint == "chroma.query":
|
114
114
|
db_operation = SemanticConvetion.DB_OPERATION_QUERY
|
115
|
-
span.set_attribute(SemanticConvetion.
|
115
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_NAME,
|
116
116
|
SemanticConvetion.DB_OPERATION_QUERY)
|
117
117
|
span.set_attribute(SemanticConvetion.DB_STATEMENT,
|
118
118
|
str(kwargs.get("query_texts", "")))
|
@@ -125,7 +125,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
125
125
|
|
126
126
|
elif gen_ai_endpoint == "chroma.update":
|
127
127
|
db_operation = SemanticConvetion.DB_OPERATION_UPDATE
|
128
|
-
span.set_attribute(SemanticConvetion.
|
128
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_NAME,
|
129
129
|
SemanticConvetion.DB_OPERATION_UPDATE)
|
130
130
|
span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
|
131
131
|
object_count(kwargs.get("embeddings", [])))
|
@@ -138,7 +138,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
138
138
|
|
139
139
|
elif gen_ai_endpoint == "chroma.upsert":
|
140
140
|
db_operation = SemanticConvetion.DB_OPERATION_UPSERT
|
141
|
-
span.set_attribute(SemanticConvetion.
|
141
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_NAME,
|
142
142
|
SemanticConvetion.DB_OPERATION_UPSERT)
|
143
143
|
span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
|
144
144
|
object_count(kwargs.get("embeddings", [])))
|
@@ -151,7 +151,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
151
151
|
|
152
152
|
elif gen_ai_endpoint == "chroma.delete":
|
153
153
|
db_operation = SemanticConvetion.DB_OPERATION_DELETE
|
154
|
-
span.set_attribute(SemanticConvetion.
|
154
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_NAME,
|
155
155
|
SemanticConvetion.DB_OPERATION_DELETE)
|
156
156
|
span.set_attribute(SemanticConvetion.DB_ID_COUNT,
|
157
157
|
object_count(kwargs.get("ids", [])))
|
@@ -164,7 +164,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
164
164
|
|
165
165
|
elif gen_ai_endpoint == "chroma.peek":
|
166
166
|
db_operation = SemanticConvetion.DB_OPERATION_PEEK
|
167
|
-
span.set_attribute(SemanticConvetion.
|
167
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_NAME,
|
168
168
|
SemanticConvetion.DB_OPERATION_PEEK)
|
169
169
|
|
170
170
|
span.set_status(Status(StatusCode.OK))
|
@@ -175,13 +175,13 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
175
175
|
"openlit",
|
176
176
|
SERVICE_NAME:
|
177
177
|
application_name,
|
178
|
-
SemanticConvetion.
|
178
|
+
SemanticConvetion.DB_SYSTEM_NAME:
|
179
179
|
SemanticConvetion.DB_SYSTEM_CHROMA,
|
180
180
|
DEPLOYMENT_ENVIRONMENT:
|
181
181
|
environment,
|
182
182
|
SemanticConvetion.GEN_AI_OPERATION:
|
183
183
|
SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB,
|
184
|
-
SemanticConvetion.
|
184
|
+
SemanticConvetion.DB_OPERATION_NAME:
|
185
185
|
db_operation
|
186
186
|
}
|
187
187
|
|
@@ -84,13 +84,13 @@ def dynamiq_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
84
84
|
getattr(getattr(instance.flow, 'nodes', [None])[0], 'model', 'default_model'))
|
85
85
|
|
86
86
|
elif gen_ai_endpoint == "dynamiq.memory_add":
|
87
|
-
span.set_attribute(SemanticConvetion.
|
87
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_NAME,
|
88
88
|
SemanticConvetion.DB_OPERATION_ADD)
|
89
89
|
span.set_attribute(SemanticConvetion.DB_METADATA, str(kwargs.get('metadata', '')))
|
90
90
|
|
91
91
|
elif gen_ai_endpoint == "dynamiq.memory_search":
|
92
92
|
query_value = kwargs.get('query', '') or (args[0] if args else '')
|
93
|
-
span.set_attribute(SemanticConvetion.
|
93
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_NAME,
|
94
94
|
SemanticConvetion.DB_OPERATION_GET)
|
95
95
|
span.set_attribute(SemanticConvetion.DB_FILTER, str(kwargs.get('filters', '')))
|
96
96
|
span.set_attribute(SemanticConvetion.DB_STATEMENT, query_value)
|
@@ -79,12 +79,12 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
79
79
|
application_name)
|
80
80
|
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
|
81
81
|
SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB)
|
82
|
-
span.set_attribute(SemanticConvetion.
|
82
|
+
span.set_attribute(SemanticConvetion.DB_SYSTEM_NAME,
|
83
83
|
SemanticConvetion.DB_SYSTEM_MILVUS)
|
84
84
|
|
85
85
|
if gen_ai_endpoint == "milvus.create_collection":
|
86
86
|
db_operation = SemanticConvetion.DB_OPERATION_CREATE_COLLECTION
|
87
|
-
span.set_attribute(SemanticConvetion.
|
87
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_NAME,
|
88
88
|
SemanticConvetion.DB_OPERATION_CREATE_COLLECTION)
|
89
89
|
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
90
90
|
kwargs.get("collection_name", ""))
|
@@ -93,14 +93,14 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
93
93
|
|
94
94
|
elif gen_ai_endpoint == "milvus.drop_collection":
|
95
95
|
db_operation = SemanticConvetion.DB_OPERATION_DELETE_COLLECTION
|
96
|
-
span.set_attribute(SemanticConvetion.
|
96
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_NAME,
|
97
97
|
SemanticConvetion.DB_OPERATION_DELETE_COLLECTION)
|
98
98
|
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
99
99
|
kwargs.get("collection_name", ""))
|
100
100
|
|
101
101
|
elif gen_ai_endpoint == "milvus.insert":
|
102
102
|
db_operation = SemanticConvetion.DB_OPERATION_ADD
|
103
|
-
span.set_attribute(SemanticConvetion.
|
103
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_NAME,
|
104
104
|
SemanticConvetion.DB_OPERATION_ADD)
|
105
105
|
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
106
106
|
kwargs.get("collection_name", ""))
|
@@ -111,7 +111,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
111
111
|
|
112
112
|
elif gen_ai_endpoint == "milvus.search":
|
113
113
|
db_operation = SemanticConvetion.DB_OPERATION_QUERY
|
114
|
-
span.set_attribute(SemanticConvetion.
|
114
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_NAME,
|
115
115
|
SemanticConvetion.DB_OPERATION_QUERY)
|
116
116
|
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
117
117
|
kwargs.get("collection_name", ""))
|
@@ -120,7 +120,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
120
120
|
|
121
121
|
elif gen_ai_endpoint in ["milvus.query", "milvus.get"]:
|
122
122
|
db_operation = SemanticConvetion.DB_OPERATION_QUERY
|
123
|
-
span.set_attribute(SemanticConvetion.
|
123
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_NAME,
|
124
124
|
SemanticConvetion.DB_OPERATION_QUERY)
|
125
125
|
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
126
126
|
kwargs.get("collection_name", ""))
|
@@ -129,7 +129,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
129
129
|
|
130
130
|
elif gen_ai_endpoint == "milvus.upsert":
|
131
131
|
db_operation = SemanticConvetion.DB_OPERATION_ADD
|
132
|
-
span.set_attribute(SemanticConvetion.
|
132
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_NAME,
|
133
133
|
SemanticConvetion.DB_OPERATION_UPSERT)
|
134
134
|
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
135
135
|
kwargs.get("collection_name", ""))
|
@@ -140,7 +140,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
140
140
|
|
141
141
|
elif gen_ai_endpoint == "milvus.delete":
|
142
142
|
db_operation = SemanticConvetion.DB_OPERATION_DELETE
|
143
|
-
span.set_attribute(SemanticConvetion.
|
143
|
+
span.set_attribute(SemanticConvetion.DB_OPERATION_NAME,
|
144
144
|
SemanticConvetion.DB_OPERATION_DELETE)
|
145
145
|
span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
|
146
146
|
kwargs.get("collection_name", ""))
|
@@ -155,13 +155,13 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
155
155
|
"openlit",
|
156
156
|
SERVICE_NAME:
|
157
157
|
application_name,
|
158
|
-
SemanticConvetion.
|
158
|
+
SemanticConvetion.DB_SYSTEM_NAME:
|
159
159
|
SemanticConvetion.DB_SYSTEM_MILVUS,
|
160
160
|
DEPLOYMENT_ENVIRONMENT:
|
161
161
|
environment,
|
162
162
|
SemanticConvetion.GEN_AI_OPERATION:
|
163
163
|
SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB,
|
164
|
-
SemanticConvetion.
|
164
|
+
SemanticConvetion.DB_OPERATION_NAME:
|
165
165
|
db_operation
|
166
166
|
}
|
167
167
|
|
@@ -5,11 +5,11 @@ import importlib.metadata
|
|
5
5
|
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
6
6
|
from wrapt import wrap_function_wrapper
|
7
7
|
|
8
|
-
from openlit.instrumentation.openai.openai import chat_completions, embedding
|
8
|
+
from openlit.instrumentation.openai.openai import chat_completions, embedding, responses
|
9
9
|
from openlit.instrumentation.openai.openai import image_generate, image_variatons, audio_create
|
10
10
|
from openlit.instrumentation.openai.async_openai import async_chat_completions, async_embedding
|
11
11
|
from openlit.instrumentation.openai.async_openai import async_image_generate, async_image_variatons
|
12
|
-
from openlit.instrumentation.openai.async_openai import async_audio_create
|
12
|
+
from openlit.instrumentation.openai.async_openai import async_audio_create, async_responses
|
13
13
|
|
14
14
|
_instruments = ("openai >= 1.1.1",)
|
15
15
|
|
@@ -45,6 +45,22 @@ class OpenAIInstrumentor(BaseInstrumentor):
|
|
45
45
|
metrics, disable_metrics),
|
46
46
|
)
|
47
47
|
|
48
|
+
wrap_function_wrapper(
|
49
|
+
"openai.resources.responses.responses",
|
50
|
+
"Responses.create",
|
51
|
+
responses(version, environment, application_name,
|
52
|
+
tracer, pricing_info, capture_message_content,
|
53
|
+
metrics, disable_metrics),
|
54
|
+
)
|
55
|
+
|
56
|
+
wrap_function_wrapper(
|
57
|
+
"openai.resources.responses.responses",
|
58
|
+
"AsyncResponses.create",
|
59
|
+
async_responses(version, environment, application_name,
|
60
|
+
tracer, pricing_info, capture_message_content,
|
61
|
+
metrics, disable_metrics),
|
62
|
+
)
|
63
|
+
|
48
64
|
wrap_function_wrapper(
|
49
65
|
"openai.resources.images",
|
50
66
|
"Images.generate",
|