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.
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 +40 -15
  53. openlit/instrumentation/crewai/async_crewai.py +32 -7
  54. openlit/instrumentation/crewai/crewai.py +32 -7
  55. openlit/instrumentation/crewai/utils.py +159 -56
  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 +304 -102
  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 +657 -185
  121. openlit/instrumentation/openai_agents/__init__.py +5 -1
  122. openlit/instrumentation/openai_agents/processor.py +110 -90
  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 +72 -6
  161. {openlit-1.34.30.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.30.dist-info/RECORD +0 -168
  167. {openlit-1.34.30.dist-info → openlit-1.34.31.dist-info}/LICENSE +0 -0
  168. {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
- ("astrapy.collection", "Collection.find_one_and_update", "astra.find_one_and_update"),
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
- ("astrapy.collection", "Collection.find_one_and_delete", "astra.find_one_and_delete"),
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
- ("astrapy.collection", "AsyncCollection.find_one_and_update", "astra.find_one_and_update"),
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
- ("astrapy.collection", "AsyncCollection.find_one_and_delete", "astra.find_one_and_delete"),
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(endpoint, version, environment, application_name,
77
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
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(endpoint, version, environment, application_name,
86
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
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
- 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 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, db_operation, server_address, server_port,
46
- environment, application_name, metrics, start_time, span,
47
- capture_message_content, disable_metrics, version, instance, args, **kwargs
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
- def async_general_wrap(gen_ai_endpoint, version, environment, application_name,
16
- tracer, pricing_info, capture_message_content, metrics, disable_metrics):
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, db_operation, server_address, server_port,
46
- environment, application_name, metrics, start_time, span,
47
- capture_message_content, disable_metrics, version, instance, args, **kwargs
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
- def common_astra_logic(scope, environment, application_name,
87
- metrics, capture_message_content, disable_metrics, version,
88
- instance=None, endpoint=None):
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(scope, SemanticConvention.DB_SYSTEM_ASTRA,
107
- scope._server_address, scope._server_port, environment, application_name, version)
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(SemanticConvention.DB_CLIENT_OPERATION_DURATION,
112
- scope._end_time - scope._start_time)
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(SemanticConvention.DB_COLLECTION_DIMENSION,
121
- scope._kwargs.get("dimension", -1))
122
- scope._span.set_attribute(SemanticConvention.DB_INDEX_METRIC,
123
- str(scope._kwargs.get("metric", "")))
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(SemanticConvention.DB_NAMESPACE, scope._response.keyspace)
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(SemanticConvention.DB_COLLECTION_NAME, scope._response.name)
155
+ scope._span.set_attribute(
156
+ SemanticConvention.DB_COLLECTION_NAME, scope._response.name
157
+ )
131
158
 
132
- scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
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(SemanticConvention.DB_QUERY_SUMMARY,
140
- f"{scope._db_operation} {collection_name}")
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 = scope._args[0] if scope._args else scope._kwargs.get("documents", [])
175
+ documents = (
176
+ scope._args[0] if scope._args else scope._kwargs.get("documents", [])
177
+ )
145
178
 
146
- scope._span.set_attribute(SemanticConvention.DB_DOCUMENTS_COUNT, object_count(documents))
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(SemanticConvention.DB_RESPONSE_RETURNED_ROWS,
152
- len(scope._response.inserted_ids))
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(SemanticConvention.DB_QUERY_SUMMARY,
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 = scope._args[1] if len(scope._args) > 1 else scope._kwargs.get("update", {})
161
- filter_query = scope._args[0] if scope._args else scope._kwargs.get("filter", {})
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(SemanticConvention.DB_RESPONSE_RETURNED_ROWS,
169
- scope._response.update_info.get("nModified", 0))
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(SemanticConvention.DB_QUERY_SUMMARY,
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 = scope._args[0] if scope._args else scope._kwargs.get("filter", {})
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(SemanticConvention.DB_OPERATION_NAME,
184
- SemanticConvention.DB_OPERATION_UPSERT)
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(SemanticConvention.DB_QUERY_SUMMARY,
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 = scope._args[0] if scope._args else scope._kwargs.get("filter", {})
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(SemanticConvention.DB_RESPONSE_RETURNED_ROWS,
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(SemanticConvention.DB_QUERY_SUMMARY,
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 [SemanticConvention.DB_OPERATION_DELETE,
211
- SemanticConvention.DB_OPERATION_FIND_AND_DELETE]:
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 = scope._args[0] if scope._args else scope._kwargs.get("filter", {})
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(SemanticConvention.DB_RESPONSE_RETURNED_ROWS,
221
- scope._response.deleted_count)
282
+ scope._span.set_attribute(
283
+ SemanticConvention.DB_RESPONSE_RETURNED_ROWS,
284
+ scope._response.deleted_count,
285
+ )
222
286
 
223
- scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
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(metrics, SemanticConvention.DB_SYSTEM_ASTRA,
232
- scope._server_address, scope._server_port, environment, application_name,
233
- scope._start_time, scope._end_time)
234
-
235
- def process_astra_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):
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(scope, environment, application_name,
275
- metrics, capture_message_content, disable_metrics, version, instance)
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(version, environment, application_name,
41
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
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(version, environment, application_name,
49
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
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(version, environment, application_name,
57
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
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(version, environment, application_name,
65
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
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):