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.
Files changed (168) hide show
  1. openlit/__helpers.py +235 -86
  2. openlit/__init__.py +16 -13
  3. openlit/_instrumentors.py +2 -1
  4. openlit/evals/all.py +50 -21
  5. openlit/evals/bias_detection.py +47 -20
  6. openlit/evals/hallucination.py +53 -22
  7. openlit/evals/toxicity.py +50 -21
  8. openlit/evals/utils.py +54 -30
  9. openlit/guard/all.py +61 -19
  10. openlit/guard/prompt_injection.py +34 -14
  11. openlit/guard/restrict_topic.py +46 -15
  12. openlit/guard/sensitive_topic.py +34 -14
  13. openlit/guard/utils.py +58 -22
  14. openlit/instrumentation/ag2/__init__.py +24 -8
  15. openlit/instrumentation/ag2/ag2.py +34 -13
  16. openlit/instrumentation/ag2/async_ag2.py +34 -13
  17. openlit/instrumentation/ag2/utils.py +133 -30
  18. openlit/instrumentation/ai21/__init__.py +43 -14
  19. openlit/instrumentation/ai21/ai21.py +47 -21
  20. openlit/instrumentation/ai21/async_ai21.py +47 -21
  21. openlit/instrumentation/ai21/utils.py +299 -78
  22. openlit/instrumentation/anthropic/__init__.py +21 -4
  23. openlit/instrumentation/anthropic/anthropic.py +28 -17
  24. openlit/instrumentation/anthropic/async_anthropic.py +28 -17
  25. openlit/instrumentation/anthropic/utils.py +145 -35
  26. openlit/instrumentation/assemblyai/__init__.py +11 -2
  27. openlit/instrumentation/assemblyai/assemblyai.py +15 -4
  28. openlit/instrumentation/assemblyai/utils.py +120 -25
  29. openlit/instrumentation/astra/__init__.py +43 -10
  30. openlit/instrumentation/astra/astra.py +28 -5
  31. openlit/instrumentation/astra/async_astra.py +28 -5
  32. openlit/instrumentation/astra/utils.py +151 -55
  33. openlit/instrumentation/azure_ai_inference/__init__.py +43 -10
  34. openlit/instrumentation/azure_ai_inference/async_azure_ai_inference.py +53 -21
  35. openlit/instrumentation/azure_ai_inference/azure_ai_inference.py +53 -21
  36. openlit/instrumentation/azure_ai_inference/utils.py +307 -83
  37. openlit/instrumentation/bedrock/__init__.py +21 -4
  38. openlit/instrumentation/bedrock/bedrock.py +63 -25
  39. openlit/instrumentation/bedrock/utils.py +139 -30
  40. openlit/instrumentation/chroma/__init__.py +89 -16
  41. openlit/instrumentation/chroma/chroma.py +28 -6
  42. openlit/instrumentation/chroma/utils.py +167 -51
  43. openlit/instrumentation/cohere/__init__.py +63 -18
  44. openlit/instrumentation/cohere/async_cohere.py +63 -24
  45. openlit/instrumentation/cohere/cohere.py +63 -24
  46. openlit/instrumentation/cohere/utils.py +286 -73
  47. openlit/instrumentation/controlflow/__init__.py +35 -9
  48. openlit/instrumentation/controlflow/controlflow.py +66 -33
  49. openlit/instrumentation/crawl4ai/__init__.py +25 -10
  50. openlit/instrumentation/crawl4ai/async_crawl4ai.py +78 -31
  51. openlit/instrumentation/crawl4ai/crawl4ai.py +78 -31
  52. openlit/instrumentation/crewai/__init__.py +111 -24
  53. openlit/instrumentation/crewai/async_crewai.py +114 -0
  54. openlit/instrumentation/crewai/crewai.py +104 -131
  55. openlit/instrumentation/crewai/utils.py +615 -0
  56. openlit/instrumentation/dynamiq/__init__.py +46 -12
  57. openlit/instrumentation/dynamiq/dynamiq.py +74 -33
  58. openlit/instrumentation/elevenlabs/__init__.py +23 -4
  59. openlit/instrumentation/elevenlabs/async_elevenlabs.py +16 -4
  60. openlit/instrumentation/elevenlabs/elevenlabs.py +16 -4
  61. openlit/instrumentation/elevenlabs/utils.py +128 -25
  62. openlit/instrumentation/embedchain/__init__.py +11 -2
  63. openlit/instrumentation/embedchain/embedchain.py +68 -35
  64. openlit/instrumentation/firecrawl/__init__.py +24 -7
  65. openlit/instrumentation/firecrawl/firecrawl.py +46 -20
  66. openlit/instrumentation/google_ai_studio/__init__.py +45 -10
  67. openlit/instrumentation/google_ai_studio/async_google_ai_studio.py +67 -44
  68. openlit/instrumentation/google_ai_studio/google_ai_studio.py +67 -44
  69. openlit/instrumentation/google_ai_studio/utils.py +180 -67
  70. openlit/instrumentation/gpt4all/__init__.py +22 -7
  71. openlit/instrumentation/gpt4all/gpt4all.py +67 -29
  72. openlit/instrumentation/gpt4all/utils.py +285 -61
  73. openlit/instrumentation/gpu/__init__.py +128 -47
  74. openlit/instrumentation/groq/__init__.py +21 -4
  75. openlit/instrumentation/groq/async_groq.py +33 -21
  76. openlit/instrumentation/groq/groq.py +33 -21
  77. openlit/instrumentation/groq/utils.py +192 -55
  78. openlit/instrumentation/haystack/__init__.py +70 -24
  79. openlit/instrumentation/haystack/async_haystack.py +28 -6
  80. openlit/instrumentation/haystack/haystack.py +28 -6
  81. openlit/instrumentation/haystack/utils.py +196 -74
  82. openlit/instrumentation/julep/__init__.py +69 -19
  83. openlit/instrumentation/julep/async_julep.py +53 -27
  84. openlit/instrumentation/julep/julep.py +53 -28
  85. openlit/instrumentation/langchain/__init__.py +74 -63
  86. openlit/instrumentation/langchain/callback_handler.py +1100 -0
  87. openlit/instrumentation/langchain_community/__init__.py +13 -2
  88. openlit/instrumentation/langchain_community/async_langchain_community.py +23 -5
  89. openlit/instrumentation/langchain_community/langchain_community.py +23 -5
  90. openlit/instrumentation/langchain_community/utils.py +35 -9
  91. openlit/instrumentation/letta/__init__.py +68 -15
  92. openlit/instrumentation/letta/letta.py +99 -54
  93. openlit/instrumentation/litellm/__init__.py +43 -14
  94. openlit/instrumentation/litellm/async_litellm.py +51 -26
  95. openlit/instrumentation/litellm/litellm.py +51 -26
  96. openlit/instrumentation/litellm/utils.py +312 -101
  97. openlit/instrumentation/llamaindex/__init__.py +267 -90
  98. openlit/instrumentation/llamaindex/async_llamaindex.py +28 -6
  99. openlit/instrumentation/llamaindex/llamaindex.py +28 -6
  100. openlit/instrumentation/llamaindex/utils.py +204 -91
  101. openlit/instrumentation/mem0/__init__.py +11 -2
  102. openlit/instrumentation/mem0/mem0.py +50 -29
  103. openlit/instrumentation/milvus/__init__.py +10 -2
  104. openlit/instrumentation/milvus/milvus.py +31 -6
  105. openlit/instrumentation/milvus/utils.py +166 -67
  106. openlit/instrumentation/mistral/__init__.py +63 -18
  107. openlit/instrumentation/mistral/async_mistral.py +63 -24
  108. openlit/instrumentation/mistral/mistral.py +63 -24
  109. openlit/instrumentation/mistral/utils.py +277 -69
  110. openlit/instrumentation/multion/__init__.py +69 -19
  111. openlit/instrumentation/multion/async_multion.py +57 -26
  112. openlit/instrumentation/multion/multion.py +57 -26
  113. openlit/instrumentation/ollama/__init__.py +39 -18
  114. openlit/instrumentation/ollama/async_ollama.py +57 -26
  115. openlit/instrumentation/ollama/ollama.py +57 -26
  116. openlit/instrumentation/ollama/utils.py +226 -50
  117. openlit/instrumentation/openai/__init__.py +156 -32
  118. openlit/instrumentation/openai/async_openai.py +147 -67
  119. openlit/instrumentation/openai/openai.py +150 -67
  120. openlit/instrumentation/openai/utils.py +660 -186
  121. openlit/instrumentation/openai_agents/__init__.py +6 -2
  122. openlit/instrumentation/openai_agents/processor.py +409 -537
  123. openlit/instrumentation/phidata/__init__.py +13 -5
  124. openlit/instrumentation/phidata/phidata.py +67 -32
  125. openlit/instrumentation/pinecone/__init__.py +48 -9
  126. openlit/instrumentation/pinecone/async_pinecone.py +27 -5
  127. openlit/instrumentation/pinecone/pinecone.py +27 -5
  128. openlit/instrumentation/pinecone/utils.py +153 -47
  129. openlit/instrumentation/premai/__init__.py +22 -7
  130. openlit/instrumentation/premai/premai.py +51 -26
  131. openlit/instrumentation/premai/utils.py +246 -59
  132. openlit/instrumentation/pydantic_ai/__init__.py +49 -22
  133. openlit/instrumentation/pydantic_ai/pydantic_ai.py +69 -16
  134. openlit/instrumentation/pydantic_ai/utils.py +89 -24
  135. openlit/instrumentation/qdrant/__init__.py +19 -4
  136. openlit/instrumentation/qdrant/async_qdrant.py +33 -7
  137. openlit/instrumentation/qdrant/qdrant.py +33 -7
  138. openlit/instrumentation/qdrant/utils.py +228 -93
  139. openlit/instrumentation/reka/__init__.py +23 -10
  140. openlit/instrumentation/reka/async_reka.py +17 -11
  141. openlit/instrumentation/reka/reka.py +17 -11
  142. openlit/instrumentation/reka/utils.py +138 -36
  143. openlit/instrumentation/together/__init__.py +44 -12
  144. openlit/instrumentation/together/async_together.py +50 -27
  145. openlit/instrumentation/together/together.py +50 -27
  146. openlit/instrumentation/together/utils.py +301 -71
  147. openlit/instrumentation/transformers/__init__.py +2 -1
  148. openlit/instrumentation/transformers/transformers.py +13 -3
  149. openlit/instrumentation/transformers/utils.py +139 -36
  150. openlit/instrumentation/vertexai/__init__.py +81 -16
  151. openlit/instrumentation/vertexai/async_vertexai.py +33 -15
  152. openlit/instrumentation/vertexai/utils.py +123 -27
  153. openlit/instrumentation/vertexai/vertexai.py +33 -15
  154. openlit/instrumentation/vllm/__init__.py +12 -5
  155. openlit/instrumentation/vllm/utils.py +121 -31
  156. openlit/instrumentation/vllm/vllm.py +16 -10
  157. openlit/otel/events.py +35 -10
  158. openlit/otel/metrics.py +32 -24
  159. openlit/otel/tracing.py +24 -9
  160. openlit/semcov/__init__.py +101 -7
  161. {openlit-1.34.29.dist-info → openlit-1.34.31.dist-info}/METADATA +2 -1
  162. openlit-1.34.31.dist-info/RECORD +166 -0
  163. openlit/instrumentation/langchain/async_langchain.py +0 -102
  164. openlit/instrumentation/langchain/langchain.py +0 -102
  165. openlit/instrumentation/langchain/utils.py +0 -252
  166. openlit-1.34.29.dist-info/RECORD +0 -166
  167. {openlit-1.34.29.dist-info → openlit-1.34.31.dist-info}/LICENSE +0 -0
  168. {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 SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
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
- def mem0_wrap(gen_ai_endpoint, version, environment, application_name,
16
- tracer, pricing_info, capture_message_content):
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(gen_ai_endpoint, kind= SpanKind.CLIENT) as 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(SemanticConvention.GEN_AI_SYSTEM,
63
- SemanticConvention.GEN_AI_SYSTEM_MEM0)
64
- span.set_attribute(SemanticConvention.GEN_AI_ENDPOINT,
65
- gen_ai_endpoint)
66
- span.set_attribute(DEPLOYMENT_ENVIRONMENT,
67
- environment)
68
- span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
69
- SemanticConvention.GEN_AI_OPERATION_TYPE_FRAMEWORK)
70
- span.set_attribute(SERVICE_NAME,
71
- application_name)
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(SemanticConvention.DB_METADATA,
75
- str(kwargs.get('metadata', '')))
89
+ span.set_attribute(
90
+ SemanticConvention.DB_METADATA, str(kwargs.get("metadata", ""))
91
+ )
76
92
  if response:
77
- span.set_attribute(SemanticConvention.GEN_AI_DATA_SOURCES,
78
- len(response))
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(SemanticConvention.GEN_AI_DATA_SOURCES,
83
- len(response))
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(SemanticConvention.GEN_AI_DATA_SOURCES,
88
- len(response))
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(SemanticConvention.DB_STATEMENT,
92
- kwargs.get("query", ""))
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(SemanticConvention.DB_UPDATE_ID,
96
- kwargs.get("memory_id", ""))
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(SemanticConvention.DB_DELETE_ID,
100
- kwargs.get("memory_id", ""))
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, version, environment, application_name, tracer,
51
- pricing_info, capture_message_content, metrics, disable_metrics
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
- def general_wrap(gen_ai_endpoint, version, environment, application_name,
16
- tracer, pricing_info, capture_message_content, metrics, disable_metrics):
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 (args[0] if args else "unknown")
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, db_operation, server_address, server_port,
43
- environment, application_name, metrics, start_time, span,
44
- capture_message_content, disable_metrics, version, instance, args, **kwargs
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
- def common_milvus_logic(scope, environment, application_name,
72
- metrics, capture_message_content, disable_metrics, version,
73
- instance=None, endpoint=None):
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(scope, SemanticConvention.DB_SYSTEM_MILVUS,
92
- scope._server_address, scope._server_port, environment, application_name, version)
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(SemanticConvention.DB_CLIENT_OPERATION_DURATION,
97
- scope._end_time - scope._start_time)
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(SemanticConvention.DB_COLLECTION_NAME, collection_name)
104
- scope._span.set_attribute(SemanticConvention.DB_COLLECTION_DIMENSION,
105
- scope._kwargs.get("dimension", -1))
106
-
107
- scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
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(SemanticConvention.DB_COLLECTION_NAME, collection_name)
141
+ scope._span.set_attribute(
142
+ SemanticConvention.DB_COLLECTION_NAME, collection_name
143
+ )
116
144
 
117
- scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
118
- f"{scope._db_operation} {collection_name}")
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(SemanticConvention.DB_COLLECTION_NAME, collection_name)
126
- scope._span.set_attribute(SemanticConvention.DB_VECTOR_COUNT, object_count(data))
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(SemanticConvention.DB_RESPONSE_RETURNED_ROWS,
132
- scope._response["insert_count"])
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(SemanticConvention.DB_OPERATION_COST,
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(SemanticConvention.DB_QUERY_SUMMARY,
139
- f"{scope._db_operation} {collection_name} "
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(SemanticConvention.DB_COLLECTION_NAME, collection_name)
148
- scope._span.set_attribute(SemanticConvention.DB_VECTOR_COUNT, object_count(data))
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(SemanticConvention.DB_RESPONSE_RETURNED_ROWS,
154
- scope._response["upsert_count"])
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(SemanticConvention.DB_OPERATION_COST,
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(SemanticConvention.DB_QUERY_SUMMARY,
161
- f"{scope._db_operation} {collection_name} "
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(SemanticConvention.DB_COLLECTION_NAME, collection_name)
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(SemanticConvention.DB_VECTOR_QUERY_TOP_K,
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(SemanticConvention.DB_FILTER,
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(SemanticConvention.DB_RESPONSE_RETURNED_ROWS,
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(SemanticConvention.DB_QUERY_SUMMARY,
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 [SemanticConvention.DB_OPERATION_QUERY, SemanticConvention.DB_OPERATION_GET]:
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(SemanticConvention.DB_COLLECTION_NAME, collection_name)
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(SemanticConvention.DB_FILTER,
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(SemanticConvention.DB_RESPONSE_RETURNED_ROWS,
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(SemanticConvention.DB_QUERY_SUMMARY,
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(SemanticConvention.DB_COLLECTION_NAME, collection_name)
215
- scope._span.set_attribute(SemanticConvention.DB_FILTER,
216
- str(scope._kwargs.get("filter", "")))
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(SemanticConvention.DB_RESPONSE_RETURNED_ROWS,
221
- scope._response["delete_count"])
285
+ scope._span.set_attribute(
286
+ SemanticConvention.DB_RESPONSE_RETURNED_ROWS,
287
+ scope._response["delete_count"],
288
+ )
222
289
 
223
- scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
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(metrics, SemanticConvention.DB_SYSTEM_MILVUS,
232
- scope._server_address, scope._server_port, environment, application_name,
233
- scope._start_time, scope._end_time)
234
-
235
- def process_milvus_response(response, db_operation, server_address, server_port,
236
- environment, application_name, metrics, start_time, span,
237
- capture_message_content, disable_metrics, version, instance, args, **kwargs):
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(scope, environment, application_name,
274
- metrics, capture_message_content, disable_metrics, version, instance)
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