openlit 1.34.29__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 +111 -24
- openlit/instrumentation/crewai/async_crewai.py +114 -0
- openlit/instrumentation/crewai/crewai.py +104 -131
- openlit/instrumentation/crewai/utils.py +615 -0
- 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 +312 -101
- 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 +660 -186
- openlit/instrumentation/openai_agents/__init__.py +6 -2
- openlit/instrumentation/openai_agents/processor.py +409 -537
- 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 +101 -7
- {openlit-1.34.29.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.29.dist-info/RECORD +0 -166
- {openlit-1.34.29.dist-info → openlit-1.34.31.dist-info}/LICENSE +0 -0
- {openlit-1.34.29.dist-info → openlit-1.34.31.dist-info}/WHEEL +0 -0
@@ -5,15 +5,27 @@ Module for monitoring mem0 applications.
|
|
5
5
|
|
6
6
|
import logging
|
7
7
|
from opentelemetry.trace import SpanKind, Status, StatusCode
|
8
|
-
from opentelemetry.sdk.resources import
|
8
|
+
from opentelemetry.sdk.resources import (
|
9
|
+
SERVICE_NAME,
|
10
|
+
TELEMETRY_SDK_NAME,
|
11
|
+
DEPLOYMENT_ENVIRONMENT,
|
12
|
+
)
|
9
13
|
from openlit.__helpers import handle_exception
|
10
14
|
from openlit.semcov import SemanticConvention
|
11
15
|
|
12
16
|
# Initialize logger for logging potential issues and operations
|
13
17
|
logger = logging.getLogger(__name__)
|
14
18
|
|
15
|
-
|
16
|
-
|
19
|
+
|
20
|
+
def mem0_wrap(
|
21
|
+
gen_ai_endpoint,
|
22
|
+
version,
|
23
|
+
environment,
|
24
|
+
application_name,
|
25
|
+
tracer,
|
26
|
+
pricing_info,
|
27
|
+
capture_message_content,
|
28
|
+
):
|
17
29
|
"""
|
18
30
|
Creates a wrapper around a function call to trace and log its execution metrics.
|
19
31
|
|
@@ -54,51 +66,60 @@ def mem0_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
54
66
|
on the span based on the function's execution and response, and ensures
|
55
67
|
errors are handled and logged appropriately.
|
56
68
|
"""
|
57
|
-
with tracer.start_as_current_span(
|
69
|
+
with tracer.start_as_current_span(
|
70
|
+
gen_ai_endpoint, kind=SpanKind.CLIENT
|
71
|
+
) as span:
|
58
72
|
response = wrapped(*args, **kwargs)
|
59
73
|
|
60
74
|
try:
|
61
75
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
62
|
-
span.set_attribute(
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
span.set_attribute(
|
67
|
-
|
68
|
-
span.set_attribute(
|
69
|
-
|
70
|
-
|
71
|
-
|
76
|
+
span.set_attribute(
|
77
|
+
SemanticConvention.GEN_AI_SYSTEM,
|
78
|
+
SemanticConvention.GEN_AI_SYSTEM_MEM0,
|
79
|
+
)
|
80
|
+
span.set_attribute(SemanticConvention.GEN_AI_ENDPOINT, gen_ai_endpoint)
|
81
|
+
span.set_attribute(DEPLOYMENT_ENVIRONMENT, environment)
|
82
|
+
span.set_attribute(
|
83
|
+
SemanticConvention.GEN_AI_OPERATION,
|
84
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_FRAMEWORK,
|
85
|
+
)
|
86
|
+
span.set_attribute(SERVICE_NAME, application_name)
|
72
87
|
|
73
88
|
if gen_ai_endpoint == "mem0.memory_add":
|
74
|
-
span.set_attribute(
|
75
|
-
|
89
|
+
span.set_attribute(
|
90
|
+
SemanticConvention.DB_METADATA, str(kwargs.get("metadata", ""))
|
91
|
+
)
|
76
92
|
if response:
|
77
|
-
span.set_attribute(
|
78
|
-
|
93
|
+
span.set_attribute(
|
94
|
+
SemanticConvention.GEN_AI_DATA_SOURCES, len(response)
|
95
|
+
)
|
79
96
|
|
80
97
|
elif gen_ai_endpoint == "mem0.memory_get_all":
|
81
98
|
if response:
|
82
|
-
span.set_attribute(
|
83
|
-
|
99
|
+
span.set_attribute(
|
100
|
+
SemanticConvention.GEN_AI_DATA_SOURCES, len(response)
|
101
|
+
)
|
84
102
|
|
85
103
|
elif gen_ai_endpoint == "mem0.memory_get":
|
86
104
|
if response:
|
87
|
-
span.set_attribute(
|
88
|
-
|
105
|
+
span.set_attribute(
|
106
|
+
SemanticConvention.GEN_AI_DATA_SOURCES, len(response)
|
107
|
+
)
|
89
108
|
|
90
109
|
elif gen_ai_endpoint == "mem0.memory_search":
|
91
|
-
span.set_attribute(
|
92
|
-
|
110
|
+
span.set_attribute(
|
111
|
+
SemanticConvention.DB_STATEMENT, kwargs.get("query", "")
|
112
|
+
)
|
93
113
|
|
94
114
|
elif gen_ai_endpoint == "mem0.memory_update":
|
95
|
-
span.set_attribute(
|
96
|
-
|
115
|
+
span.set_attribute(
|
116
|
+
SemanticConvention.DB_UPDATE_ID, kwargs.get("memory_id", "")
|
117
|
+
)
|
97
118
|
|
98
119
|
elif gen_ai_endpoint == "mem0.memory_delete":
|
99
|
-
span.set_attribute(
|
100
|
-
|
101
|
-
|
120
|
+
span.set_attribute(
|
121
|
+
SemanticConvention.DB_DELETE_ID, kwargs.get("memory_id", "")
|
122
|
+
)
|
102
123
|
|
103
124
|
span.set_status(Status(StatusCode.OK))
|
104
125
|
|
@@ -23,6 +23,7 @@ MILVUS_OPERATIONS = [
|
|
23
23
|
("delete", "milvus.delete"),
|
24
24
|
]
|
25
25
|
|
26
|
+
|
26
27
|
class MilvusInstrumentor(BaseInstrumentor):
|
27
28
|
"""
|
28
29
|
An instrumentor for Milvus's client library.
|
@@ -47,8 +48,15 @@ class MilvusInstrumentor(BaseInstrumentor):
|
|
47
48
|
"pymilvus",
|
48
49
|
f"MilvusClient.{method_name}",
|
49
50
|
general_wrap(
|
50
|
-
endpoint,
|
51
|
-
|
51
|
+
endpoint,
|
52
|
+
version,
|
53
|
+
environment,
|
54
|
+
application_name,
|
55
|
+
tracer,
|
56
|
+
pricing_info,
|
57
|
+
capture_message_content,
|
58
|
+
metrics,
|
59
|
+
disable_metrics,
|
52
60
|
),
|
53
61
|
)
|
54
62
|
|
@@ -12,11 +12,22 @@ from openlit.instrumentation.milvus.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 Milvus 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):
|
@@ -27,7 +38,9 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
27
38
|
|
28
39
|
db_operation = DB_OPERATION_MAP.get(gen_ai_endpoint, "unknown")
|
29
40
|
if db_operation == "create_collection":
|
30
|
-
collection_name = kwargs.get("collection_name") or (
|
41
|
+
collection_name = kwargs.get("collection_name") or (
|
42
|
+
args[0] if args else "unknown"
|
43
|
+
)
|
31
44
|
else:
|
32
45
|
collection_name = kwargs.get("collection_name", "unknown")
|
33
46
|
span_name = f"{db_operation} {collection_name}"
|
@@ -39,9 +52,21 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
39
52
|
try:
|
40
53
|
# Process response and generate telemetry
|
41
54
|
response = process_milvus_response(
|
42
|
-
response,
|
43
|
-
|
44
|
-
|
55
|
+
response,
|
56
|
+
db_operation,
|
57
|
+
server_address,
|
58
|
+
server_port,
|
59
|
+
environment,
|
60
|
+
application_name,
|
61
|
+
metrics,
|
62
|
+
start_time,
|
63
|
+
span,
|
64
|
+
capture_message_content,
|
65
|
+
disable_metrics,
|
66
|
+
version,
|
67
|
+
instance,
|
68
|
+
args,
|
69
|
+
**kwargs,
|
45
70
|
)
|
46
71
|
|
47
72
|
except Exception as e:
|
@@ -23,12 +23,14 @@ DB_OPERATION_MAP = {
|
|
23
23
|
"milvus.delete": SemanticConvention.DB_OPERATION_DELETE,
|
24
24
|
}
|
25
25
|
|
26
|
+
|
26
27
|
def object_count(obj):
|
27
28
|
"""
|
28
29
|
Counts length of object if it exists, else returns 0.
|
29
30
|
"""
|
30
31
|
return len(obj) if obj else 0
|
31
32
|
|
33
|
+
|
32
34
|
def set_server_address_and_port(instance):
|
33
35
|
"""
|
34
36
|
Extracts server address and port from Milvus client instance.
|
@@ -68,9 +70,18 @@ def set_server_address_and_port(instance):
|
|
68
70
|
|
69
71
|
return server_address, server_port
|
70
72
|
|
71
|
-
|
72
|
-
|
73
|
-
|
73
|
+
|
74
|
+
def common_milvus_logic(
|
75
|
+
scope,
|
76
|
+
environment,
|
77
|
+
application_name,
|
78
|
+
metrics,
|
79
|
+
capture_message_content,
|
80
|
+
disable_metrics,
|
81
|
+
version,
|
82
|
+
instance=None,
|
83
|
+
endpoint=None,
|
84
|
+
):
|
74
85
|
"""
|
75
86
|
Process Milvus database request and generate telemetry.
|
76
87
|
|
@@ -88,153 +99,233 @@ def common_milvus_logic(scope, environment, application_name,
|
|
88
99
|
scope._end_time = time.time()
|
89
100
|
|
90
101
|
# Set common database span attributes using helper
|
91
|
-
common_db_span_attributes(
|
92
|
-
scope
|
102
|
+
common_db_span_attributes(
|
103
|
+
scope,
|
104
|
+
SemanticConvention.DB_SYSTEM_MILVUS,
|
105
|
+
scope._server_address,
|
106
|
+
scope._server_port,
|
107
|
+
environment,
|
108
|
+
application_name,
|
109
|
+
version,
|
110
|
+
)
|
93
111
|
|
94
112
|
# Set DB operation specific attributes
|
95
113
|
scope._span.set_attribute(SemanticConvention.DB_OPERATION_NAME, scope._db_operation)
|
96
|
-
scope._span.set_attribute(
|
97
|
-
|
114
|
+
scope._span.set_attribute(
|
115
|
+
SemanticConvention.DB_CLIENT_OPERATION_DURATION,
|
116
|
+
scope._end_time - scope._start_time,
|
117
|
+
)
|
98
118
|
|
99
119
|
if scope._db_operation == SemanticConvention.DB_OPERATION_CREATE_COLLECTION:
|
100
120
|
collection_name = scope._kwargs.get("collection_name", "unknown")
|
101
121
|
|
102
122
|
# Standard database attributes
|
103
|
-
scope._span.set_attribute(
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
123
|
+
scope._span.set_attribute(
|
124
|
+
SemanticConvention.DB_COLLECTION_NAME, collection_name
|
125
|
+
)
|
126
|
+
scope._span.set_attribute(
|
127
|
+
SemanticConvention.DB_COLLECTION_DIMENSION,
|
128
|
+
scope._kwargs.get("dimension", -1),
|
129
|
+
)
|
130
|
+
|
131
|
+
scope._span.set_attribute(
|
132
|
+
SemanticConvention.DB_QUERY_SUMMARY,
|
108
133
|
f"{scope._db_operation} {collection_name} "
|
109
|
-
f"dimension={scope._kwargs.get('dimension', 'None')}"
|
134
|
+
f"dimension={scope._kwargs.get('dimension', 'None')}",
|
135
|
+
)
|
110
136
|
|
111
137
|
elif scope._db_operation == SemanticConvention.DB_OPERATION_DELETE_COLLECTION:
|
112
138
|
collection_name = scope._kwargs.get("collection_name", "unknown")
|
113
139
|
|
114
140
|
# Standard database attributes
|
115
|
-
scope._span.set_attribute(
|
141
|
+
scope._span.set_attribute(
|
142
|
+
SemanticConvention.DB_COLLECTION_NAME, collection_name
|
143
|
+
)
|
116
144
|
|
117
|
-
scope._span.set_attribute(
|
118
|
-
|
145
|
+
scope._span.set_attribute(
|
146
|
+
SemanticConvention.DB_QUERY_SUMMARY,
|
147
|
+
f"{scope._db_operation} {collection_name}",
|
148
|
+
)
|
119
149
|
|
120
150
|
elif scope._db_operation == SemanticConvention.DB_OPERATION_INSERT:
|
121
151
|
collection_name = scope._kwargs.get("collection_name", "unknown")
|
122
152
|
data = scope._kwargs.get("data", [])
|
123
153
|
|
124
154
|
# Standard database attributes
|
125
|
-
scope._span.set_attribute(
|
126
|
-
|
155
|
+
scope._span.set_attribute(
|
156
|
+
SemanticConvention.DB_COLLECTION_NAME, collection_name
|
157
|
+
)
|
158
|
+
scope._span.set_attribute(
|
159
|
+
SemanticConvention.DB_VECTOR_COUNT, object_count(data)
|
160
|
+
)
|
127
161
|
scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(data))
|
128
162
|
|
129
163
|
# Response metrics
|
130
164
|
if scope._response and scope._response.get("insert_count"):
|
131
|
-
scope._span.set_attribute(
|
132
|
-
|
165
|
+
scope._span.set_attribute(
|
166
|
+
SemanticConvention.DB_RESPONSE_RETURNED_ROWS,
|
167
|
+
scope._response["insert_count"],
|
168
|
+
)
|
133
169
|
|
134
170
|
if scope._response and scope._response.get("cost"):
|
135
|
-
scope._span.set_attribute(
|
136
|
-
scope._response["cost"]
|
171
|
+
scope._span.set_attribute(
|
172
|
+
SemanticConvention.DB_OPERATION_COST, scope._response["cost"]
|
173
|
+
)
|
137
174
|
|
138
|
-
scope._span.set_attribute(
|
139
|
-
|
140
|
-
f"data_count={object_count(data)}"
|
175
|
+
scope._span.set_attribute(
|
176
|
+
SemanticConvention.DB_QUERY_SUMMARY,
|
177
|
+
f"{scope._db_operation} {collection_name} data_count={object_count(data)}",
|
178
|
+
)
|
141
179
|
|
142
180
|
elif scope._db_operation == SemanticConvention.DB_OPERATION_UPSERT:
|
143
181
|
collection_name = scope._kwargs.get("collection_name", "unknown")
|
144
182
|
data = scope._kwargs.get("data", [])
|
145
183
|
|
146
184
|
# Standard database attributes
|
147
|
-
scope._span.set_attribute(
|
148
|
-
|
185
|
+
scope._span.set_attribute(
|
186
|
+
SemanticConvention.DB_COLLECTION_NAME, collection_name
|
187
|
+
)
|
188
|
+
scope._span.set_attribute(
|
189
|
+
SemanticConvention.DB_VECTOR_COUNT, object_count(data)
|
190
|
+
)
|
149
191
|
scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(data))
|
150
192
|
|
151
193
|
# Response metrics
|
152
194
|
if scope._response and scope._response.get("upsert_count"):
|
153
|
-
scope._span.set_attribute(
|
154
|
-
|
195
|
+
scope._span.set_attribute(
|
196
|
+
SemanticConvention.DB_RESPONSE_RETURNED_ROWS,
|
197
|
+
scope._response["upsert_count"],
|
198
|
+
)
|
155
199
|
|
156
200
|
if scope._response and scope._response.get("cost"):
|
157
|
-
scope._span.set_attribute(
|
158
|
-
scope._response["cost"]
|
201
|
+
scope._span.set_attribute(
|
202
|
+
SemanticConvention.DB_OPERATION_COST, scope._response["cost"]
|
203
|
+
)
|
159
204
|
|
160
|
-
scope._span.set_attribute(
|
161
|
-
|
162
|
-
f"data_count={object_count(data)}"
|
205
|
+
scope._span.set_attribute(
|
206
|
+
SemanticConvention.DB_QUERY_SUMMARY,
|
207
|
+
f"{scope._db_operation} {collection_name} data_count={object_count(data)}",
|
208
|
+
)
|
163
209
|
|
164
210
|
elif scope._db_operation == SemanticConvention.DB_OPERATION_SEARCH:
|
165
211
|
collection_name = scope._kwargs.get("collection_name", "unknown")
|
166
212
|
data = scope._kwargs.get("data", [])
|
167
213
|
|
168
214
|
# Standard database attributes
|
169
|
-
scope._span.set_attribute(
|
215
|
+
scope._span.set_attribute(
|
216
|
+
SemanticConvention.DB_COLLECTION_NAME, collection_name
|
217
|
+
)
|
170
218
|
scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(data))
|
171
|
-
scope._span.set_attribute(
|
172
|
-
scope._kwargs.get("limit", -1)
|
219
|
+
scope._span.set_attribute(
|
220
|
+
SemanticConvention.DB_VECTOR_QUERY_TOP_K, scope._kwargs.get("limit", -1)
|
221
|
+
)
|
173
222
|
|
174
223
|
# Search specific attributes
|
175
|
-
scope._span.set_attribute(
|
176
|
-
str(scope._kwargs.get("filter", ""))
|
224
|
+
scope._span.set_attribute(
|
225
|
+
SemanticConvention.DB_FILTER, str(scope._kwargs.get("filter", ""))
|
226
|
+
)
|
177
227
|
|
178
228
|
# Response metrics
|
179
229
|
if scope._response and isinstance(scope._response, list):
|
180
|
-
scope._span.set_attribute(
|
181
|
-
len(scope._response)
|
230
|
+
scope._span.set_attribute(
|
231
|
+
SemanticConvention.DB_RESPONSE_RETURNED_ROWS, len(scope._response)
|
232
|
+
)
|
182
233
|
|
183
|
-
scope._span.set_attribute(
|
234
|
+
scope._span.set_attribute(
|
235
|
+
SemanticConvention.DB_QUERY_SUMMARY,
|
184
236
|
f"{scope._db_operation} {collection_name} "
|
185
237
|
f"data={str(data)[:100]}... "
|
186
|
-
f"limit={scope._kwargs.get('limit', 'None')}"
|
238
|
+
f"limit={scope._kwargs.get('limit', 'None')}",
|
239
|
+
)
|
187
240
|
|
188
|
-
elif scope._db_operation in [
|
241
|
+
elif scope._db_operation in [
|
242
|
+
SemanticConvention.DB_OPERATION_QUERY,
|
243
|
+
SemanticConvention.DB_OPERATION_GET,
|
244
|
+
]:
|
189
245
|
collection_name = scope._kwargs.get("collection_name", "unknown")
|
190
246
|
output_fields = scope._kwargs.get("output_fields", [])
|
191
247
|
|
192
248
|
# Standard database attributes
|
193
|
-
scope._span.set_attribute(
|
249
|
+
scope._span.set_attribute(
|
250
|
+
SemanticConvention.DB_COLLECTION_NAME, collection_name
|
251
|
+
)
|
194
252
|
scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(output_fields))
|
195
253
|
|
196
254
|
# Query specific attributes
|
197
|
-
scope._span.set_attribute(
|
198
|
-
str(scope._kwargs.get("filter", ""))
|
255
|
+
scope._span.set_attribute(
|
256
|
+
SemanticConvention.DB_FILTER, str(scope._kwargs.get("filter", ""))
|
257
|
+
)
|
199
258
|
|
200
259
|
# Response metrics
|
201
260
|
if scope._response and isinstance(scope._response, list):
|
202
|
-
scope._span.set_attribute(
|
203
|
-
len(scope._response)
|
261
|
+
scope._span.set_attribute(
|
262
|
+
SemanticConvention.DB_RESPONSE_RETURNED_ROWS, len(scope._response)
|
263
|
+
)
|
204
264
|
|
205
|
-
scope._span.set_attribute(
|
265
|
+
scope._span.set_attribute(
|
266
|
+
SemanticConvention.DB_QUERY_SUMMARY,
|
206
267
|
f"{scope._db_operation} {collection_name} "
|
207
268
|
f"output_fields={output_fields} "
|
208
|
-
f"filter={scope._kwargs.get('filter', 'None')}"
|
269
|
+
f"filter={scope._kwargs.get('filter', 'None')}",
|
270
|
+
)
|
209
271
|
|
210
272
|
elif scope._db_operation == SemanticConvention.DB_OPERATION_DELETE:
|
211
273
|
collection_name = scope._kwargs.get("collection_name", "unknown")
|
212
274
|
|
213
275
|
# Standard database attributes
|
214
|
-
scope._span.set_attribute(
|
215
|
-
|
216
|
-
|
276
|
+
scope._span.set_attribute(
|
277
|
+
SemanticConvention.DB_COLLECTION_NAME, collection_name
|
278
|
+
)
|
279
|
+
scope._span.set_attribute(
|
280
|
+
SemanticConvention.DB_FILTER, str(scope._kwargs.get("filter", ""))
|
281
|
+
)
|
217
282
|
|
218
283
|
# Response metrics
|
219
284
|
if scope._response and scope._response.get("delete_count"):
|
220
|
-
scope._span.set_attribute(
|
221
|
-
|
285
|
+
scope._span.set_attribute(
|
286
|
+
SemanticConvention.DB_RESPONSE_RETURNED_ROWS,
|
287
|
+
scope._response["delete_count"],
|
288
|
+
)
|
222
289
|
|
223
|
-
scope._span.set_attribute(
|
290
|
+
scope._span.set_attribute(
|
291
|
+
SemanticConvention.DB_QUERY_SUMMARY,
|
224
292
|
f"{scope._db_operation} {collection_name} "
|
225
|
-
f"filter={scope._kwargs.get('filter', 'None')}"
|
293
|
+
f"filter={scope._kwargs.get('filter', 'None')}",
|
294
|
+
)
|
226
295
|
|
227
296
|
scope._span.set_status(Status(StatusCode.OK))
|
228
297
|
|
229
298
|
# Record metrics using helper
|
230
299
|
if not disable_metrics:
|
231
|
-
record_db_metrics(
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
300
|
+
record_db_metrics(
|
301
|
+
metrics,
|
302
|
+
SemanticConvention.DB_SYSTEM_MILVUS,
|
303
|
+
scope._server_address,
|
304
|
+
scope._server_port,
|
305
|
+
environment,
|
306
|
+
application_name,
|
307
|
+
scope._start_time,
|
308
|
+
scope._end_time,
|
309
|
+
)
|
310
|
+
|
311
|
+
|
312
|
+
def process_milvus_response(
|
313
|
+
response,
|
314
|
+
db_operation,
|
315
|
+
server_address,
|
316
|
+
server_port,
|
317
|
+
environment,
|
318
|
+
application_name,
|
319
|
+
metrics,
|
320
|
+
start_time,
|
321
|
+
span,
|
322
|
+
capture_message_content,
|
323
|
+
disable_metrics,
|
324
|
+
version,
|
325
|
+
instance,
|
326
|
+
args,
|
327
|
+
**kwargs,
|
328
|
+
):
|
238
329
|
"""
|
239
330
|
Process Milvus response and generate telemetry.
|
240
331
|
|
@@ -270,7 +361,15 @@ def process_milvus_response(response, db_operation, server_address, server_port,
|
|
270
361
|
scope._kwargs = kwargs
|
271
362
|
|
272
363
|
# Process the response using common logic
|
273
|
-
common_milvus_logic(
|
274
|
-
|
364
|
+
common_milvus_logic(
|
365
|
+
scope,
|
366
|
+
environment,
|
367
|
+
application_name,
|
368
|
+
metrics,
|
369
|
+
capture_message_content,
|
370
|
+
disable_metrics,
|
371
|
+
version,
|
372
|
+
instance,
|
373
|
+
)
|
275
374
|
|
276
375
|
return response
|