openlit 1.34.26__py3-none-any.whl → 1.34.28__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/__helpers.py +38 -0
- openlit/__init__.py +22 -155
- openlit/_instrumentors.py +144 -0
- openlit/guard/all.py +3 -3
- openlit/instrumentation/astra/__init__.py +71 -159
- openlit/instrumentation/astra/astra.py +32 -22
- openlit/instrumentation/astra/async_astra.py +32 -22
- openlit/instrumentation/astra/utils.py +263 -88
- openlit/instrumentation/chroma/utils.py +2 -2
- openlit/instrumentation/controlflow/controlflow.py +2 -2
- openlit/instrumentation/embedchain/embedchain.py +4 -4
- openlit/instrumentation/groq/__init__.py +4 -4
- openlit/instrumentation/haystack/__init__.py +57 -28
- openlit/instrumentation/haystack/async_haystack.py +54 -0
- openlit/instrumentation/haystack/haystack.py +35 -65
- openlit/instrumentation/haystack/utils.py +377 -0
- openlit/instrumentation/julep/async_julep.py +2 -2
- openlit/instrumentation/julep/julep.py +2 -2
- openlit/instrumentation/langchain_community/utils.py +2 -2
- openlit/instrumentation/llamaindex/__init__.py +165 -37
- openlit/instrumentation/llamaindex/async_llamaindex.py +53 -0
- openlit/instrumentation/llamaindex/llamaindex.py +32 -64
- openlit/instrumentation/llamaindex/utils.py +412 -0
- openlit/instrumentation/mem0/mem0.py +2 -2
- openlit/instrumentation/milvus/__init__.py +30 -68
- openlit/instrumentation/milvus/milvus.py +34 -161
- openlit/instrumentation/milvus/utils.py +276 -0
- openlit/instrumentation/openai/__init__.py +24 -24
- openlit/instrumentation/openai/utils.py +10 -4
- openlit/instrumentation/pinecone/utils.py +2 -2
- openlit/instrumentation/qdrant/utils.py +2 -2
- openlit/instrumentation/together/__init__.py +8 -8
- openlit/semcov/__init__.py +79 -0
- {openlit-1.34.26.dist-info → openlit-1.34.28.dist-info}/METADATA +1 -1
- {openlit-1.34.26.dist-info → openlit-1.34.28.dist-info}/RECORD +37 -31
- {openlit-1.34.26.dist-info → openlit-1.34.28.dist-info}/LICENSE +0 -0
- {openlit-1.34.26.dist-info → openlit-1.34.28.dist-info}/WHEEL +0 -0
@@ -1,178 +1,90 @@
|
|
1
|
-
"""
|
1
|
+
"""
|
2
|
+
OpenLIT AstraDB Instrumentation
|
3
|
+
"""
|
4
|
+
|
2
5
|
from typing import Collection
|
3
6
|
import importlib.metadata
|
4
7
|
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
5
8
|
from wrapt import wrap_function_wrapper
|
6
9
|
|
7
10
|
from openlit.instrumentation.astra.astra import general_wrap
|
8
|
-
|
11
|
+
from openlit.instrumentation.astra.async_astra import async_general_wrap
|
12
|
+
|
13
|
+
_instruments = ("astrapy >= 1.5.2",)
|
14
|
+
|
15
|
+
# AstraDB sync operations
|
16
|
+
ASTRA_SYNC_OPERATIONS = [
|
17
|
+
# Database operations
|
18
|
+
("astrapy.database", "Database.create_collection", "astra.create_collection"),
|
19
|
+
("astrapy.database", "Database.drop_collection", "astra.drop_collection"),
|
20
|
+
|
21
|
+
# Collection operations
|
22
|
+
("astrapy.collection", "Collection.insert_one", "astra.insert_one"),
|
23
|
+
("astrapy.collection", "Collection.insert_many", "astra.insert_many"),
|
24
|
+
("astrapy.collection", "Collection.update_one", "astra.update_one"),
|
25
|
+
("astrapy.collection", "Collection.update_many", "astra.update_many"),
|
26
|
+
("astrapy.collection", "Collection.find_one_and_update", "astra.find_one_and_update"),
|
27
|
+
("astrapy.collection", "Collection.find", "astra.find"),
|
28
|
+
("astrapy.collection", "Collection.replace_one", "astra.replace_one"),
|
29
|
+
("astrapy.collection", "Collection.find_one_and_delete", "astra.find_one_and_delete"),
|
30
|
+
("astrapy.collection", "Collection.delete_one", "astra.delete_one"),
|
31
|
+
("astrapy.collection", "Collection.delete_many", "astra.delete_many"),
|
32
|
+
]
|
33
|
+
|
34
|
+
# AstraDB async operations
|
35
|
+
ASTRA_ASYNC_OPERATIONS = [
|
36
|
+
# Async Database operations
|
37
|
+
("astrapy.database", "AsyncDatabase.create_collection", "astra.create_collection"),
|
38
|
+
("astrapy.database", "AsyncDatabase.drop_collection", "astra.drop_collection"),
|
9
39
|
|
10
|
-
|
40
|
+
# Async Collection operations
|
41
|
+
("astrapy.collection", "AsyncCollection.insert_one", "astra.insert_one"),
|
42
|
+
("astrapy.collection", "AsyncCollection.insert_many", "astra.insert_many"),
|
43
|
+
("astrapy.collection", "AsyncCollection.update_one", "astra.update_one"),
|
44
|
+
("astrapy.collection", "AsyncCollection.update_many", "astra.update_many"),
|
45
|
+
("astrapy.collection", "AsyncCollection.find_one_and_update", "astra.find_one_and_update"),
|
46
|
+
("astrapy.collection", "AsyncCollection.find", "astra.find"),
|
47
|
+
("astrapy.collection", "AsyncCollection.replace_one", "astra.replace_one"),
|
48
|
+
("astrapy.collection", "AsyncCollection.find_one_and_delete", "astra.find_one_and_delete"),
|
49
|
+
("astrapy.collection", "AsyncCollection.delete_one", "astra.delete_one"),
|
50
|
+
("astrapy.collection", "AsyncCollection.delete_many", "astra.delete_many"),
|
51
|
+
]
|
11
52
|
|
12
53
|
class AstraInstrumentor(BaseInstrumentor):
|
13
|
-
"""
|
54
|
+
"""
|
55
|
+
An instrumentor for AstraDB's client library.
|
56
|
+
"""
|
14
57
|
|
15
58
|
def instrumentation_dependencies(self) -> Collection[str]:
|
16
59
|
return _instruments
|
17
60
|
|
18
61
|
def _instrument(self, **kwargs):
|
19
|
-
|
20
|
-
environment = kwargs.get(
|
21
|
-
|
22
|
-
|
23
|
-
pricing_info = kwargs.get(
|
24
|
-
capture_message_content = kwargs.get(
|
25
|
-
|
26
|
-
|
62
|
+
version = importlib.metadata.version("astrapy")
|
63
|
+
environment = kwargs.get("environment", "default")
|
64
|
+
application_name = kwargs.get("application_name", "default")
|
65
|
+
tracer = kwargs.get("tracer")
|
66
|
+
pricing_info = kwargs.get("pricing_info", {})
|
67
|
+
capture_message_content = kwargs.get("capture_message_content", False)
|
68
|
+
metrics = kwargs.get("metrics_dict")
|
69
|
+
disable_metrics = kwargs.get("disable_metrics")
|
27
70
|
|
28
|
-
#
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
'astrapy.database',
|
37
|
-
'Database.drop_collection',
|
38
|
-
general_wrap('astra.drop_collection', version, environment, application_name,
|
39
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
40
|
-
)
|
41
|
-
wrap_function_wrapper(
|
42
|
-
'astrapy.collection',
|
43
|
-
'Collection.insert_one',
|
44
|
-
general_wrap('astra.insert', version, environment, application_name,
|
45
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
46
|
-
)
|
47
|
-
wrap_function_wrapper(
|
48
|
-
'astrapy.collection',
|
49
|
-
'Collection.insert_many',
|
50
|
-
general_wrap('astra.insert', version, environment, application_name,
|
51
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
52
|
-
)
|
53
|
-
wrap_function_wrapper(
|
54
|
-
'astrapy.collection',
|
55
|
-
'Collection.update_one',
|
56
|
-
general_wrap('astra.update', version, environment, application_name,
|
57
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
58
|
-
)
|
59
|
-
wrap_function_wrapper(
|
60
|
-
'astrapy.collection',
|
61
|
-
'Collection.update_many',
|
62
|
-
general_wrap('astra.update', version, environment, application_name,
|
63
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
64
|
-
)
|
65
|
-
wrap_function_wrapper(
|
66
|
-
'astrapy.collection',
|
67
|
-
'Collection.find_one_and_update',
|
68
|
-
general_wrap('astra.find_one_and_update', version, environment, application_name,
|
69
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
70
|
-
)
|
71
|
-
wrap_function_wrapper(
|
72
|
-
'astrapy.collection',
|
73
|
-
'Collection.find',
|
74
|
-
general_wrap('astra.find', version, environment, application_name,
|
75
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
76
|
-
)
|
77
|
-
wrap_function_wrapper(
|
78
|
-
'astrapy.collection',
|
79
|
-
'Collection.replace_one',
|
80
|
-
general_wrap('astra.replace_one', version, environment, application_name,
|
81
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
82
|
-
)
|
83
|
-
wrap_function_wrapper(
|
84
|
-
'astrapy.collection',
|
85
|
-
'Collection.find_one_and_delete',
|
86
|
-
general_wrap('astra.find_one_and_delete', version, environment, application_name,
|
87
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
88
|
-
)
|
89
|
-
wrap_function_wrapper(
|
90
|
-
'astrapy.collection',
|
91
|
-
'Collection.delete_one',
|
92
|
-
general_wrap('astra.delete', version, environment, application_name,
|
93
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
94
|
-
)
|
95
|
-
wrap_function_wrapper(
|
96
|
-
'astrapy.collection',
|
97
|
-
'Collection.delete_many',
|
98
|
-
general_wrap('astra.delete', version, environment, application_name,
|
99
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
100
|
-
)
|
71
|
+
# Wrap sync operations
|
72
|
+
for module, class_method, endpoint in ASTRA_SYNC_OPERATIONS:
|
73
|
+
wrap_function_wrapper(
|
74
|
+
module,
|
75
|
+
class_method,
|
76
|
+
general_wrap(endpoint, version, environment, application_name,
|
77
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
78
|
+
)
|
101
79
|
|
102
|
-
#
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
'astrapy.database',
|
111
|
-
'AsyncDatabase.drop_collection',
|
112
|
-
general_wrap('astra.drop_collection', version, environment, application_name,
|
113
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
114
|
-
)
|
115
|
-
wrap_function_wrapper(
|
116
|
-
'astrapy.collection',
|
117
|
-
'AsyncCollection.insert_one',
|
118
|
-
general_wrap('astra.insert_one', version, environment, application_name,
|
119
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
120
|
-
)
|
121
|
-
wrap_function_wrapper(
|
122
|
-
'astrapy.collection',
|
123
|
-
'AsyncCollection.insert_many',
|
124
|
-
general_wrap('astra.insert_many', version, environment, application_name,
|
125
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
126
|
-
)
|
127
|
-
wrap_function_wrapper(
|
128
|
-
'astrapy.collection',
|
129
|
-
'AsyncCollection.update_one',
|
130
|
-
general_wrap('astra.update_one', version, environment, application_name,
|
131
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
132
|
-
)
|
133
|
-
wrap_function_wrapper(
|
134
|
-
'astrapy.collection',
|
135
|
-
'AsyncCollection.update_many',
|
136
|
-
general_wrap('astra.update_many', version, environment, application_name,
|
137
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
138
|
-
)
|
139
|
-
wrap_function_wrapper(
|
140
|
-
'astrapy.collection',
|
141
|
-
'AsyncCollection.find_one_and_update',
|
142
|
-
general_wrap('astra.find_one_and_update', version, environment, application_name,
|
143
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
144
|
-
)
|
145
|
-
wrap_function_wrapper(
|
146
|
-
'astrapy.collection',
|
147
|
-
'AsyncCollection.find',
|
148
|
-
general_wrap('astra.find', version, environment, application_name,
|
149
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
150
|
-
)
|
151
|
-
wrap_function_wrapper(
|
152
|
-
'astrapy.collection',
|
153
|
-
'AsyncCollection.replace_one',
|
154
|
-
general_wrap('astra.replace_one', version, environment, application_name,
|
155
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
156
|
-
)
|
157
|
-
wrap_function_wrapper(
|
158
|
-
'astrapy.collection',
|
159
|
-
'AsyncCollection.find_one_and_delete',
|
160
|
-
general_wrap('astra.find_one_and_delete', version, environment, application_name,
|
161
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
162
|
-
)
|
163
|
-
wrap_function_wrapper(
|
164
|
-
'astrapy.collection',
|
165
|
-
'AsyncCollection.delete_one',
|
166
|
-
general_wrap('astra.delete_one', version, environment, application_name,
|
167
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
168
|
-
)
|
169
|
-
wrap_function_wrapper(
|
170
|
-
'astrapy.collection',
|
171
|
-
'AsyncCollection.delete_many',
|
172
|
-
general_wrap('astra.delete_many', version, environment, application_name,
|
173
|
-
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
174
|
-
)
|
80
|
+
# Wrap async operations
|
81
|
+
for module, class_method, endpoint in ASTRA_ASYNC_OPERATIONS:
|
82
|
+
wrap_function_wrapper(
|
83
|
+
module,
|
84
|
+
class_method,
|
85
|
+
async_general_wrap(endpoint, version, environment, application_name,
|
86
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
87
|
+
)
|
175
88
|
|
176
89
|
def _uninstrument(self, **kwargs):
|
177
|
-
# Proper uninstrumentation logic to revert patched methods
|
178
90
|
pass
|
@@ -1,44 +1,54 @@
|
|
1
1
|
"""
|
2
|
-
Module for monitoring AstraDB.
|
2
|
+
Module for monitoring AstraDB API calls.
|
3
3
|
"""
|
4
4
|
|
5
5
|
import time
|
6
6
|
from opentelemetry.trace import SpanKind
|
7
|
+
from opentelemetry import context as context_api
|
8
|
+
from openlit.__helpers import handle_exception
|
7
9
|
from openlit.instrumentation.astra.utils import (
|
10
|
+
process_astra_response,
|
8
11
|
DB_OPERATION_MAP,
|
9
|
-
|
12
|
+
set_server_address_and_port,
|
10
13
|
)
|
11
|
-
from openlit.semcov import SemanticConvention
|
12
14
|
|
13
15
|
def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
14
|
-
|
16
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics):
|
15
17
|
"""
|
16
|
-
Generates a telemetry wrapper for
|
18
|
+
Generates a telemetry wrapper for AstraDB function calls.
|
17
19
|
"""
|
18
|
-
|
19
20
|
def wrapper(wrapped, instance, args, kwargs):
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
# CRITICAL: Suppression check
|
22
|
+
if context_api.get_value(context_api._SUPPRESS_INSTRUMENTATION_KEY):
|
23
|
+
return wrapped(*args, **kwargs)
|
24
|
+
|
25
|
+
# Get server address and port using the standard helper
|
26
|
+
server_address, server_port = set_server_address_and_port(instance)
|
27
|
+
|
28
|
+
db_operation = DB_OPERATION_MAP.get(gen_ai_endpoint, "unknown")
|
23
29
|
|
24
|
-
|
25
|
-
if db_operation ==
|
26
|
-
db_operation =
|
30
|
+
# Handle upsert detection for replace operations
|
31
|
+
if db_operation == "DB_OPERATION_REPLACE" and kwargs.get("upsert"):
|
32
|
+
db_operation = "DB_OPERATION_UPSERT"
|
27
33
|
|
28
|
-
|
34
|
+
# Get collection name for span naming
|
35
|
+
collection_name = getattr(instance, "name", "unknown")
|
36
|
+
span_name = f"{db_operation} {collection_name}"
|
29
37
|
|
30
38
|
with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
|
31
39
|
start_time = time.time()
|
32
40
|
response = wrapped(*args, **kwargs)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
|
42
|
+
try:
|
43
|
+
# Process response and generate telemetry
|
44
|
+
response = process_astra_response(
|
45
|
+
response, db_operation, server_address, server_port,
|
46
|
+
environment, application_name, metrics, start_time, span,
|
47
|
+
capture_message_content, disable_metrics, version, instance, args, **kwargs
|
48
|
+
)
|
49
|
+
|
50
|
+
except Exception as e:
|
51
|
+
handle_exception(span, e)
|
42
52
|
|
43
53
|
return response
|
44
54
|
|
@@ -1,44 +1,54 @@
|
|
1
1
|
"""
|
2
|
-
Module for monitoring AstraDB.
|
2
|
+
Module for monitoring AstraDB async API calls.
|
3
3
|
"""
|
4
4
|
|
5
5
|
import time
|
6
6
|
from opentelemetry.trace import SpanKind
|
7
|
+
from opentelemetry import context as context_api
|
8
|
+
from openlit.__helpers import handle_exception
|
7
9
|
from openlit.instrumentation.astra.utils import (
|
10
|
+
process_astra_response,
|
8
11
|
DB_OPERATION_MAP,
|
9
|
-
|
12
|
+
set_server_address_and_port,
|
10
13
|
)
|
11
|
-
from openlit.semcov import SemanticConvention
|
12
14
|
|
13
15
|
def async_general_wrap(gen_ai_endpoint, version, environment, application_name,
|
14
|
-
|
16
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics):
|
15
17
|
"""
|
16
|
-
Generates a telemetry wrapper for
|
18
|
+
Generates a telemetry wrapper for AstraDB async function calls.
|
17
19
|
"""
|
18
|
-
|
19
20
|
async def wrapper(wrapped, instance, args, kwargs):
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
# CRITICAL: Suppression check
|
22
|
+
if context_api.get_value(context_api._SUPPRESS_INSTRUMENTATION_KEY):
|
23
|
+
return wrapped(*args, **kwargs)
|
24
|
+
|
25
|
+
# Get server address and port using the standard helper
|
26
|
+
server_address, server_port = set_server_address_and_port(instance)
|
27
|
+
|
28
|
+
db_operation = DB_OPERATION_MAP.get(gen_ai_endpoint, "unknown")
|
23
29
|
|
24
|
-
|
25
|
-
if db_operation ==
|
26
|
-
db_operation =
|
30
|
+
# Handle upsert detection for replace operations
|
31
|
+
if db_operation == "DB_OPERATION_REPLACE" and kwargs.get("upsert"):
|
32
|
+
db_operation = "DB_OPERATION_UPSERT"
|
27
33
|
|
28
|
-
|
34
|
+
# Get collection name for span naming
|
35
|
+
collection_name = getattr(instance, "name", "unknown")
|
36
|
+
span_name = f"{db_operation} {collection_name}"
|
29
37
|
|
30
38
|
with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
|
31
39
|
start_time = time.time()
|
32
40
|
response = await wrapped(*args, **kwargs)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
|
42
|
+
try:
|
43
|
+
# Process response and generate telemetry
|
44
|
+
response = process_astra_response(
|
45
|
+
response, db_operation, server_address, server_port,
|
46
|
+
environment, application_name, metrics, start_time, span,
|
47
|
+
capture_message_content, disable_metrics, version, instance, args, **kwargs
|
48
|
+
)
|
49
|
+
|
50
|
+
except Exception as e:
|
51
|
+
handle_exception(span, e)
|
42
52
|
|
43
53
|
return response
|
44
54
|
|