openlit 1.33.10__py3-none-any.whl → 1.33.12__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 (113) hide show
  1. openlit/__helpers.py +125 -88
  2. openlit/__init__.py +38 -11
  3. openlit/instrumentation/ag2/__init__.py +19 -20
  4. openlit/instrumentation/ag2/ag2.py +134 -69
  5. openlit/instrumentation/ai21/__init__.py +22 -21
  6. openlit/instrumentation/ai21/ai21.py +82 -546
  7. openlit/instrumentation/ai21/async_ai21.py +82 -546
  8. openlit/instrumentation/ai21/utils.py +409 -0
  9. openlit/instrumentation/anthropic/__init__.py +16 -16
  10. openlit/instrumentation/anthropic/anthropic.py +61 -353
  11. openlit/instrumentation/anthropic/async_anthropic.py +62 -354
  12. openlit/instrumentation/anthropic/utils.py +251 -0
  13. openlit/instrumentation/assemblyai/__init__.py +2 -2
  14. openlit/instrumentation/assemblyai/assemblyai.py +3 -3
  15. openlit/instrumentation/astra/__init__.py +25 -25
  16. openlit/instrumentation/astra/astra.py +2 -2
  17. openlit/instrumentation/astra/async_astra.py +2 -2
  18. openlit/instrumentation/azure_ai_inference/__init__.py +5 -5
  19. openlit/instrumentation/azure_ai_inference/async_azure_ai_inference.py +8 -8
  20. openlit/instrumentation/azure_ai_inference/azure_ai_inference.py +8 -8
  21. openlit/instrumentation/bedrock/__init__.py +2 -2
  22. openlit/instrumentation/bedrock/bedrock.py +3 -3
  23. openlit/instrumentation/chroma/__init__.py +9 -9
  24. openlit/instrumentation/chroma/chroma.py +2 -2
  25. openlit/instrumentation/cohere/__init__.py +7 -7
  26. openlit/instrumentation/cohere/async_cohere.py +9 -9
  27. openlit/instrumentation/cohere/cohere.py +9 -9
  28. openlit/instrumentation/controlflow/__init__.py +4 -4
  29. openlit/instrumentation/controlflow/controlflow.py +2 -2
  30. openlit/instrumentation/crawl4ai/__init__.py +3 -3
  31. openlit/instrumentation/crawl4ai/async_crawl4ai.py +2 -2
  32. openlit/instrumentation/crawl4ai/crawl4ai.py +2 -2
  33. openlit/instrumentation/crewai/__init__.py +3 -3
  34. openlit/instrumentation/crewai/crewai.py +2 -2
  35. openlit/instrumentation/dynamiq/__init__.py +5 -5
  36. openlit/instrumentation/dynamiq/dynamiq.py +2 -2
  37. openlit/instrumentation/elevenlabs/__init__.py +5 -5
  38. openlit/instrumentation/elevenlabs/async_elevenlabs.py +3 -3
  39. openlit/instrumentation/elevenlabs/elevenlabs.py +3 -3
  40. openlit/instrumentation/embedchain/__init__.py +2 -2
  41. openlit/instrumentation/embedchain/embedchain.py +4 -4
  42. openlit/instrumentation/firecrawl/__init__.py +3 -3
  43. openlit/instrumentation/firecrawl/firecrawl.py +2 -2
  44. openlit/instrumentation/google_ai_studio/__init__.py +3 -3
  45. openlit/instrumentation/google_ai_studio/async_google_ai_studio.py +3 -3
  46. openlit/instrumentation/google_ai_studio/google_ai_studio.py +3 -3
  47. openlit/instrumentation/gpt4all/__init__.py +3 -3
  48. openlit/instrumentation/gpt4all/gpt4all.py +7 -7
  49. openlit/instrumentation/groq/__init__.py +3 -3
  50. openlit/instrumentation/groq/async_groq.py +5 -5
  51. openlit/instrumentation/groq/groq.py +5 -5
  52. openlit/instrumentation/haystack/__init__.py +2 -2
  53. openlit/instrumentation/haystack/haystack.py +2 -2
  54. openlit/instrumentation/julep/__init__.py +7 -7
  55. openlit/instrumentation/julep/async_julep.py +3 -3
  56. openlit/instrumentation/julep/julep.py +3 -3
  57. openlit/instrumentation/langchain/__init__.py +2 -2
  58. openlit/instrumentation/langchain/async_langchain.py +13 -9
  59. openlit/instrumentation/langchain/langchain.py +13 -8
  60. openlit/instrumentation/letta/__init__.py +7 -7
  61. openlit/instrumentation/letta/letta.py +5 -5
  62. openlit/instrumentation/litellm/__init__.py +5 -5
  63. openlit/instrumentation/litellm/async_litellm.py +8 -8
  64. openlit/instrumentation/litellm/litellm.py +8 -8
  65. openlit/instrumentation/llamaindex/__init__.py +2 -2
  66. openlit/instrumentation/llamaindex/llamaindex.py +2 -2
  67. openlit/instrumentation/mem0/__init__.py +2 -2
  68. openlit/instrumentation/mem0/mem0.py +2 -2
  69. openlit/instrumentation/milvus/__init__.py +2 -2
  70. openlit/instrumentation/milvus/milvus.py +2 -2
  71. openlit/instrumentation/mistral/__init__.py +7 -7
  72. openlit/instrumentation/mistral/async_mistral.py +10 -10
  73. openlit/instrumentation/mistral/mistral.py +10 -10
  74. openlit/instrumentation/multion/__init__.py +7 -7
  75. openlit/instrumentation/multion/async_multion.py +5 -5
  76. openlit/instrumentation/multion/multion.py +5 -5
  77. openlit/instrumentation/ollama/__init__.py +11 -9
  78. openlit/instrumentation/ollama/async_ollama.py +71 -465
  79. openlit/instrumentation/ollama/ollama.py +71 -465
  80. openlit/instrumentation/ollama/utils.py +332 -0
  81. openlit/instrumentation/openai/__init__.py +11 -11
  82. openlit/instrumentation/openai/async_openai.py +18 -18
  83. openlit/instrumentation/openai/openai.py +18 -18
  84. openlit/instrumentation/phidata/__init__.py +2 -2
  85. openlit/instrumentation/phidata/phidata.py +2 -2
  86. openlit/instrumentation/pinecone/__init__.py +6 -6
  87. openlit/instrumentation/pinecone/pinecone.py +2 -2
  88. openlit/instrumentation/premai/__init__.py +3 -3
  89. openlit/instrumentation/premai/premai.py +7 -7
  90. openlit/instrumentation/qdrant/__init__.py +2 -2
  91. openlit/instrumentation/qdrant/async_qdrant.py +2 -2
  92. openlit/instrumentation/qdrant/qdrant.py +2 -2
  93. openlit/instrumentation/reka/__init__.py +3 -3
  94. openlit/instrumentation/reka/async_reka.py +3 -3
  95. openlit/instrumentation/reka/reka.py +3 -3
  96. openlit/instrumentation/together/__init__.py +5 -5
  97. openlit/instrumentation/together/async_together.py +8 -8
  98. openlit/instrumentation/together/together.py +8 -8
  99. openlit/instrumentation/transformers/__init__.py +2 -2
  100. openlit/instrumentation/transformers/transformers.py +4 -4
  101. openlit/instrumentation/vertexai/__init__.py +9 -9
  102. openlit/instrumentation/vertexai/async_vertexai.py +4 -4
  103. openlit/instrumentation/vertexai/vertexai.py +4 -4
  104. openlit/instrumentation/vllm/__init__.py +2 -2
  105. openlit/instrumentation/vllm/vllm.py +3 -3
  106. openlit/otel/events.py +85 -0
  107. openlit/otel/tracing.py +3 -13
  108. openlit/semcov/__init__.py +13 -1
  109. {openlit-1.33.10.dist-info → openlit-1.33.12.dist-info}/METADATA +2 -2
  110. openlit-1.33.12.dist-info/RECORD +126 -0
  111. openlit-1.33.10.dist-info/RECORD +0 -122
  112. {openlit-1.33.10.dist-info → openlit-1.33.12.dist-info}/LICENSE +0 -0
  113. {openlit-1.33.10.dist-info → openlit-1.33.12.dist-info}/WHEEL +0 -0
@@ -0,0 +1,251 @@
1
+ """
2
+ Anthropic OpenTelemetry instrumentation utility functions
3
+ """
4
+ import time
5
+
6
+ from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
7
+ from opentelemetry.trace import Status, StatusCode
8
+
9
+ from openlit.__helpers import (
10
+ calculate_ttft,
11
+ response_as_dict,
12
+ calculate_tbt,
13
+ extract_and_format_input,
14
+ get_chat_model_cost,
15
+ create_metrics_attributes,
16
+ otel_event,
17
+ concatenate_all_contents
18
+ )
19
+ from openlit.semcov import SemanticConvetion
20
+
21
+ def process_chunk(self, chunk):
22
+ """
23
+ Process a chunk of response data and update state.
24
+ """
25
+
26
+ end_time = time.time()
27
+ # Record the timestamp for the current chunk
28
+ self._timestamps.append(end_time)
29
+
30
+ if len(self._timestamps) == 1:
31
+ # Calculate time to first chunk
32
+ self._ttft = calculate_ttft(self._timestamps, self._start_time)
33
+
34
+ chunked = response_as_dict(chunk)
35
+
36
+ # Collect message IDs and input token from events
37
+ if chunked.get('type') == 'message_start':
38
+ self._response_id = chunked.get('message').get('id')
39
+ self._input_tokens = chunked.get('message').get('usage').get('input_tokens')
40
+ self._response_model = chunked.get('message').get('model')
41
+ self._response_role = chunked.get('message').get('role')
42
+
43
+ # Collect message IDs and aggregated response from events
44
+ if chunked.get('type') == 'content_block_delta':
45
+ if chunked.get('delta').get('text'):
46
+ self._llmresponse += chunked.get('delta').get('text')
47
+ elif chunked.get('delta').get('partial_json'):
48
+ self._tool_arguments += chunked.get('delta').get('partial_json')
49
+
50
+ if chunked.get('type') == 'content_block_start':
51
+ if chunked.get('content_block').get('id'):
52
+ self._tool_id = chunked.get('content_block').get('id')
53
+ if chunked.get('content_block').get('name'):
54
+ self._tool_name = chunked.get('content_block').get('name')
55
+
56
+ # Collect output tokens and stop reason from events
57
+ if chunked.get('type') == 'message_delta':
58
+ self._output_tokens = chunked.get('usage').get('output_tokens')
59
+ self._finish_reason = chunked.get('delta').get('stop_reason')
60
+
61
+ def common_chat_logic(scope, pricing_info, environment, application_name, metrics,
62
+ event_provider, capture_message_content, disable_metrics, version, is_stream):
63
+ """
64
+ Process chat request and generate Telemetry
65
+ """
66
+
67
+ scope._end_time = time.time()
68
+ if len(scope._timestamps) > 1:
69
+ scope._tbt = calculate_tbt(scope._timestamps)
70
+
71
+ formatted_messages = extract_and_format_input(scope._kwargs.get('messages', ''))
72
+ request_model = scope._kwargs.get('model', 'claude-3-opus-20240229')
73
+
74
+ cost = get_chat_model_cost(request_model, pricing_info, scope._input_tokens, scope._output_tokens)
75
+
76
+ # Set Span attributes (OTel Semconv)
77
+ scope._span.set_attribute(TELEMETRY_SDK_NAME, 'openlit')
78
+ scope._span.set_attribute(SemanticConvetion.GEN_AI_OPERATION, SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
79
+ scope._span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM, SemanticConvetion.GEN_AI_SYSTEM_ANTHROPIC)
80
+ scope._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL, request_model)
81
+ scope._span.set_attribute(SemanticConvetion.SERVER_PORT, scope._server_port)
82
+ scope._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS, scope._kwargs.get('max_tokens', -1))
83
+ scope._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_STOP_SEQUENCES, scope._kwargs.get('stop_sequences', []))
84
+ scope._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE, scope._kwargs.get('temperature', 1.0))
85
+ scope._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_K, scope._kwargs.get('top_k', 1.0))
86
+ scope._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P, scope._kwargs.get('top_p', 1.0))
87
+ scope._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON, [scope._finish_reason])
88
+ scope._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID, scope._response_id)
89
+ scope._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL, scope._response_model)
90
+ scope._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS, scope._input_tokens)
91
+ scope._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS, scope._output_tokens)
92
+ scope._span.set_attribute(SemanticConvetion.SERVER_ADDRESS, scope._server_address)
93
+
94
+ scope._span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,
95
+ 'text' if isinstance(scope._llmresponse, str) else 'json')
96
+
97
+ scope._span.set_attribute(DEPLOYMENT_ENVIRONMENT, environment)
98
+ scope._span.set_attribute(SERVICE_NAME, application_name)
99
+ scope._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM, is_stream)
100
+ scope._span.set_attribute(SemanticConvetion.GEN_AI_CLIENT_TOKEN_USAGE, scope._input_tokens + scope._output_tokens)
101
+ scope._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST, cost)
102
+ scope._span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TBT, scope._tbt)
103
+ scope._span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TTFT, scope._ttft)
104
+ scope._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION, version)
105
+
106
+ # To be removed one the change to log events (from span events) is complete
107
+ prompt = concatenate_all_contents(formatted_messages)
108
+ if capture_message_content:
109
+ scope._span.add_event(
110
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
111
+ attributes={
112
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
113
+ },
114
+ )
115
+ scope._span.add_event(
116
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
117
+ attributes={
118
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: scope._llmresponse,
119
+ },
120
+ )
121
+
122
+ choice_event_body = {
123
+ 'finish_reason': scope._finish_reason,
124
+ 'index': 0,
125
+ 'message': {
126
+ **({'content': scope._llmresponse} if capture_message_content else {}),
127
+ 'role': scope._response_role
128
+ }
129
+ }
130
+
131
+ if scope._tool_calls:
132
+ choice_event_body['message'].update({
133
+ 'tool_calls': {
134
+ 'function': {
135
+ 'name': scope._tool_calls.get('name', ''),
136
+ 'arguments': scope._tool_calls.get('input', '')
137
+ },
138
+ 'id': scope._tool_calls.get('id', ''),
139
+ 'type': 'function'
140
+ }
141
+ })
142
+
143
+ # Emit events
144
+ for role in ['user', 'system', 'assistant', 'tool']:
145
+ if formatted_messages.get(role, {}).get('content', ''):
146
+ event = otel_event(
147
+ name=getattr(SemanticConvetion, f'GEN_AI_{role.upper()}_MESSAGE'),
148
+ attributes={
149
+ SemanticConvetion.GEN_AI_SYSTEM: SemanticConvetion.GEN_AI_SYSTEM_ANTHROPIC
150
+ },
151
+ body = {
152
+ # pylint: disable=line-too-long
153
+ **({'content': formatted_messages.get(role, {}).get('content', '')} if capture_message_content else {}),
154
+ 'role': formatted_messages.get(role, {}).get('role', []),
155
+ **({
156
+ 'tool_calls': {
157
+ 'function': {
158
+ # pylint: disable=line-too-long
159
+ 'name': (scope._tool_calls[0].get('function', {}).get('name', '') if scope._tool_calls else ''),
160
+ 'arguments': (scope._tool_calls[0].get('function', {}).get('arguments', '') if scope._tool_calls else '')
161
+ },
162
+ 'id': (scope._tool_calls[0].get('id', '') if scope._tool_calls else ''),
163
+ 'type': 'function'
164
+ }
165
+ } if role == 'assistant' else {}),
166
+ **({
167
+ 'id': (scope._tool_calls[0].get('id', '') if scope._tool_calls else '')
168
+ } if role == 'tool' else {})
169
+ }
170
+ )
171
+ event_provider.emit(event)
172
+
173
+ choice_event = otel_event(
174
+ name=SemanticConvetion.GEN_AI_CHOICE,
175
+ attributes={
176
+ SemanticConvetion.GEN_AI_SYSTEM: SemanticConvetion.GEN_AI_SYSTEM_ANTHROPIC
177
+ },
178
+ body=choice_event_body
179
+ )
180
+ event_provider.emit(choice_event)
181
+
182
+ scope._span.set_status(Status(StatusCode.OK))
183
+
184
+ if not disable_metrics:
185
+ metrics_attributes = create_metrics_attributes(
186
+ service_name=application_name,
187
+ deployment_environment=environment,
188
+ operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
189
+ system=SemanticConvetion.GEN_AI_SYSTEM_ANTHROPIC,
190
+ request_model=request_model,
191
+ server_address=scope._server_address,
192
+ server_port=scope._server_port,
193
+ response_model=scope._response_model,
194
+ )
195
+
196
+ metrics['genai_client_usage_tokens'].record(scope._input_tokens + scope._output_tokens, metrics_attributes)
197
+ metrics['genai_client_operation_duration'].record(scope._end_time - scope._start_time, metrics_attributes)
198
+ metrics['genai_server_tbt'].record(scope._tbt, metrics_attributes)
199
+ metrics['genai_server_ttft'].record(scope._ttft, metrics_attributes)
200
+ metrics['genai_requests'].add(1, metrics_attributes)
201
+ metrics['genai_completion_tokens'].add(scope._output_tokens, metrics_attributes)
202
+ metrics['genai_prompt_tokens'].add(scope._input_tokens, metrics_attributes)
203
+ metrics['genai_cost'].record(cost, metrics_attributes)
204
+
205
+ def process_streaming_chat_response(self, pricing_info, environment, application_name, metrics,
206
+ event_provider, capture_message_content=False, disable_metrics=False, version=''):
207
+ """
208
+ Process chat request and generate Telemetry
209
+ """
210
+ if self._tool_id != '':
211
+ self._tool_calls = {
212
+ 'id': self._tool_id,
213
+ 'name': self._tool_name,
214
+ 'input': self._tool_arguments
215
+ }
216
+
217
+ common_chat_logic(self, pricing_info, environment, application_name, metrics,
218
+ event_provider, capture_message_content, disable_metrics, version, is_stream=True)
219
+
220
+ def process_chat_response(response, request_model, pricing_info, server_port, server_address,
221
+ environment, application_name, metrics, event_provider, start_time,
222
+ span, capture_message_content=False, disable_metrics=False, version='1.0.0', **kwargs):
223
+ """
224
+ Process chat request and generate Telemetry
225
+ """
226
+
227
+ self = type('GenericScope', (), {})()
228
+ response_dict = response_as_dict(response)
229
+
230
+ # pylint: disable = no-member
231
+ self._start_time = start_time
232
+ self._end_time = time.time()
233
+ self._span = span
234
+ self._llmresponse = response_dict.get('content', {})[0].get('text', '')
235
+ self._response_role = response_dict.get('message', {}).get('role', 'assistant')
236
+ self._input_tokens = response_dict.get('usage').get('input_tokens')
237
+ self._output_tokens = response_dict.get('usage').get('output_tokens')
238
+ self._response_model = response_dict.get('model', '')
239
+ self._finish_reason = response_dict.get('stop_reason', '')
240
+ self._response_id = response_dict.get('id', '')
241
+ self._timestamps = []
242
+ self._ttft, self._tbt = self._end_time - self._start_time, 0
243
+ self._server_address, self._server_port = server_address, server_port
244
+ self._kwargs = kwargs
245
+ #pylint: disable=line-too-long
246
+ self._tool_calls = (lambda c: c[1] if len(c) > 1 and c[1].get('type') == 'tool_use' else None)(response_dict.get('content', []))
247
+
248
+ common_chat_logic(self, pricing_info, environment, application_name, metrics,
249
+ event_provider, capture_message_content, disable_metrics, version, is_stream=False)
250
+
251
+ return response
@@ -26,7 +26,7 @@ class AssemblyAIInstrumentor(BaseInstrumentor):
26
26
  tracer = kwargs.get("tracer")
27
27
  metrics = kwargs.get("metrics_dict")
28
28
  pricing_info = kwargs.get("pricing_info", {})
29
- trace_content = kwargs.get("trace_content", False)
29
+ capture_message_content = kwargs.get("capture_message_content", False)
30
30
  disable_metrics = kwargs.get("disable_metrics")
31
31
  version = importlib.metadata.version("assemblyai")
32
32
 
@@ -35,7 +35,7 @@ class AssemblyAIInstrumentor(BaseInstrumentor):
35
35
  "assemblyai.transcriber",
36
36
  "Transcriber.transcribe",
37
37
  transcribe(version, environment, application_name,
38
- tracer, pricing_info, trace_content, metrics, disable_metrics),
38
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
39
39
  )
40
40
 
41
41
  def _uninstrument(self, **kwargs):
@@ -18,7 +18,7 @@ from openlit.semcov import SemanticConvetion
18
18
  logger = logging.getLogger(__name__)
19
19
 
20
20
  def transcribe(version, environment, application_name,
21
- tracer, pricing_info, trace_content, metrics, disable_metrics):
21
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):
22
22
  """
23
23
  Generates a telemetry wrapper for creating speech audio to collect metrics.
24
24
 
@@ -29,7 +29,7 @@ def transcribe(version, environment, application_name,
29
29
  application_name: Name of the application using the Assembly AI API.
30
30
  tracer: OpenTelemetry tracer for creating spans.
31
31
  pricing_info: Information used for calculating the cost of generating speech audio.
32
- trace_content: Flag indicating whether to trace the input text and generated audio.
32
+ capture_message_content: Flag indicating whether to trace the input text and generated audio.
33
33
 
34
34
  Returns:
35
35
  A function that wraps the speech audio creation method to add telemetry.
@@ -96,7 +96,7 @@ def transcribe(version, environment, application_name,
96
96
  span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,
97
97
  version)
98
98
 
99
- if trace_content:
99
+ if capture_message_content:
100
100
  span.add_event(
101
101
  name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
102
102
  attributes={
@@ -22,7 +22,7 @@ class AstraInstrumentor(BaseInstrumentor):
22
22
  tracer = kwargs.get("tracer")
23
23
  metrics = kwargs.get("metrics_dict")
24
24
  pricing_info = kwargs.get("pricing_info")
25
- trace_content = kwargs.get("trace_content")
25
+ capture_message_content = kwargs.get("capture_message_content")
26
26
  disable_metrics = kwargs.get("disable_metrics")
27
27
  version = importlib.metadata.version("astrapy")
28
28
 
@@ -31,73 +31,73 @@ class AstraInstrumentor(BaseInstrumentor):
31
31
  "astrapy.database",
32
32
  "Database.create_collection",
33
33
  general_wrap("astra.create_collection", version, environment, application_name,
34
- tracer, pricing_info, trace_content, metrics, disable_metrics),
34
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
35
35
  )
36
36
  wrap_function_wrapper(
37
37
  "astrapy.database",
38
38
  "Database.drop_collection",
39
39
  general_wrap("astra.drop_collection", version, environment, application_name,
40
- tracer, pricing_info, trace_content, metrics, disable_metrics),
40
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
41
41
  )
42
42
  wrap_function_wrapper(
43
43
  "astrapy.collection",
44
44
  "Collection.insert_one",
45
45
  general_wrap("astra.insert_one", version, environment, application_name,
46
- tracer, pricing_info, trace_content, metrics, disable_metrics),
46
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
47
47
  )
48
48
  wrap_function_wrapper(
49
49
  "astrapy.collection",
50
50
  "Collection.insert_many",
51
51
  general_wrap("astra.insert_many", version, environment, application_name,
52
- tracer, pricing_info, trace_content, metrics, disable_metrics),
52
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
53
53
  )
54
54
  wrap_function_wrapper(
55
55
  "astrapy.collection",
56
56
  "Collection.update_one",
57
57
  general_wrap("astra.update_one", version, environment, application_name,
58
- tracer, pricing_info, trace_content, metrics, disable_metrics),
58
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
59
59
  )
60
60
  wrap_function_wrapper(
61
61
  "astrapy.collection",
62
62
  "Collection.update_many",
63
63
  general_wrap("astra.update_many", version, environment, application_name,
64
- tracer, pricing_info, trace_content, metrics, disable_metrics),
64
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
65
65
  )
66
66
  wrap_function_wrapper(
67
67
  "astrapy.collection",
68
68
  "Collection.find_one_and_update",
69
69
  general_wrap("astra.find_one_and_update", version, environment, application_name,
70
- tracer, pricing_info, trace_content, metrics, disable_metrics),
70
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
71
71
  )
72
72
  wrap_function_wrapper(
73
73
  "astrapy.collection",
74
74
  "Collection.find",
75
75
  general_wrap("astra.find", version, environment, application_name,
76
- tracer, pricing_info, trace_content, metrics, disable_metrics),
76
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
77
77
  )
78
78
  wrap_function_wrapper(
79
79
  "astrapy.collection",
80
80
  "Collection.replace_one",
81
81
  general_wrap("astra.replace_one", version, environment, application_name,
82
- tracer, pricing_info, trace_content, metrics, disable_metrics),
82
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
83
83
  )
84
84
  wrap_function_wrapper(
85
85
  "astrapy.collection",
86
86
  "Collection.find_one_and_delete",
87
87
  general_wrap("astra.find_one_and_delete", version, environment, application_name,
88
- tracer, pricing_info, trace_content, metrics, disable_metrics),
88
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
89
89
  )
90
90
  wrap_function_wrapper(
91
91
  "astrapy.collection",
92
92
  "Collection.delete_one",
93
93
  general_wrap("astra.delete_one", version, environment, application_name,
94
- tracer, pricing_info, trace_content, metrics, disable_metrics),
94
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
95
95
  )
96
96
  wrap_function_wrapper(
97
97
  "astrapy.collection",
98
98
  "Collection.delete_many",
99
99
  general_wrap("astra.delete_many", version, environment, application_name,
100
- tracer, pricing_info, trace_content, metrics, disable_metrics),
100
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
101
101
  )
102
102
 
103
103
  # ASync
@@ -105,73 +105,73 @@ class AstraInstrumentor(BaseInstrumentor):
105
105
  "astrapy.database",
106
106
  "AsyncDatabase.create_collection",
107
107
  general_wrap("astra.create_collection", version, environment, application_name,
108
- tracer, pricing_info, trace_content, metrics, disable_metrics),
108
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
109
109
  )
110
110
  wrap_function_wrapper(
111
111
  "astrapy.database",
112
112
  "AsyncDatabase.drop_collection",
113
113
  general_wrap("astra.drop_collection", version, environment, application_name,
114
- tracer, pricing_info, trace_content, metrics, disable_metrics),
114
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
115
115
  )
116
116
  wrap_function_wrapper(
117
117
  "astrapy.collection",
118
118
  "AsyncCollection.insert_one",
119
119
  general_wrap("astra.insert_one", version, environment, application_name,
120
- tracer, pricing_info, trace_content, metrics, disable_metrics),
120
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
121
121
  )
122
122
  wrap_function_wrapper(
123
123
  "astrapy.collection",
124
124
  "AsyncCollection.insert_many",
125
125
  general_wrap("astra.insert_many", version, environment, application_name,
126
- tracer, pricing_info, trace_content, metrics, disable_metrics),
126
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
127
127
  )
128
128
  wrap_function_wrapper(
129
129
  "astrapy.collection",
130
130
  "AsyncCollection.update_one",
131
131
  general_wrap("astra.update_one", version, environment, application_name,
132
- tracer, pricing_info, trace_content, metrics, disable_metrics),
132
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
133
133
  )
134
134
  wrap_function_wrapper(
135
135
  "astrapy.collection",
136
136
  "AsyncCollection.update_many",
137
137
  general_wrap("astra.update_many", version, environment, application_name,
138
- tracer, pricing_info, trace_content, metrics, disable_metrics),
138
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
139
139
  )
140
140
  wrap_function_wrapper(
141
141
  "astrapy.collection",
142
142
  "AsyncCollection.find_one_and_update",
143
143
  general_wrap("astra.find_one_and_update", version, environment, application_name,
144
- tracer, pricing_info, trace_content, metrics, disable_metrics),
144
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
145
145
  )
146
146
  wrap_function_wrapper(
147
147
  "astrapy.collection",
148
148
  "AsyncCollection.find",
149
149
  general_wrap("astra.find", version, environment, application_name,
150
- tracer, pricing_info, trace_content, metrics, disable_metrics),
150
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
151
151
  )
152
152
  wrap_function_wrapper(
153
153
  "astrapy.collection",
154
154
  "AsyncCollection.replace_one",
155
155
  general_wrap("astra.replace_one", version, environment, application_name,
156
- tracer, pricing_info, trace_content, metrics, disable_metrics),
156
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
157
157
  )
158
158
  wrap_function_wrapper(
159
159
  "astrapy.collection",
160
160
  "AsyncCollection.find_one_and_delete",
161
161
  general_wrap("astra.find_one_and_delete", version, environment, application_name,
162
- tracer, pricing_info, trace_content, metrics, disable_metrics),
162
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
163
163
  )
164
164
  wrap_function_wrapper(
165
165
  "astrapy.collection",
166
166
  "AsyncCollection.delete_one",
167
167
  general_wrap("astra.delete_one", version, environment, application_name,
168
- tracer, pricing_info, trace_content, metrics, disable_metrics),
168
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
169
169
  )
170
170
  wrap_function_wrapper(
171
171
  "astrapy.collection",
172
172
  "AsyncCollection.delete_many",
173
173
  general_wrap("astra.delete_many", version, environment, application_name,
174
- tracer, pricing_info, trace_content, metrics, disable_metrics),
174
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
175
175
  )
176
176
 
177
177
  @staticmethod
@@ -20,7 +20,7 @@ def object_count(obj):
20
20
  return len(obj) if obj else None
21
21
 
22
22
  def general_wrap(gen_ai_endpoint, version, environment, application_name,
23
- tracer, pricing_info, trace_content, metrics, disable_metrics):
23
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):
24
24
  """
25
25
  Wraps a AstraDB operation to trace and log its execution metrics.
26
26
 
@@ -37,7 +37,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
37
37
  - application_name (str): The name of the application performing the AstraDB operation.
38
38
  - tracer (opentelemetry.trace.Tracer): An object used for OpenTelemetry tracing.
39
39
  - pricing_info (dict): Information about pricing, not used in current implementation.
40
- - trace_content (bool): A flag indicating whether the content of responses should be traced.
40
+ - capture_message_content (bool): A flag indicating whether the content of responses should be traced.
41
41
 
42
42
  Returns:
43
43
  - function: A decorator function that, when applied, wraps the target function with
@@ -20,7 +20,7 @@ def object_count(obj):
20
20
  return len(obj) if obj else None
21
21
 
22
22
  def general_wrap(gen_ai_endpoint, version, environment, application_name,
23
- tracer, pricing_info, trace_content, metrics, disable_metrics):
23
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):
24
24
  """
25
25
  Wraps a AstraDB operation to trace and log its execution metrics.
26
26
 
@@ -37,7 +37,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
37
37
  - application_name (str): The name of the application performing the AstraDB operation.
38
38
  - tracer (opentelemetry.trace.Tracer): An object used for OpenTelemetry tracing.
39
39
  - pricing_info (dict): Information about pricing, not used in current implementation.
40
- - trace_content (bool): A flag indicating whether the content of responses should be traced.
40
+ - capture_message_content (bool): A flag indicating whether the content of responses should be traced.
41
41
 
42
42
  Returns:
43
43
  - function: A decorator function that, when applied, wraps the target function with
@@ -30,7 +30,7 @@ class AzureAIInferenceInstrumentor(BaseInstrumentor):
30
30
  tracer = kwargs.get("tracer")
31
31
  metrics = kwargs.get("metrics_dict")
32
32
  pricing_info = kwargs.get("pricing_info", {})
33
- trace_content = kwargs.get("trace_content", False)
33
+ capture_message_content = kwargs.get("capture_message_content", False)
34
34
  disable_metrics = kwargs.get("disable_metrics")
35
35
  version = importlib.metadata.version("azure-ai-inference")
36
36
 
@@ -39,7 +39,7 @@ class AzureAIInferenceInstrumentor(BaseInstrumentor):
39
39
  "azure.ai.inference",
40
40
  "ChatCompletionsClient.complete",
41
41
  complete(version, environment, application_name,
42
- tracer, pricing_info, trace_content, metrics, disable_metrics),
42
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
43
43
  )
44
44
 
45
45
  # sync embedding
@@ -47,7 +47,7 @@ class AzureAIInferenceInstrumentor(BaseInstrumentor):
47
47
  "azure.ai.inference",
48
48
  "EmbeddingsClient.embed",
49
49
  embedding(version, environment, application_name,
50
- tracer, pricing_info, trace_content, metrics, disable_metrics),
50
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
51
51
  )
52
52
 
53
53
  # async generate
@@ -55,7 +55,7 @@ class AzureAIInferenceInstrumentor(BaseInstrumentor):
55
55
  "azure.ai.inference.aio",
56
56
  "ChatCompletionsClient.complete",
57
57
  async_complete(version, environment, application_name,
58
- tracer, pricing_info, trace_content, metrics, disable_metrics),
58
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
59
59
  )
60
60
 
61
61
  # async embedding
@@ -63,7 +63,7 @@ class AzureAIInferenceInstrumentor(BaseInstrumentor):
63
63
  "azure.ai.inference.aio",
64
64
  "EmbeddingsClient.embed",
65
65
  async_embedding(version, environment, application_name,
66
- tracer, pricing_info, trace_content, metrics, disable_metrics),
66
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
67
67
  )
68
68
 
69
69
  def _uninstrument(self, **kwargs):
@@ -23,7 +23,7 @@ from openlit.semcov import SemanticConvetion
23
23
  logger = logging.getLogger(__name__)
24
24
 
25
25
  def async_complete(version, environment, application_name,
26
- tracer, pricing_info, trace_content, metrics, disable_metrics):
26
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):
27
27
  """
28
28
  Generates a telemetry wrapper for chat to collect metrics.
29
29
 
@@ -33,7 +33,7 @@ def async_complete(version, environment, application_name,
33
33
  application_name: Name of the application using the Azure AI Inference API.
34
34
  tracer: OpenTelemetry tracer for creating spans.
35
35
  pricing_info: Information used for calculating the cost of Azure AI Inference usage.
36
- trace_content: Flag indicating whether to trace the actual content.
36
+ capture_message_content: Flag indicating whether to trace the actual content.
37
37
 
38
38
  Returns:
39
39
  A function that wraps the chat method to add telemetry.
@@ -217,7 +217,7 @@ def async_complete(version, environment, application_name,
217
217
  self._ttft)
218
218
  self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,
219
219
  version)
220
- if trace_content:
220
+ if capture_message_content:
221
221
  self._span.add_event(
222
222
  name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
223
223
  attributes={
@@ -388,7 +388,7 @@ def async_complete(version, environment, application_name,
388
388
  end_time - start_time)
389
389
  span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,
390
390
  version)
391
- if trace_content:
391
+ if capture_message_content:
392
392
  span.add_event(
393
393
  name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
394
394
  attributes={
@@ -399,7 +399,7 @@ def async_complete(version, environment, application_name,
399
399
  for i in range(kwargs.get('n',1)):
400
400
  span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
401
401
  [response_dict.get('choices')[i].get('finish_reason')])
402
- if trace_content:
402
+ if capture_message_content:
403
403
  span.add_event(
404
404
  name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
405
405
  attributes={
@@ -459,7 +459,7 @@ def async_complete(version, environment, application_name,
459
459
  return wrapper
460
460
 
461
461
  def async_embedding(version, environment, application_name,
462
- tracer, pricing_info, trace_content, metrics, disable_metrics):
462
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):
463
463
  """
464
464
  Generates a telemetry wrapper for embeddings to collect metrics.
465
465
 
@@ -469,7 +469,7 @@ def async_embedding(version, environment, application_name,
469
469
  application_name: Name of the application using the Azure Inference API.
470
470
  tracer: OpenTelemetry tracer for creating spans.
471
471
  pricing_info: Information used for calculating the cost of Azure Inference usage.
472
- trace_content: Flag indicating whether to trace the actual content.
472
+ capture_message_content: Flag indicating whether to trace the actual content.
473
473
 
474
474
  Returns:
475
475
  A function that wraps the embeddings method to add telemetry.
@@ -541,7 +541,7 @@ def async_embedding(version, environment, application_name,
541
541
  span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,
542
542
  version)
543
543
 
544
- if trace_content:
544
+ if capture_message_content:
545
545
  span.add_event(
546
546
  name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
547
547
  attributes={