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
openlit/__init__.py
CHANGED
@@ -65,6 +65,7 @@ from openlit.instrumentation.controlflow import ControlFlowInstrumentor
|
|
65
65
|
from openlit.instrumentation.crawl4ai import Crawl4AIInstrumentor
|
66
66
|
from openlit.instrumentation.firecrawl import FireCrawlInstrumentor
|
67
67
|
from openlit.instrumentation.letta import LettaInstrumentor
|
68
|
+
from openlit.instrumentation.openai_agents import OpenAIAgentsInstrumentor
|
68
69
|
from openlit.instrumentation.gpu import GPUInstrumentor
|
69
70
|
import openlit.guard
|
70
71
|
import openlit.evals
|
@@ -293,6 +294,7 @@ def init(
|
|
293
294
|
"firecrawl": "firecrawl",
|
294
295
|
"letta": "letta",
|
295
296
|
"together": "together",
|
297
|
+
"openai-agents": "agents"
|
296
298
|
}
|
297
299
|
|
298
300
|
invalid_instrumentors = [
|
@@ -411,6 +413,7 @@ def init(
|
|
411
413
|
"firecrawl": FireCrawlInstrumentor(),
|
412
414
|
"letta": LettaInstrumentor(),
|
413
415
|
"together": TogetherInstrumentor(),
|
416
|
+
"openai-agents": OpenAIAgentsInstrumentor(),
|
414
417
|
}
|
415
418
|
|
416
419
|
# Initialize and instrument only the enabled instrumentors
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
|
2
1
|
"""Initializer of Auto Instrumentation of AstraDB Functions"""
|
3
2
|
from typing import Collection
|
4
3
|
import importlib.metadata
|
@@ -8,7 +7,7 @@ from wrapt import wrap_function_wrapper
|
|
8
7
|
from openlit.instrumentation.astra.astra import general_wrap
|
9
8
|
# from openlit.instrumentation.astra.async_astra import asyc_general_wrap
|
10
9
|
|
11
|
-
_instruments = (
|
10
|
+
_instruments = ('astrapy >= 1.5.2',)
|
12
11
|
|
13
12
|
class AstraInstrumentor(BaseInstrumentor):
|
14
13
|
"""An instrumentor for AstraDB's client library."""
|
@@ -17,163 +16,163 @@ class AstraInstrumentor(BaseInstrumentor):
|
|
17
16
|
return _instruments
|
18
17
|
|
19
18
|
def _instrument(self, **kwargs):
|
20
|
-
application_name = kwargs.get(
|
21
|
-
environment = kwargs.get(
|
22
|
-
tracer = kwargs.get(
|
23
|
-
metrics = kwargs.get(
|
24
|
-
pricing_info = kwargs.get(
|
25
|
-
capture_message_content = kwargs.get(
|
26
|
-
disable_metrics = kwargs.get(
|
27
|
-
version = importlib.metadata.version(
|
19
|
+
application_name = kwargs.get('application_name')
|
20
|
+
environment = kwargs.get('environment')
|
21
|
+
tracer = kwargs.get('tracer')
|
22
|
+
metrics = kwargs.get('metrics_dict')
|
23
|
+
pricing_info = kwargs.get('pricing_info')
|
24
|
+
capture_message_content = kwargs.get('capture_message_content')
|
25
|
+
disable_metrics = kwargs.get('disable_metrics')
|
26
|
+
version = importlib.metadata.version('astrapy')
|
28
27
|
|
29
28
|
# Sync
|
30
29
|
wrap_function_wrapper(
|
31
|
-
|
32
|
-
|
33
|
-
general_wrap(
|
30
|
+
'astrapy.database',
|
31
|
+
'Database.create_collection',
|
32
|
+
general_wrap('astra.create_collection', version, environment, application_name,
|
34
33
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
35
34
|
)
|
36
35
|
wrap_function_wrapper(
|
37
|
-
|
38
|
-
|
39
|
-
general_wrap(
|
36
|
+
'astrapy.database',
|
37
|
+
'Database.drop_collection',
|
38
|
+
general_wrap('astra.drop_collection', version, environment, application_name,
|
40
39
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
41
40
|
)
|
42
41
|
wrap_function_wrapper(
|
43
|
-
|
44
|
-
|
45
|
-
general_wrap(
|
42
|
+
'astrapy.collection',
|
43
|
+
'Collection.insert_one',
|
44
|
+
general_wrap('astra.insert', version, environment, application_name,
|
46
45
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
47
46
|
)
|
48
47
|
wrap_function_wrapper(
|
49
|
-
|
50
|
-
|
51
|
-
general_wrap(
|
48
|
+
'astrapy.collection',
|
49
|
+
'Collection.insert_many',
|
50
|
+
general_wrap('astra.insert', version, environment, application_name,
|
52
51
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
53
52
|
)
|
54
53
|
wrap_function_wrapper(
|
55
|
-
|
56
|
-
|
57
|
-
general_wrap(
|
54
|
+
'astrapy.collection',
|
55
|
+
'Collection.update_one',
|
56
|
+
general_wrap('astra.update', version, environment, application_name,
|
58
57
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
59
58
|
)
|
60
59
|
wrap_function_wrapper(
|
61
|
-
|
62
|
-
|
63
|
-
general_wrap(
|
60
|
+
'astrapy.collection',
|
61
|
+
'Collection.update_many',
|
62
|
+
general_wrap('astra.update', version, environment, application_name,
|
64
63
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
65
64
|
)
|
66
65
|
wrap_function_wrapper(
|
67
|
-
|
68
|
-
|
69
|
-
general_wrap(
|
66
|
+
'astrapy.collection',
|
67
|
+
'Collection.find_one_and_update',
|
68
|
+
general_wrap('astra.find_one_and_update', version, environment, application_name,
|
70
69
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
71
70
|
)
|
72
71
|
wrap_function_wrapper(
|
73
|
-
|
74
|
-
|
75
|
-
general_wrap(
|
72
|
+
'astrapy.collection',
|
73
|
+
'Collection.find',
|
74
|
+
general_wrap('astra.find', version, environment, application_name,
|
76
75
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
77
76
|
)
|
78
77
|
wrap_function_wrapper(
|
79
|
-
|
80
|
-
|
81
|
-
general_wrap(
|
78
|
+
'astrapy.collection',
|
79
|
+
'Collection.replace_one',
|
80
|
+
general_wrap('astra.replace_one', version, environment, application_name,
|
82
81
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
83
82
|
)
|
84
83
|
wrap_function_wrapper(
|
85
|
-
|
86
|
-
|
87
|
-
general_wrap(
|
84
|
+
'astrapy.collection',
|
85
|
+
'Collection.find_one_and_delete',
|
86
|
+
general_wrap('astra.find_one_and_delete', version, environment, application_name,
|
88
87
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
89
88
|
)
|
90
89
|
wrap_function_wrapper(
|
91
|
-
|
92
|
-
|
93
|
-
general_wrap(
|
90
|
+
'astrapy.collection',
|
91
|
+
'Collection.delete_one',
|
92
|
+
general_wrap('astra.delete', version, environment, application_name,
|
94
93
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
95
94
|
)
|
96
95
|
wrap_function_wrapper(
|
97
|
-
|
98
|
-
|
99
|
-
general_wrap(
|
96
|
+
'astrapy.collection',
|
97
|
+
'Collection.delete_many',
|
98
|
+
general_wrap('astra.delete', version, environment, application_name,
|
100
99
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
101
100
|
)
|
102
101
|
|
103
102
|
# ASync
|
104
103
|
wrap_function_wrapper(
|
105
|
-
|
106
|
-
|
107
|
-
general_wrap(
|
104
|
+
'astrapy.database',
|
105
|
+
'AsyncDatabase.create_collection',
|
106
|
+
general_wrap('astra.create_collection', version, environment, application_name,
|
108
107
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
109
108
|
)
|
110
109
|
wrap_function_wrapper(
|
111
|
-
|
112
|
-
|
113
|
-
general_wrap(
|
110
|
+
'astrapy.database',
|
111
|
+
'AsyncDatabase.drop_collection',
|
112
|
+
general_wrap('astra.drop_collection', version, environment, application_name,
|
114
113
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
115
114
|
)
|
116
115
|
wrap_function_wrapper(
|
117
|
-
|
118
|
-
|
119
|
-
general_wrap(
|
116
|
+
'astrapy.collection',
|
117
|
+
'AsyncCollection.insert_one',
|
118
|
+
general_wrap('astra.insert_one', version, environment, application_name,
|
120
119
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
121
120
|
)
|
122
121
|
wrap_function_wrapper(
|
123
|
-
|
124
|
-
|
125
|
-
general_wrap(
|
122
|
+
'astrapy.collection',
|
123
|
+
'AsyncCollection.insert_many',
|
124
|
+
general_wrap('astra.insert_many', version, environment, application_name,
|
126
125
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
127
126
|
)
|
128
127
|
wrap_function_wrapper(
|
129
|
-
|
130
|
-
|
131
|
-
general_wrap(
|
128
|
+
'astrapy.collection',
|
129
|
+
'AsyncCollection.update_one',
|
130
|
+
general_wrap('astra.update_one', version, environment, application_name,
|
132
131
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
133
132
|
)
|
134
133
|
wrap_function_wrapper(
|
135
|
-
|
136
|
-
|
137
|
-
general_wrap(
|
134
|
+
'astrapy.collection',
|
135
|
+
'AsyncCollection.update_many',
|
136
|
+
general_wrap('astra.update_many', version, environment, application_name,
|
138
137
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
139
138
|
)
|
140
139
|
wrap_function_wrapper(
|
141
|
-
|
142
|
-
|
143
|
-
general_wrap(
|
140
|
+
'astrapy.collection',
|
141
|
+
'AsyncCollection.find_one_and_update',
|
142
|
+
general_wrap('astra.find_one_and_update', version, environment, application_name,
|
144
143
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
145
144
|
)
|
146
145
|
wrap_function_wrapper(
|
147
|
-
|
148
|
-
|
149
|
-
general_wrap(
|
146
|
+
'astrapy.collection',
|
147
|
+
'AsyncCollection.find',
|
148
|
+
general_wrap('astra.find', version, environment, application_name,
|
150
149
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
151
150
|
)
|
152
151
|
wrap_function_wrapper(
|
153
|
-
|
154
|
-
|
155
|
-
general_wrap(
|
152
|
+
'astrapy.collection',
|
153
|
+
'AsyncCollection.replace_one',
|
154
|
+
general_wrap('astra.replace_one', version, environment, application_name,
|
156
155
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
157
156
|
)
|
158
157
|
wrap_function_wrapper(
|
159
|
-
|
160
|
-
|
161
|
-
general_wrap(
|
158
|
+
'astrapy.collection',
|
159
|
+
'AsyncCollection.find_one_and_delete',
|
160
|
+
general_wrap('astra.find_one_and_delete', version, environment, application_name,
|
162
161
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
163
162
|
)
|
164
163
|
wrap_function_wrapper(
|
165
|
-
|
166
|
-
|
167
|
-
general_wrap(
|
164
|
+
'astrapy.collection',
|
165
|
+
'AsyncCollection.delete_one',
|
166
|
+
general_wrap('astra.delete_one', version, environment, application_name,
|
168
167
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
169
168
|
)
|
170
169
|
wrap_function_wrapper(
|
171
|
-
|
172
|
-
|
173
|
-
general_wrap(
|
170
|
+
'astrapy.collection',
|
171
|
+
'AsyncCollection.delete_many',
|
172
|
+
general_wrap('astra.delete_many', version, environment, application_name,
|
174
173
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
175
174
|
)
|
176
175
|
|
177
|
-
@staticmethod
|
178
176
|
def _uninstrument(self, **kwargs):
|
177
|
+
# Proper uninstrumentation logic to revert patched methods
|
179
178
|
pass
|
@@ -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
|
-
# 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
|
-
|
20
|
-
return len(obj) if obj else None
|
21
|
-
|
22
13
|
def 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
|
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 = 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
|