openlit 1.34.30__py3-none-any.whl → 1.34.31__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 +235 -86
- openlit/__init__.py +16 -13
- openlit/_instrumentors.py +2 -1
- openlit/evals/all.py +50 -21
- openlit/evals/bias_detection.py +47 -20
- openlit/evals/hallucination.py +53 -22
- openlit/evals/toxicity.py +50 -21
- openlit/evals/utils.py +54 -30
- openlit/guard/all.py +61 -19
- openlit/guard/prompt_injection.py +34 -14
- openlit/guard/restrict_topic.py +46 -15
- openlit/guard/sensitive_topic.py +34 -14
- openlit/guard/utils.py +58 -22
- openlit/instrumentation/ag2/__init__.py +24 -8
- openlit/instrumentation/ag2/ag2.py +34 -13
- openlit/instrumentation/ag2/async_ag2.py +34 -13
- openlit/instrumentation/ag2/utils.py +133 -30
- openlit/instrumentation/ai21/__init__.py +43 -14
- openlit/instrumentation/ai21/ai21.py +47 -21
- openlit/instrumentation/ai21/async_ai21.py +47 -21
- openlit/instrumentation/ai21/utils.py +299 -78
- openlit/instrumentation/anthropic/__init__.py +21 -4
- openlit/instrumentation/anthropic/anthropic.py +28 -17
- openlit/instrumentation/anthropic/async_anthropic.py +28 -17
- openlit/instrumentation/anthropic/utils.py +145 -35
- openlit/instrumentation/assemblyai/__init__.py +11 -2
- openlit/instrumentation/assemblyai/assemblyai.py +15 -4
- openlit/instrumentation/assemblyai/utils.py +120 -25
- openlit/instrumentation/astra/__init__.py +43 -10
- openlit/instrumentation/astra/astra.py +28 -5
- openlit/instrumentation/astra/async_astra.py +28 -5
- openlit/instrumentation/astra/utils.py +151 -55
- openlit/instrumentation/azure_ai_inference/__init__.py +43 -10
- openlit/instrumentation/azure_ai_inference/async_azure_ai_inference.py +53 -21
- openlit/instrumentation/azure_ai_inference/azure_ai_inference.py +53 -21
- openlit/instrumentation/azure_ai_inference/utils.py +307 -83
- openlit/instrumentation/bedrock/__init__.py +21 -4
- openlit/instrumentation/bedrock/bedrock.py +63 -25
- openlit/instrumentation/bedrock/utils.py +139 -30
- openlit/instrumentation/chroma/__init__.py +89 -16
- openlit/instrumentation/chroma/chroma.py +28 -6
- openlit/instrumentation/chroma/utils.py +167 -51
- openlit/instrumentation/cohere/__init__.py +63 -18
- openlit/instrumentation/cohere/async_cohere.py +63 -24
- openlit/instrumentation/cohere/cohere.py +63 -24
- openlit/instrumentation/cohere/utils.py +286 -73
- openlit/instrumentation/controlflow/__init__.py +35 -9
- openlit/instrumentation/controlflow/controlflow.py +66 -33
- openlit/instrumentation/crawl4ai/__init__.py +25 -10
- openlit/instrumentation/crawl4ai/async_crawl4ai.py +78 -31
- openlit/instrumentation/crawl4ai/crawl4ai.py +78 -31
- openlit/instrumentation/crewai/__init__.py +40 -15
- openlit/instrumentation/crewai/async_crewai.py +32 -7
- openlit/instrumentation/crewai/crewai.py +32 -7
- openlit/instrumentation/crewai/utils.py +159 -56
- openlit/instrumentation/dynamiq/__init__.py +46 -12
- openlit/instrumentation/dynamiq/dynamiq.py +74 -33
- openlit/instrumentation/elevenlabs/__init__.py +23 -4
- openlit/instrumentation/elevenlabs/async_elevenlabs.py +16 -4
- openlit/instrumentation/elevenlabs/elevenlabs.py +16 -4
- openlit/instrumentation/elevenlabs/utils.py +128 -25
- openlit/instrumentation/embedchain/__init__.py +11 -2
- openlit/instrumentation/embedchain/embedchain.py +68 -35
- openlit/instrumentation/firecrawl/__init__.py +24 -7
- openlit/instrumentation/firecrawl/firecrawl.py +46 -20
- openlit/instrumentation/google_ai_studio/__init__.py +45 -10
- openlit/instrumentation/google_ai_studio/async_google_ai_studio.py +67 -44
- openlit/instrumentation/google_ai_studio/google_ai_studio.py +67 -44
- openlit/instrumentation/google_ai_studio/utils.py +180 -67
- openlit/instrumentation/gpt4all/__init__.py +22 -7
- openlit/instrumentation/gpt4all/gpt4all.py +67 -29
- openlit/instrumentation/gpt4all/utils.py +285 -61
- openlit/instrumentation/gpu/__init__.py +128 -47
- openlit/instrumentation/groq/__init__.py +21 -4
- openlit/instrumentation/groq/async_groq.py +33 -21
- openlit/instrumentation/groq/groq.py +33 -21
- openlit/instrumentation/groq/utils.py +192 -55
- openlit/instrumentation/haystack/__init__.py +70 -24
- openlit/instrumentation/haystack/async_haystack.py +28 -6
- openlit/instrumentation/haystack/haystack.py +28 -6
- openlit/instrumentation/haystack/utils.py +196 -74
- openlit/instrumentation/julep/__init__.py +69 -19
- openlit/instrumentation/julep/async_julep.py +53 -27
- openlit/instrumentation/julep/julep.py +53 -28
- openlit/instrumentation/langchain/__init__.py +74 -63
- openlit/instrumentation/langchain/callback_handler.py +1100 -0
- openlit/instrumentation/langchain_community/__init__.py +13 -2
- openlit/instrumentation/langchain_community/async_langchain_community.py +23 -5
- openlit/instrumentation/langchain_community/langchain_community.py +23 -5
- openlit/instrumentation/langchain_community/utils.py +35 -9
- openlit/instrumentation/letta/__init__.py +68 -15
- openlit/instrumentation/letta/letta.py +99 -54
- openlit/instrumentation/litellm/__init__.py +43 -14
- openlit/instrumentation/litellm/async_litellm.py +51 -26
- openlit/instrumentation/litellm/litellm.py +51 -26
- openlit/instrumentation/litellm/utils.py +304 -102
- openlit/instrumentation/llamaindex/__init__.py +267 -90
- openlit/instrumentation/llamaindex/async_llamaindex.py +28 -6
- openlit/instrumentation/llamaindex/llamaindex.py +28 -6
- openlit/instrumentation/llamaindex/utils.py +204 -91
- openlit/instrumentation/mem0/__init__.py +11 -2
- openlit/instrumentation/mem0/mem0.py +50 -29
- openlit/instrumentation/milvus/__init__.py +10 -2
- openlit/instrumentation/milvus/milvus.py +31 -6
- openlit/instrumentation/milvus/utils.py +166 -67
- openlit/instrumentation/mistral/__init__.py +63 -18
- openlit/instrumentation/mistral/async_mistral.py +63 -24
- openlit/instrumentation/mistral/mistral.py +63 -24
- openlit/instrumentation/mistral/utils.py +277 -69
- openlit/instrumentation/multion/__init__.py +69 -19
- openlit/instrumentation/multion/async_multion.py +57 -26
- openlit/instrumentation/multion/multion.py +57 -26
- openlit/instrumentation/ollama/__init__.py +39 -18
- openlit/instrumentation/ollama/async_ollama.py +57 -26
- openlit/instrumentation/ollama/ollama.py +57 -26
- openlit/instrumentation/ollama/utils.py +226 -50
- openlit/instrumentation/openai/__init__.py +156 -32
- openlit/instrumentation/openai/async_openai.py +147 -67
- openlit/instrumentation/openai/openai.py +150 -67
- openlit/instrumentation/openai/utils.py +657 -185
- openlit/instrumentation/openai_agents/__init__.py +5 -1
- openlit/instrumentation/openai_agents/processor.py +110 -90
- openlit/instrumentation/phidata/__init__.py +13 -5
- openlit/instrumentation/phidata/phidata.py +67 -32
- openlit/instrumentation/pinecone/__init__.py +48 -9
- openlit/instrumentation/pinecone/async_pinecone.py +27 -5
- openlit/instrumentation/pinecone/pinecone.py +27 -5
- openlit/instrumentation/pinecone/utils.py +153 -47
- openlit/instrumentation/premai/__init__.py +22 -7
- openlit/instrumentation/premai/premai.py +51 -26
- openlit/instrumentation/premai/utils.py +246 -59
- openlit/instrumentation/pydantic_ai/__init__.py +49 -22
- openlit/instrumentation/pydantic_ai/pydantic_ai.py +69 -16
- openlit/instrumentation/pydantic_ai/utils.py +89 -24
- openlit/instrumentation/qdrant/__init__.py +19 -4
- openlit/instrumentation/qdrant/async_qdrant.py +33 -7
- openlit/instrumentation/qdrant/qdrant.py +33 -7
- openlit/instrumentation/qdrant/utils.py +228 -93
- openlit/instrumentation/reka/__init__.py +23 -10
- openlit/instrumentation/reka/async_reka.py +17 -11
- openlit/instrumentation/reka/reka.py +17 -11
- openlit/instrumentation/reka/utils.py +138 -36
- openlit/instrumentation/together/__init__.py +44 -12
- openlit/instrumentation/together/async_together.py +50 -27
- openlit/instrumentation/together/together.py +50 -27
- openlit/instrumentation/together/utils.py +301 -71
- openlit/instrumentation/transformers/__init__.py +2 -1
- openlit/instrumentation/transformers/transformers.py +13 -3
- openlit/instrumentation/transformers/utils.py +139 -36
- openlit/instrumentation/vertexai/__init__.py +81 -16
- openlit/instrumentation/vertexai/async_vertexai.py +33 -15
- openlit/instrumentation/vertexai/utils.py +123 -27
- openlit/instrumentation/vertexai/vertexai.py +33 -15
- openlit/instrumentation/vllm/__init__.py +12 -5
- openlit/instrumentation/vllm/utils.py +121 -31
- openlit/instrumentation/vllm/vllm.py +16 -10
- openlit/otel/events.py +35 -10
- openlit/otel/metrics.py +32 -24
- openlit/otel/tracing.py +24 -9
- openlit/semcov/__init__.py +72 -6
- {openlit-1.34.30.dist-info → openlit-1.34.31.dist-info}/METADATA +2 -1
- openlit-1.34.31.dist-info/RECORD +166 -0
- openlit/instrumentation/langchain/async_langchain.py +0 -102
- openlit/instrumentation/langchain/langchain.py +0 -102
- openlit/instrumentation/langchain/utils.py +0 -252
- openlit-1.34.30.dist-info/RECORD +0 -168
- {openlit-1.34.30.dist-info → openlit-1.34.31.dist-info}/LICENSE +0 -0
- {openlit-1.34.30.dist-info → openlit-1.34.31.dist-info}/WHEEL +0 -0
@@ -17,16 +17,23 @@ ASTRA_SYNC_OPERATIONS = [
|
|
17
17
|
# Database operations
|
18
18
|
("astrapy.database", "Database.create_collection", "astra.create_collection"),
|
19
19
|
("astrapy.database", "Database.drop_collection", "astra.drop_collection"),
|
20
|
-
|
21
20
|
# Collection operations
|
22
21
|
("astrapy.collection", "Collection.insert_one", "astra.insert_one"),
|
23
22
|
("astrapy.collection", "Collection.insert_many", "astra.insert_many"),
|
24
23
|
("astrapy.collection", "Collection.update_one", "astra.update_one"),
|
25
24
|
("astrapy.collection", "Collection.update_many", "astra.update_many"),
|
26
|
-
(
|
25
|
+
(
|
26
|
+
"astrapy.collection",
|
27
|
+
"Collection.find_one_and_update",
|
28
|
+
"astra.find_one_and_update",
|
29
|
+
),
|
27
30
|
("astrapy.collection", "Collection.find", "astra.find"),
|
28
31
|
("astrapy.collection", "Collection.replace_one", "astra.replace_one"),
|
29
|
-
(
|
32
|
+
(
|
33
|
+
"astrapy.collection",
|
34
|
+
"Collection.find_one_and_delete",
|
35
|
+
"astra.find_one_and_delete",
|
36
|
+
),
|
30
37
|
("astrapy.collection", "Collection.delete_one", "astra.delete_one"),
|
31
38
|
("astrapy.collection", "Collection.delete_many", "astra.delete_many"),
|
32
39
|
]
|
@@ -36,20 +43,28 @@ ASTRA_ASYNC_OPERATIONS = [
|
|
36
43
|
# Async Database operations
|
37
44
|
("astrapy.database", "AsyncDatabase.create_collection", "astra.create_collection"),
|
38
45
|
("astrapy.database", "AsyncDatabase.drop_collection", "astra.drop_collection"),
|
39
|
-
|
40
46
|
# Async Collection operations
|
41
47
|
("astrapy.collection", "AsyncCollection.insert_one", "astra.insert_one"),
|
42
48
|
("astrapy.collection", "AsyncCollection.insert_many", "astra.insert_many"),
|
43
49
|
("astrapy.collection", "AsyncCollection.update_one", "astra.update_one"),
|
44
50
|
("astrapy.collection", "AsyncCollection.update_many", "astra.update_many"),
|
45
|
-
(
|
51
|
+
(
|
52
|
+
"astrapy.collection",
|
53
|
+
"AsyncCollection.find_one_and_update",
|
54
|
+
"astra.find_one_and_update",
|
55
|
+
),
|
46
56
|
("astrapy.collection", "AsyncCollection.find", "astra.find"),
|
47
57
|
("astrapy.collection", "AsyncCollection.replace_one", "astra.replace_one"),
|
48
|
-
(
|
58
|
+
(
|
59
|
+
"astrapy.collection",
|
60
|
+
"AsyncCollection.find_one_and_delete",
|
61
|
+
"astra.find_one_and_delete",
|
62
|
+
),
|
49
63
|
("astrapy.collection", "AsyncCollection.delete_one", "astra.delete_one"),
|
50
64
|
("astrapy.collection", "AsyncCollection.delete_many", "astra.delete_many"),
|
51
65
|
]
|
52
66
|
|
67
|
+
|
53
68
|
class AstraInstrumentor(BaseInstrumentor):
|
54
69
|
"""
|
55
70
|
An instrumentor for AstraDB's client library.
|
@@ -73,8 +88,17 @@ class AstraInstrumentor(BaseInstrumentor):
|
|
73
88
|
wrap_function_wrapper(
|
74
89
|
module,
|
75
90
|
class_method,
|
76
|
-
general_wrap(
|
77
|
-
|
91
|
+
general_wrap(
|
92
|
+
endpoint,
|
93
|
+
version,
|
94
|
+
environment,
|
95
|
+
application_name,
|
96
|
+
tracer,
|
97
|
+
pricing_info,
|
98
|
+
capture_message_content,
|
99
|
+
metrics,
|
100
|
+
disable_metrics,
|
101
|
+
),
|
78
102
|
)
|
79
103
|
|
80
104
|
# Wrap async operations
|
@@ -82,8 +106,17 @@ class AstraInstrumentor(BaseInstrumentor):
|
|
82
106
|
wrap_function_wrapper(
|
83
107
|
module,
|
84
108
|
class_method,
|
85
|
-
async_general_wrap(
|
86
|
-
|
109
|
+
async_general_wrap(
|
110
|
+
endpoint,
|
111
|
+
version,
|
112
|
+
environment,
|
113
|
+
application_name,
|
114
|
+
tracer,
|
115
|
+
pricing_info,
|
116
|
+
capture_message_content,
|
117
|
+
metrics,
|
118
|
+
disable_metrics,
|
119
|
+
),
|
87
120
|
)
|
88
121
|
|
89
122
|
def _uninstrument(self, **kwargs):
|
@@ -12,11 +12,22 @@ from openlit.instrumentation.astra.utils import (
|
|
12
12
|
set_server_address_and_port,
|
13
13
|
)
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
|
16
|
+
def general_wrap(
|
17
|
+
gen_ai_endpoint,
|
18
|
+
version,
|
19
|
+
environment,
|
20
|
+
application_name,
|
21
|
+
tracer,
|
22
|
+
pricing_info,
|
23
|
+
capture_message_content,
|
24
|
+
metrics,
|
25
|
+
disable_metrics,
|
26
|
+
):
|
17
27
|
"""
|
18
28
|
Generates a telemetry wrapper for AstraDB function calls.
|
19
29
|
"""
|
30
|
+
|
20
31
|
def wrapper(wrapped, instance, args, kwargs):
|
21
32
|
# CRITICAL: Suppression check
|
22
33
|
if context_api.get_value(context_api._SUPPRESS_INSTRUMENTATION_KEY):
|
@@ -42,9 +53,21 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
42
53
|
try:
|
43
54
|
# Process response and generate telemetry
|
44
55
|
response = process_astra_response(
|
45
|
-
response,
|
46
|
-
|
47
|
-
|
56
|
+
response,
|
57
|
+
db_operation,
|
58
|
+
server_address,
|
59
|
+
server_port,
|
60
|
+
environment,
|
61
|
+
application_name,
|
62
|
+
metrics,
|
63
|
+
start_time,
|
64
|
+
span,
|
65
|
+
capture_message_content,
|
66
|
+
disable_metrics,
|
67
|
+
version,
|
68
|
+
instance,
|
69
|
+
args,
|
70
|
+
**kwargs,
|
48
71
|
)
|
49
72
|
|
50
73
|
except Exception as e:
|
@@ -12,11 +12,22 @@ from openlit.instrumentation.astra.utils import (
|
|
12
12
|
set_server_address_and_port,
|
13
13
|
)
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
|
16
|
+
def async_general_wrap(
|
17
|
+
gen_ai_endpoint,
|
18
|
+
version,
|
19
|
+
environment,
|
20
|
+
application_name,
|
21
|
+
tracer,
|
22
|
+
pricing_info,
|
23
|
+
capture_message_content,
|
24
|
+
metrics,
|
25
|
+
disable_metrics,
|
26
|
+
):
|
17
27
|
"""
|
18
28
|
Generates a telemetry wrapper for AstraDB async function calls.
|
19
29
|
"""
|
30
|
+
|
20
31
|
async def wrapper(wrapped, instance, args, kwargs):
|
21
32
|
# CRITICAL: Suppression check
|
22
33
|
if context_api.get_value(context_api._SUPPRESS_INSTRUMENTATION_KEY):
|
@@ -42,9 +53,21 @@ def async_general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
42
53
|
try:
|
43
54
|
# Process response and generate telemetry
|
44
55
|
response = process_astra_response(
|
45
|
-
response,
|
46
|
-
|
47
|
-
|
56
|
+
response,
|
57
|
+
db_operation,
|
58
|
+
server_address,
|
59
|
+
server_port,
|
60
|
+
environment,
|
61
|
+
application_name,
|
62
|
+
metrics,
|
63
|
+
start_time,
|
64
|
+
span,
|
65
|
+
capture_message_content,
|
66
|
+
disable_metrics,
|
67
|
+
version,
|
68
|
+
instance,
|
69
|
+
args,
|
70
|
+
**kwargs,
|
48
71
|
)
|
49
72
|
|
50
73
|
except Exception as e:
|
@@ -30,6 +30,7 @@ DB_OPERATION_MAP = {
|
|
30
30
|
"astra.delete_many": SemanticConvention.DB_OPERATION_DELETE,
|
31
31
|
}
|
32
32
|
|
33
|
+
|
33
34
|
def object_count(obj):
|
34
35
|
"""
|
35
36
|
Counts length of object if it exists, else returns 0.
|
@@ -40,6 +41,7 @@ def object_count(obj):
|
|
40
41
|
return 1
|
41
42
|
return 0
|
42
43
|
|
44
|
+
|
43
45
|
def set_server_address_and_port(instance):
|
44
46
|
"""
|
45
47
|
Extracts server address and port from AstraDB client instance.
|
@@ -83,9 +85,18 @@ def set_server_address_and_port(instance):
|
|
83
85
|
|
84
86
|
return server_address, server_port
|
85
87
|
|
86
|
-
|
87
|
-
|
88
|
-
|
88
|
+
|
89
|
+
def common_astra_logic(
|
90
|
+
scope,
|
91
|
+
environment,
|
92
|
+
application_name,
|
93
|
+
metrics,
|
94
|
+
capture_message_content,
|
95
|
+
disable_metrics,
|
96
|
+
version,
|
97
|
+
instance=None,
|
98
|
+
endpoint=None,
|
99
|
+
):
|
89
100
|
"""
|
90
101
|
Process AstraDB request and generate telemetry.
|
91
102
|
|
@@ -103,13 +114,22 @@ def common_astra_logic(scope, environment, application_name,
|
|
103
114
|
scope._end_time = time.time()
|
104
115
|
|
105
116
|
# Set common database span attributes using helper
|
106
|
-
common_db_span_attributes(
|
107
|
-
scope
|
117
|
+
common_db_span_attributes(
|
118
|
+
scope,
|
119
|
+
SemanticConvention.DB_SYSTEM_ASTRA,
|
120
|
+
scope._server_address,
|
121
|
+
scope._server_port,
|
122
|
+
environment,
|
123
|
+
application_name,
|
124
|
+
version,
|
125
|
+
)
|
108
126
|
|
109
127
|
# Set DB operation specific attributes
|
110
128
|
scope._span.set_attribute(SemanticConvention.DB_OPERATION_NAME, scope._db_operation)
|
111
|
-
scope._span.set_attribute(
|
112
|
-
|
129
|
+
scope._span.set_attribute(
|
130
|
+
SemanticConvention.DB_CLIENT_OPERATION_DURATION,
|
131
|
+
scope._end_time - scope._start_time,
|
132
|
+
)
|
113
133
|
|
114
134
|
# Get collection name from instance
|
115
135
|
collection_name = getattr(instance, "name", "unknown")
|
@@ -117,124 +137,192 @@ def common_astra_logic(scope, environment, application_name,
|
|
117
137
|
|
118
138
|
if scope._db_operation == SemanticConvention.DB_OPERATION_CREATE_COLLECTION:
|
119
139
|
# Handle create_collection operation
|
120
|
-
scope._span.set_attribute(
|
121
|
-
|
122
|
-
|
123
|
-
|
140
|
+
scope._span.set_attribute(
|
141
|
+
SemanticConvention.DB_COLLECTION_DIMENSION,
|
142
|
+
scope._kwargs.get("dimension", -1),
|
143
|
+
)
|
144
|
+
scope._span.set_attribute(
|
145
|
+
SemanticConvention.DB_INDEX_METRIC, str(scope._kwargs.get("metric", ""))
|
146
|
+
)
|
124
147
|
|
125
148
|
# Set namespace if available in response
|
126
149
|
if scope._response and hasattr(scope._response, "keyspace"):
|
127
|
-
scope._span.set_attribute(
|
150
|
+
scope._span.set_attribute(
|
151
|
+
SemanticConvention.DB_NAMESPACE, scope._response.keyspace
|
152
|
+
)
|
128
153
|
|
129
154
|
if scope._response and hasattr(scope._response, "name"):
|
130
|
-
scope._span.set_attribute(
|
155
|
+
scope._span.set_attribute(
|
156
|
+
SemanticConvention.DB_COLLECTION_NAME, scope._response.name
|
157
|
+
)
|
131
158
|
|
132
|
-
scope._span.set_attribute(
|
159
|
+
scope._span.set_attribute(
|
160
|
+
SemanticConvention.DB_QUERY_SUMMARY,
|
133
161
|
f"{scope._db_operation} {collection_name} "
|
134
162
|
f"dimension={scope._kwargs.get('dimension', 'None')} "
|
135
|
-
f"metric={scope._kwargs.get('metric', 'None')}"
|
163
|
+
f"metric={scope._kwargs.get('metric', 'None')}",
|
164
|
+
)
|
136
165
|
|
137
166
|
elif scope._db_operation == SemanticConvention.DB_OPERATION_DELETE_COLLECTION:
|
138
167
|
# Handle drop_collection operation
|
139
|
-
scope._span.set_attribute(
|
140
|
-
|
168
|
+
scope._span.set_attribute(
|
169
|
+
SemanticConvention.DB_QUERY_SUMMARY,
|
170
|
+
f"{scope._db_operation} {collection_name}",
|
171
|
+
)
|
141
172
|
|
142
173
|
elif scope._db_operation == SemanticConvention.DB_OPERATION_INSERT:
|
143
174
|
# Handle insert operations (insert_one, insert_many, regular insert)
|
144
|
-
documents =
|
175
|
+
documents = (
|
176
|
+
scope._args[0] if scope._args else scope._kwargs.get("documents", [])
|
177
|
+
)
|
145
178
|
|
146
|
-
scope._span.set_attribute(
|
179
|
+
scope._span.set_attribute(
|
180
|
+
SemanticConvention.DB_DOCUMENTS_COUNT, object_count(documents)
|
181
|
+
)
|
147
182
|
scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(documents))
|
148
183
|
|
149
184
|
# Response metrics
|
150
185
|
if scope._response and hasattr(scope._response, "inserted_ids"):
|
151
|
-
scope._span.set_attribute(
|
152
|
-
|
186
|
+
scope._span.set_attribute(
|
187
|
+
SemanticConvention.DB_RESPONSE_RETURNED_ROWS,
|
188
|
+
len(scope._response.inserted_ids),
|
189
|
+
)
|
153
190
|
|
154
|
-
scope._span.set_attribute(
|
191
|
+
scope._span.set_attribute(
|
192
|
+
SemanticConvention.DB_QUERY_SUMMARY,
|
155
193
|
f"{scope._db_operation} {collection_name} "
|
156
|
-
f"documents_count={object_count(documents)}"
|
194
|
+
f"documents_count={object_count(documents)}",
|
195
|
+
)
|
157
196
|
|
158
197
|
elif scope._db_operation == SemanticConvention.DB_OPERATION_UPDATE:
|
159
198
|
# Handle update operations (update_one, update_many, regular update)
|
160
|
-
update_query =
|
161
|
-
|
199
|
+
update_query = (
|
200
|
+
scope._args[1] if len(scope._args) > 1 else scope._kwargs.get("update", {})
|
201
|
+
)
|
202
|
+
filter_query = (
|
203
|
+
scope._args[0] if scope._args else scope._kwargs.get("filter", {})
|
204
|
+
)
|
162
205
|
|
163
206
|
scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(update_query))
|
164
207
|
scope._span.set_attribute(SemanticConvention.DB_FILTER, str(filter_query))
|
165
208
|
|
166
209
|
# Response metrics
|
167
210
|
if scope._response and hasattr(scope._response, "update_info"):
|
168
|
-
scope._span.set_attribute(
|
169
|
-
|
211
|
+
scope._span.set_attribute(
|
212
|
+
SemanticConvention.DB_RESPONSE_RETURNED_ROWS,
|
213
|
+
scope._response.update_info.get("nModified", 0),
|
214
|
+
)
|
170
215
|
|
171
|
-
scope._span.set_attribute(
|
216
|
+
scope._span.set_attribute(
|
217
|
+
SemanticConvention.DB_QUERY_SUMMARY,
|
172
218
|
f"{scope._db_operation} {collection_name} "
|
173
219
|
f"filter={str(filter_query)[:100]}... "
|
174
|
-
f"update={str(update_query)[:100]}..."
|
220
|
+
f"update={str(update_query)[:100]}...",
|
221
|
+
)
|
175
222
|
|
176
223
|
elif scope._db_operation == SemanticConvention.DB_OPERATION_REPLACE:
|
177
224
|
# Handle replace operations (find_one_and_update, replace_one)
|
178
|
-
filter_query =
|
225
|
+
filter_query = (
|
226
|
+
scope._args[0] if scope._args else scope._kwargs.get("filter", {})
|
227
|
+
)
|
179
228
|
|
180
229
|
# Check if it's an upsert operation
|
181
230
|
if scope._kwargs.get("upsert"):
|
182
231
|
scope._db_operation = SemanticConvention.DB_OPERATION_UPSERT
|
183
|
-
scope._span.set_attribute(
|
184
|
-
SemanticConvention.
|
232
|
+
scope._span.set_attribute(
|
233
|
+
SemanticConvention.DB_OPERATION_NAME,
|
234
|
+
SemanticConvention.DB_OPERATION_UPSERT,
|
235
|
+
)
|
185
236
|
|
186
237
|
scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(filter_query))
|
187
238
|
scope._span.set_attribute(SemanticConvention.DB_FILTER, str(filter_query))
|
188
239
|
|
189
|
-
scope._span.set_attribute(
|
240
|
+
scope._span.set_attribute(
|
241
|
+
SemanticConvention.DB_QUERY_SUMMARY,
|
190
242
|
f"{scope._db_operation} {collection_name} "
|
191
243
|
f"filter={str(filter_query)[:100]}... "
|
192
|
-
f"upsert={scope._kwargs.get('upsert', False)}"
|
244
|
+
f"upsert={scope._kwargs.get('upsert', False)}",
|
245
|
+
)
|
193
246
|
|
194
247
|
elif scope._db_operation == SemanticConvention.DB_OPERATION_SELECT:
|
195
248
|
# Handle find operations
|
196
|
-
filter_query =
|
249
|
+
filter_query = (
|
250
|
+
scope._args[0] if scope._args else scope._kwargs.get("filter", {})
|
251
|
+
)
|
197
252
|
|
198
253
|
scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(filter_query))
|
199
254
|
scope._span.set_attribute(SemanticConvention.DB_FILTER, str(filter_query))
|
200
255
|
|
201
256
|
# Response metrics
|
202
257
|
if scope._response and hasattr(scope._response, "__len__"):
|
203
|
-
scope._span.set_attribute(
|
204
|
-
len(scope._response)
|
258
|
+
scope._span.set_attribute(
|
259
|
+
SemanticConvention.DB_RESPONSE_RETURNED_ROWS, len(scope._response)
|
260
|
+
)
|
205
261
|
|
206
|
-
scope._span.set_attribute(
|
262
|
+
scope._span.set_attribute(
|
263
|
+
SemanticConvention.DB_QUERY_SUMMARY,
|
207
264
|
f"{scope._db_operation} {collection_name} "
|
208
|
-
f"filter={str(filter_query)[:100]}..."
|
265
|
+
f"filter={str(filter_query)[:100]}...",
|
266
|
+
)
|
209
267
|
|
210
|
-
elif scope._db_operation in [
|
211
|
-
|
268
|
+
elif scope._db_operation in [
|
269
|
+
SemanticConvention.DB_OPERATION_DELETE,
|
270
|
+
SemanticConvention.DB_OPERATION_FIND_AND_DELETE,
|
271
|
+
]:
|
212
272
|
# Handle delete operations (delete_one, delete_many, find_one_and_delete)
|
213
|
-
filter_query =
|
273
|
+
filter_query = (
|
274
|
+
scope._args[0] if scope._args else scope._kwargs.get("filter", {})
|
275
|
+
)
|
214
276
|
|
215
277
|
scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(filter_query))
|
216
278
|
scope._span.set_attribute(SemanticConvention.DB_FILTER, str(filter_query))
|
217
279
|
|
218
280
|
# Response metrics
|
219
281
|
if scope._response and hasattr(scope._response, "deleted_count"):
|
220
|
-
scope._span.set_attribute(
|
221
|
-
|
282
|
+
scope._span.set_attribute(
|
283
|
+
SemanticConvention.DB_RESPONSE_RETURNED_ROWS,
|
284
|
+
scope._response.deleted_count,
|
285
|
+
)
|
222
286
|
|
223
|
-
scope._span.set_attribute(
|
287
|
+
scope._span.set_attribute(
|
288
|
+
SemanticConvention.DB_QUERY_SUMMARY,
|
224
289
|
f"{scope._db_operation} {collection_name} "
|
225
|
-
f"filter={str(filter_query)[:100]}..."
|
290
|
+
f"filter={str(filter_query)[:100]}...",
|
291
|
+
)
|
226
292
|
|
227
293
|
scope._span.set_status(Status(StatusCode.OK))
|
228
294
|
|
229
295
|
# Record metrics using helper
|
230
296
|
if not disable_metrics:
|
231
|
-
record_db_metrics(
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
297
|
+
record_db_metrics(
|
298
|
+
metrics,
|
299
|
+
SemanticConvention.DB_SYSTEM_ASTRA,
|
300
|
+
scope._server_address,
|
301
|
+
scope._server_port,
|
302
|
+
environment,
|
303
|
+
application_name,
|
304
|
+
scope._start_time,
|
305
|
+
scope._end_time,
|
306
|
+
)
|
307
|
+
|
308
|
+
|
309
|
+
def process_astra_response(
|
310
|
+
response,
|
311
|
+
db_operation,
|
312
|
+
server_address,
|
313
|
+
server_port,
|
314
|
+
environment,
|
315
|
+
application_name,
|
316
|
+
metrics,
|
317
|
+
start_time,
|
318
|
+
span,
|
319
|
+
capture_message_content,
|
320
|
+
disable_metrics,
|
321
|
+
version,
|
322
|
+
instance,
|
323
|
+
args,
|
324
|
+
**kwargs,
|
325
|
+
):
|
238
326
|
"""
|
239
327
|
Process AstraDB response and generate telemetry.
|
240
328
|
|
@@ -271,7 +359,15 @@ def process_astra_response(response, db_operation, server_address, server_port,
|
|
271
359
|
scope._args = args
|
272
360
|
|
273
361
|
# Process the response using common logic
|
274
|
-
common_astra_logic(
|
275
|
-
|
362
|
+
common_astra_logic(
|
363
|
+
scope,
|
364
|
+
environment,
|
365
|
+
application_name,
|
366
|
+
metrics,
|
367
|
+
capture_message_content,
|
368
|
+
disable_metrics,
|
369
|
+
version,
|
370
|
+
instance,
|
371
|
+
)
|
276
372
|
|
277
373
|
return response
|
@@ -6,15 +6,16 @@ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
|
6
6
|
from wrapt import wrap_function_wrapper
|
7
7
|
from openlit.instrumentation.azure_ai_inference.azure_ai_inference import (
|
8
8
|
complete,
|
9
|
-
embed
|
9
|
+
embed,
|
10
10
|
)
|
11
11
|
from openlit.instrumentation.azure_ai_inference.async_azure_ai_inference import (
|
12
12
|
async_complete,
|
13
|
-
async_embed
|
13
|
+
async_embed,
|
14
14
|
)
|
15
15
|
|
16
16
|
_instruments = ("azure-ai-inference >= 1.0.0b4",)
|
17
17
|
|
18
|
+
|
18
19
|
class AzureAIInferenceInstrumentor(BaseInstrumentor):
|
19
20
|
"""
|
20
21
|
An instrumentor for azure-ai-inference client library.
|
@@ -37,32 +38,64 @@ class AzureAIInferenceInstrumentor(BaseInstrumentor):
|
|
37
38
|
wrap_function_wrapper(
|
38
39
|
"azure.ai.inference",
|
39
40
|
"ChatCompletionsClient.complete",
|
40
|
-
complete(
|
41
|
-
|
41
|
+
complete(
|
42
|
+
version,
|
43
|
+
environment,
|
44
|
+
application_name,
|
45
|
+
tracer,
|
46
|
+
pricing_info,
|
47
|
+
capture_message_content,
|
48
|
+
metrics,
|
49
|
+
disable_metrics,
|
50
|
+
),
|
42
51
|
)
|
43
52
|
|
44
53
|
# async chat completions
|
45
54
|
wrap_function_wrapper(
|
46
55
|
"azure.ai.inference.aio",
|
47
56
|
"ChatCompletionsClient.complete",
|
48
|
-
async_complete(
|
49
|
-
|
57
|
+
async_complete(
|
58
|
+
version,
|
59
|
+
environment,
|
60
|
+
application_name,
|
61
|
+
tracer,
|
62
|
+
pricing_info,
|
63
|
+
capture_message_content,
|
64
|
+
metrics,
|
65
|
+
disable_metrics,
|
66
|
+
),
|
50
67
|
)
|
51
68
|
|
52
69
|
# sync embeddings
|
53
70
|
wrap_function_wrapper(
|
54
71
|
"azure.ai.inference",
|
55
72
|
"EmbeddingsClient.embed",
|
56
|
-
embed(
|
57
|
-
|
73
|
+
embed(
|
74
|
+
version,
|
75
|
+
environment,
|
76
|
+
application_name,
|
77
|
+
tracer,
|
78
|
+
pricing_info,
|
79
|
+
capture_message_content,
|
80
|
+
metrics,
|
81
|
+
disable_metrics,
|
82
|
+
),
|
58
83
|
)
|
59
84
|
|
60
85
|
# async embeddings
|
61
86
|
wrap_function_wrapper(
|
62
87
|
"azure.ai.inference.aio",
|
63
88
|
"EmbeddingsClient.embed",
|
64
|
-
async_embed(
|
65
|
-
|
89
|
+
async_embed(
|
90
|
+
version,
|
91
|
+
environment,
|
92
|
+
application_name,
|
93
|
+
tracer,
|
94
|
+
pricing_info,
|
95
|
+
capture_message_content,
|
96
|
+
metrics,
|
97
|
+
disable_metrics,
|
98
|
+
),
|
66
99
|
)
|
67
100
|
|
68
101
|
def _uninstrument(self, **kwargs):
|