openlit 1.34.30__py3-none-any.whl → 1.34.31__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openlit/__helpers.py +235 -86
- openlit/__init__.py +16 -13
- openlit/_instrumentors.py +2 -1
- openlit/evals/all.py +50 -21
- openlit/evals/bias_detection.py +47 -20
- openlit/evals/hallucination.py +53 -22
- openlit/evals/toxicity.py +50 -21
- openlit/evals/utils.py +54 -30
- openlit/guard/all.py +61 -19
- openlit/guard/prompt_injection.py +34 -14
- openlit/guard/restrict_topic.py +46 -15
- openlit/guard/sensitive_topic.py +34 -14
- openlit/guard/utils.py +58 -22
- openlit/instrumentation/ag2/__init__.py +24 -8
- openlit/instrumentation/ag2/ag2.py +34 -13
- openlit/instrumentation/ag2/async_ag2.py +34 -13
- openlit/instrumentation/ag2/utils.py +133 -30
- openlit/instrumentation/ai21/__init__.py +43 -14
- openlit/instrumentation/ai21/ai21.py +47 -21
- openlit/instrumentation/ai21/async_ai21.py +47 -21
- openlit/instrumentation/ai21/utils.py +299 -78
- openlit/instrumentation/anthropic/__init__.py +21 -4
- openlit/instrumentation/anthropic/anthropic.py +28 -17
- openlit/instrumentation/anthropic/async_anthropic.py +28 -17
- openlit/instrumentation/anthropic/utils.py +145 -35
- openlit/instrumentation/assemblyai/__init__.py +11 -2
- openlit/instrumentation/assemblyai/assemblyai.py +15 -4
- openlit/instrumentation/assemblyai/utils.py +120 -25
- openlit/instrumentation/astra/__init__.py +43 -10
- openlit/instrumentation/astra/astra.py +28 -5
- openlit/instrumentation/astra/async_astra.py +28 -5
- openlit/instrumentation/astra/utils.py +151 -55
- openlit/instrumentation/azure_ai_inference/__init__.py +43 -10
- openlit/instrumentation/azure_ai_inference/async_azure_ai_inference.py +53 -21
- openlit/instrumentation/azure_ai_inference/azure_ai_inference.py +53 -21
- openlit/instrumentation/azure_ai_inference/utils.py +307 -83
- openlit/instrumentation/bedrock/__init__.py +21 -4
- openlit/instrumentation/bedrock/bedrock.py +63 -25
- openlit/instrumentation/bedrock/utils.py +139 -30
- openlit/instrumentation/chroma/__init__.py +89 -16
- openlit/instrumentation/chroma/chroma.py +28 -6
- openlit/instrumentation/chroma/utils.py +167 -51
- openlit/instrumentation/cohere/__init__.py +63 -18
- openlit/instrumentation/cohere/async_cohere.py +63 -24
- openlit/instrumentation/cohere/cohere.py +63 -24
- openlit/instrumentation/cohere/utils.py +286 -73
- openlit/instrumentation/controlflow/__init__.py +35 -9
- openlit/instrumentation/controlflow/controlflow.py +66 -33
- openlit/instrumentation/crawl4ai/__init__.py +25 -10
- openlit/instrumentation/crawl4ai/async_crawl4ai.py +78 -31
- openlit/instrumentation/crawl4ai/crawl4ai.py +78 -31
- openlit/instrumentation/crewai/__init__.py +40 -15
- openlit/instrumentation/crewai/async_crewai.py +32 -7
- openlit/instrumentation/crewai/crewai.py +32 -7
- openlit/instrumentation/crewai/utils.py +159 -56
- openlit/instrumentation/dynamiq/__init__.py +46 -12
- openlit/instrumentation/dynamiq/dynamiq.py +74 -33
- openlit/instrumentation/elevenlabs/__init__.py +23 -4
- openlit/instrumentation/elevenlabs/async_elevenlabs.py +16 -4
- openlit/instrumentation/elevenlabs/elevenlabs.py +16 -4
- openlit/instrumentation/elevenlabs/utils.py +128 -25
- openlit/instrumentation/embedchain/__init__.py +11 -2
- openlit/instrumentation/embedchain/embedchain.py +68 -35
- openlit/instrumentation/firecrawl/__init__.py +24 -7
- openlit/instrumentation/firecrawl/firecrawl.py +46 -20
- openlit/instrumentation/google_ai_studio/__init__.py +45 -10
- openlit/instrumentation/google_ai_studio/async_google_ai_studio.py +67 -44
- openlit/instrumentation/google_ai_studio/google_ai_studio.py +67 -44
- openlit/instrumentation/google_ai_studio/utils.py +180 -67
- openlit/instrumentation/gpt4all/__init__.py +22 -7
- openlit/instrumentation/gpt4all/gpt4all.py +67 -29
- openlit/instrumentation/gpt4all/utils.py +285 -61
- openlit/instrumentation/gpu/__init__.py +128 -47
- openlit/instrumentation/groq/__init__.py +21 -4
- openlit/instrumentation/groq/async_groq.py +33 -21
- openlit/instrumentation/groq/groq.py +33 -21
- openlit/instrumentation/groq/utils.py +192 -55
- openlit/instrumentation/haystack/__init__.py +70 -24
- openlit/instrumentation/haystack/async_haystack.py +28 -6
- openlit/instrumentation/haystack/haystack.py +28 -6
- openlit/instrumentation/haystack/utils.py +196 -74
- openlit/instrumentation/julep/__init__.py +69 -19
- openlit/instrumentation/julep/async_julep.py +53 -27
- openlit/instrumentation/julep/julep.py +53 -28
- openlit/instrumentation/langchain/__init__.py +74 -63
- openlit/instrumentation/langchain/callback_handler.py +1100 -0
- openlit/instrumentation/langchain_community/__init__.py +13 -2
- openlit/instrumentation/langchain_community/async_langchain_community.py +23 -5
- openlit/instrumentation/langchain_community/langchain_community.py +23 -5
- openlit/instrumentation/langchain_community/utils.py +35 -9
- openlit/instrumentation/letta/__init__.py +68 -15
- openlit/instrumentation/letta/letta.py +99 -54
- openlit/instrumentation/litellm/__init__.py +43 -14
- openlit/instrumentation/litellm/async_litellm.py +51 -26
- openlit/instrumentation/litellm/litellm.py +51 -26
- openlit/instrumentation/litellm/utils.py +304 -102
- openlit/instrumentation/llamaindex/__init__.py +267 -90
- openlit/instrumentation/llamaindex/async_llamaindex.py +28 -6
- openlit/instrumentation/llamaindex/llamaindex.py +28 -6
- openlit/instrumentation/llamaindex/utils.py +204 -91
- openlit/instrumentation/mem0/__init__.py +11 -2
- openlit/instrumentation/mem0/mem0.py +50 -29
- openlit/instrumentation/milvus/__init__.py +10 -2
- openlit/instrumentation/milvus/milvus.py +31 -6
- openlit/instrumentation/milvus/utils.py +166 -67
- openlit/instrumentation/mistral/__init__.py +63 -18
- openlit/instrumentation/mistral/async_mistral.py +63 -24
- openlit/instrumentation/mistral/mistral.py +63 -24
- openlit/instrumentation/mistral/utils.py +277 -69
- openlit/instrumentation/multion/__init__.py +69 -19
- openlit/instrumentation/multion/async_multion.py +57 -26
- openlit/instrumentation/multion/multion.py +57 -26
- openlit/instrumentation/ollama/__init__.py +39 -18
- openlit/instrumentation/ollama/async_ollama.py +57 -26
- openlit/instrumentation/ollama/ollama.py +57 -26
- openlit/instrumentation/ollama/utils.py +226 -50
- openlit/instrumentation/openai/__init__.py +156 -32
- openlit/instrumentation/openai/async_openai.py +147 -67
- openlit/instrumentation/openai/openai.py +150 -67
- openlit/instrumentation/openai/utils.py +657 -185
- openlit/instrumentation/openai_agents/__init__.py +5 -1
- openlit/instrumentation/openai_agents/processor.py +110 -90
- openlit/instrumentation/phidata/__init__.py +13 -5
- openlit/instrumentation/phidata/phidata.py +67 -32
- openlit/instrumentation/pinecone/__init__.py +48 -9
- openlit/instrumentation/pinecone/async_pinecone.py +27 -5
- openlit/instrumentation/pinecone/pinecone.py +27 -5
- openlit/instrumentation/pinecone/utils.py +153 -47
- openlit/instrumentation/premai/__init__.py +22 -7
- openlit/instrumentation/premai/premai.py +51 -26
- openlit/instrumentation/premai/utils.py +246 -59
- openlit/instrumentation/pydantic_ai/__init__.py +49 -22
- openlit/instrumentation/pydantic_ai/pydantic_ai.py +69 -16
- openlit/instrumentation/pydantic_ai/utils.py +89 -24
- openlit/instrumentation/qdrant/__init__.py +19 -4
- openlit/instrumentation/qdrant/async_qdrant.py +33 -7
- openlit/instrumentation/qdrant/qdrant.py +33 -7
- openlit/instrumentation/qdrant/utils.py +228 -93
- openlit/instrumentation/reka/__init__.py +23 -10
- openlit/instrumentation/reka/async_reka.py +17 -11
- openlit/instrumentation/reka/reka.py +17 -11
- openlit/instrumentation/reka/utils.py +138 -36
- openlit/instrumentation/together/__init__.py +44 -12
- openlit/instrumentation/together/async_together.py +50 -27
- openlit/instrumentation/together/together.py +50 -27
- openlit/instrumentation/together/utils.py +301 -71
- openlit/instrumentation/transformers/__init__.py +2 -1
- openlit/instrumentation/transformers/transformers.py +13 -3
- openlit/instrumentation/transformers/utils.py +139 -36
- openlit/instrumentation/vertexai/__init__.py +81 -16
- openlit/instrumentation/vertexai/async_vertexai.py +33 -15
- openlit/instrumentation/vertexai/utils.py +123 -27
- openlit/instrumentation/vertexai/vertexai.py +33 -15
- openlit/instrumentation/vllm/__init__.py +12 -5
- openlit/instrumentation/vllm/utils.py +121 -31
- openlit/instrumentation/vllm/vllm.py +16 -10
- openlit/otel/events.py +35 -10
- openlit/otel/metrics.py +32 -24
- openlit/otel/tracing.py +24 -9
- openlit/semcov/__init__.py +72 -6
- {openlit-1.34.30.dist-info → openlit-1.34.31.dist-info}/METADATA +2 -1
- openlit-1.34.31.dist-info/RECORD +166 -0
- openlit/instrumentation/langchain/async_langchain.py +0 -102
- openlit/instrumentation/langchain/langchain.py +0 -102
- openlit/instrumentation/langchain/utils.py +0 -252
- openlit-1.34.30.dist-info/RECORD +0 -168
- {openlit-1.34.30.dist-info → openlit-1.34.31.dist-info}/LICENSE +0 -0
- {openlit-1.34.30.dist-info → openlit-1.34.31.dist-info}/WHEEL +0 -0
@@ -4,10 +4,7 @@ Module for monitoring Amazon Bedrock API calls.
|
|
4
4
|
|
5
5
|
import time
|
6
6
|
from opentelemetry.trace import SpanKind
|
7
|
-
from openlit.__helpers import
|
8
|
-
handle_exception,
|
9
|
-
set_server_address_and_port
|
10
|
-
)
|
7
|
+
from openlit.__helpers import handle_exception, set_server_address_and_port
|
11
8
|
from openlit.instrumentation.bedrock.utils import (
|
12
9
|
process_chunk,
|
13
10
|
process_chat_response,
|
@@ -15,7 +12,17 @@ from openlit.instrumentation.bedrock.utils import (
|
|
15
12
|
)
|
16
13
|
from openlit.semcov import SemanticConvention
|
17
14
|
|
18
|
-
|
15
|
+
|
16
|
+
def converse(
|
17
|
+
version,
|
18
|
+
environment,
|
19
|
+
application_name,
|
20
|
+
tracer,
|
21
|
+
pricing_info,
|
22
|
+
capture_message_content,
|
23
|
+
metrics,
|
24
|
+
disable_metrics,
|
25
|
+
):
|
19
26
|
"""
|
20
27
|
Generates a telemetry wrapper for AWS Bedrock converse calls.
|
21
28
|
"""
|
@@ -30,10 +37,14 @@ def converse(version, environment, application_name, tracer, pricing_info, captu
|
|
30
37
|
Wraps the individual converse method call.
|
31
38
|
"""
|
32
39
|
|
33
|
-
server_address, server_port = set_server_address_and_port(
|
40
|
+
server_address, server_port = set_server_address_and_port(
|
41
|
+
instance, "aws.amazon.com", 443
|
42
|
+
)
|
34
43
|
request_model = method_kwargs.get("modelId", "amazon.titan-text-express-v1")
|
35
44
|
|
36
|
-
span_name =
|
45
|
+
span_name = (
|
46
|
+
f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
|
47
|
+
)
|
37
48
|
|
38
49
|
with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
|
39
50
|
start_time = time.time()
|
@@ -56,7 +67,7 @@ def converse(version, environment, application_name, tracer, pricing_info, captu
|
|
56
67
|
disable_metrics=disable_metrics,
|
57
68
|
version=version,
|
58
69
|
llm_config=llm_config,
|
59
|
-
**method_kwargs
|
70
|
+
**method_kwargs,
|
60
71
|
)
|
61
72
|
|
62
73
|
except Exception as e:
|
@@ -70,13 +81,25 @@ def converse(version, environment, application_name, tracer, pricing_info, captu
|
|
70
81
|
# Replace the original method with the instrumented one
|
71
82
|
if kwargs.get("service_name") == "bedrock-runtime":
|
72
83
|
original_invoke_model = client.converse
|
73
|
-
client.converse = lambda *args, **kwargs: converse_wrapper(
|
84
|
+
client.converse = lambda *args, **kwargs: converse_wrapper(
|
85
|
+
original_invoke_model, *args, **kwargs
|
86
|
+
)
|
74
87
|
|
75
88
|
return client
|
76
89
|
|
77
90
|
return wrapper
|
78
91
|
|
79
|
-
|
92
|
+
|
93
|
+
def converse_stream(
|
94
|
+
version,
|
95
|
+
environment,
|
96
|
+
application_name,
|
97
|
+
tracer,
|
98
|
+
pricing_info,
|
99
|
+
capture_message_content,
|
100
|
+
metrics,
|
101
|
+
disable_metrics,
|
102
|
+
):
|
80
103
|
"""
|
81
104
|
Generates a telemetry wrapper for AWS Bedrock converse_stream calls.
|
82
105
|
"""
|
@@ -87,15 +110,15 @@ def converse_stream(version, environment, application_name, tracer, pricing_info
|
|
87
110
|
"""
|
88
111
|
|
89
112
|
def __init__(
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
113
|
+
self,
|
114
|
+
wrapped_response,
|
115
|
+
span,
|
116
|
+
span_name,
|
117
|
+
kwargs,
|
118
|
+
server_address,
|
119
|
+
server_port,
|
120
|
+
**args,
|
121
|
+
):
|
99
122
|
self.__wrapped_response = wrapped_response
|
100
123
|
# Extract the actual stream iterator from the response
|
101
124
|
if isinstance(wrapped_response, dict) and "stream" in wrapped_response:
|
@@ -159,7 +182,9 @@ def converse_stream(version, environment, application_name, tracer, pricing_info
|
|
159
182
|
except StopIteration:
|
160
183
|
try:
|
161
184
|
llm_config = self._kwargs.get("inferenceConfig", {})
|
162
|
-
with tracer.start_as_current_span(
|
185
|
+
with tracer.start_as_current_span(
|
186
|
+
self._span_name, kind=SpanKind.CLIENT
|
187
|
+
) as self._span:
|
163
188
|
process_streaming_chat_response(
|
164
189
|
self,
|
165
190
|
pricing_info=pricing_info,
|
@@ -169,7 +194,7 @@ def converse_stream(version, environment, application_name, tracer, pricing_info
|
|
169
194
|
capture_message_content=capture_message_content,
|
170
195
|
disable_metrics=disable_metrics,
|
171
196
|
version=version,
|
172
|
-
llm_config=llm_config
|
197
|
+
llm_config=llm_config,
|
173
198
|
)
|
174
199
|
|
175
200
|
except Exception as e:
|
@@ -187,16 +212,27 @@ def converse_stream(version, environment, application_name, tracer, pricing_info
|
|
187
212
|
Wraps the individual converse_stream method call.
|
188
213
|
"""
|
189
214
|
|
190
|
-
server_address, server_port = set_server_address_and_port(
|
215
|
+
server_address, server_port = set_server_address_and_port(
|
216
|
+
instance, "aws.amazon.com", 443
|
217
|
+
)
|
191
218
|
request_model = method_kwargs.get("modelId", "amazon.titan-text-express-v1")
|
192
219
|
|
193
|
-
span_name =
|
220
|
+
span_name = (
|
221
|
+
f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
|
222
|
+
)
|
194
223
|
|
195
224
|
# Get the streaming response
|
196
225
|
stream_response = original_method(*method_args, **method_kwargs)
|
197
226
|
span = tracer.start_span(span_name, kind=SpanKind.CLIENT)
|
198
227
|
|
199
|
-
return TracedSyncStream(
|
228
|
+
return TracedSyncStream(
|
229
|
+
stream_response,
|
230
|
+
span,
|
231
|
+
span_name,
|
232
|
+
method_kwargs,
|
233
|
+
server_address,
|
234
|
+
server_port,
|
235
|
+
)
|
200
236
|
|
201
237
|
# Get the original client instance from the wrapper
|
202
238
|
client = wrapped(*args, **kwargs)
|
@@ -204,7 +240,9 @@ def converse_stream(version, environment, application_name, tracer, pricing_info
|
|
204
240
|
# Replace the original method with the instrumented one
|
205
241
|
if kwargs.get("service_name") == "bedrock-runtime":
|
206
242
|
original_stream_model = client.converse_stream
|
207
|
-
client.converse_stream = lambda *args, **kwargs: converse_stream_wrapper(
|
243
|
+
client.converse_stream = lambda *args, **kwargs: converse_stream_wrapper(
|
244
|
+
original_stream_model, *args, **kwargs
|
245
|
+
)
|
208
246
|
|
209
247
|
return client
|
210
248
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"""
|
2
2
|
AWS Bedrock OpenTelemetry instrumentation utility functions
|
3
3
|
"""
|
4
|
+
|
4
5
|
import time
|
5
6
|
|
6
7
|
from opentelemetry.trace import Status, StatusCode
|
@@ -12,10 +13,11 @@ from openlit.__helpers import (
|
|
12
13
|
get_chat_model_cost,
|
13
14
|
record_completion_metrics,
|
14
15
|
common_span_attributes,
|
15
|
-
handle_exception
|
16
|
+
handle_exception,
|
16
17
|
)
|
17
18
|
from openlit.semcov import SemanticConvention
|
18
19
|
|
20
|
+
|
19
21
|
def format_content(messages):
|
20
22
|
"""
|
21
23
|
Format the messages into a string for span events.
|
@@ -52,6 +54,7 @@ def format_content(messages):
|
|
52
54
|
|
53
55
|
return "\n".join(formatted_messages)
|
54
56
|
|
57
|
+
|
55
58
|
def process_chunk(self, chunk):
|
56
59
|
"""
|
57
60
|
Process a chunk of response data and update state.
|
@@ -92,8 +95,19 @@ def process_chunk(self, chunk):
|
|
92
95
|
self._output_tokens = usage.get("outputTokens", 0)
|
93
96
|
self._end_time = end_time
|
94
97
|
|
95
|
-
|
96
|
-
|
98
|
+
|
99
|
+
def common_chat_logic(
|
100
|
+
scope,
|
101
|
+
pricing_info,
|
102
|
+
environment,
|
103
|
+
application_name,
|
104
|
+
metrics,
|
105
|
+
capture_message_content,
|
106
|
+
disable_metrics,
|
107
|
+
version,
|
108
|
+
llm_config,
|
109
|
+
is_stream,
|
110
|
+
):
|
97
111
|
"""
|
98
112
|
Process chat request and generate Telemetry
|
99
113
|
"""
|
@@ -105,13 +119,26 @@ def common_chat_logic(scope, pricing_info, environment, application_name, metric
|
|
105
119
|
formatted_messages = format_content(scope._kwargs.get("messages", []))
|
106
120
|
request_model = scope._kwargs.get("modelId", "amazon.titan-text-express-v1")
|
107
121
|
|
108
|
-
cost = get_chat_model_cost(
|
122
|
+
cost = get_chat_model_cost(
|
123
|
+
request_model, pricing_info, scope._input_tokens, scope._output_tokens
|
124
|
+
)
|
109
125
|
|
110
126
|
# Common Span Attributes
|
111
|
-
common_span_attributes(
|
112
|
-
|
113
|
-
|
114
|
-
|
127
|
+
common_span_attributes(
|
128
|
+
scope,
|
129
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,
|
130
|
+
SemanticConvention.GEN_AI_SYSTEM_AWS_BEDROCK,
|
131
|
+
scope._server_address,
|
132
|
+
scope._server_port,
|
133
|
+
request_model,
|
134
|
+
scope._response_model,
|
135
|
+
environment,
|
136
|
+
application_name,
|
137
|
+
is_stream,
|
138
|
+
scope._tbt,
|
139
|
+
scope._ttft,
|
140
|
+
version,
|
141
|
+
)
|
115
142
|
|
116
143
|
# Bedrock-specific attributes from llm_config
|
117
144
|
bedrock_attributes = [
|
@@ -132,19 +159,35 @@ def common_chat_logic(scope, pricing_info, environment, application_name, metric
|
|
132
159
|
|
133
160
|
# Span Attributes for Response parameters
|
134
161
|
scope._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID, scope._response_id)
|
135
|
-
scope._span.set_attribute(
|
136
|
-
|
162
|
+
scope._span.set_attribute(
|
163
|
+
SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON, [scope._finish_reason]
|
164
|
+
)
|
165
|
+
scope._span.set_attribute(
|
166
|
+
SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
167
|
+
"text" if isinstance(scope._llmresponse, str) else "json",
|
168
|
+
)
|
137
169
|
|
138
170
|
# Span Attributes for Cost and Tokens
|
139
|
-
scope._span.set_attribute(
|
140
|
-
|
141
|
-
|
171
|
+
scope._span.set_attribute(
|
172
|
+
SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS, scope._input_tokens
|
173
|
+
)
|
174
|
+
scope._span.set_attribute(
|
175
|
+
SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS, scope._output_tokens
|
176
|
+
)
|
177
|
+
scope._span.set_attribute(
|
178
|
+
SemanticConvention.GEN_AI_CLIENT_TOKEN_USAGE,
|
179
|
+
scope._input_tokens + scope._output_tokens,
|
180
|
+
)
|
142
181
|
scope._span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST, cost)
|
143
182
|
|
144
183
|
# Span Attributes for Content
|
145
184
|
if capture_message_content:
|
146
|
-
scope._span.set_attribute(
|
147
|
-
|
185
|
+
scope._span.set_attribute(
|
186
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT, formatted_messages
|
187
|
+
)
|
188
|
+
scope._span.set_attribute(
|
189
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION, scope._llmresponse
|
190
|
+
)
|
148
191
|
|
149
192
|
# To be removed once the change to span_attributes (from span events) is complete
|
150
193
|
scope._span.add_event(
|
@@ -164,13 +207,37 @@ def common_chat_logic(scope, pricing_info, environment, application_name, metric
|
|
164
207
|
|
165
208
|
# Record metrics
|
166
209
|
if not disable_metrics:
|
167
|
-
record_completion_metrics(
|
168
|
-
|
169
|
-
|
170
|
-
|
210
|
+
record_completion_metrics(
|
211
|
+
metrics,
|
212
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,
|
213
|
+
SemanticConvention.GEN_AI_SYSTEM_AWS_BEDROCK,
|
214
|
+
scope._server_address,
|
215
|
+
scope._server_port,
|
216
|
+
request_model,
|
217
|
+
scope._response_model,
|
218
|
+
environment,
|
219
|
+
application_name,
|
220
|
+
scope._start_time,
|
221
|
+
scope._end_time,
|
222
|
+
scope._input_tokens,
|
223
|
+
scope._output_tokens,
|
224
|
+
cost,
|
225
|
+
scope._tbt,
|
226
|
+
scope._ttft,
|
227
|
+
)
|
171
228
|
|
172
|
-
|
173
|
-
|
229
|
+
|
230
|
+
def process_streaming_chat_response(
|
231
|
+
scope,
|
232
|
+
pricing_info,
|
233
|
+
environment,
|
234
|
+
application_name,
|
235
|
+
metrics,
|
236
|
+
capture_message_content=False,
|
237
|
+
disable_metrics=False,
|
238
|
+
version="",
|
239
|
+
llm_config=None,
|
240
|
+
):
|
174
241
|
"""
|
175
242
|
Process streaming chat response and generate telemetry.
|
176
243
|
"""
|
@@ -179,15 +246,40 @@ def process_streaming_chat_response(scope, pricing_info, environment, applicatio
|
|
179
246
|
if llm_config is None:
|
180
247
|
llm_config = {}
|
181
248
|
|
182
|
-
common_chat_logic(
|
183
|
-
|
249
|
+
common_chat_logic(
|
250
|
+
scope,
|
251
|
+
pricing_info,
|
252
|
+
environment,
|
253
|
+
application_name,
|
254
|
+
metrics,
|
255
|
+
capture_message_content,
|
256
|
+
disable_metrics,
|
257
|
+
version,
|
258
|
+
llm_config,
|
259
|
+
is_stream=True,
|
260
|
+
)
|
184
261
|
except Exception as e:
|
185
262
|
handle_exception(scope._span, e)
|
186
263
|
raise
|
187
264
|
|
188
|
-
|
189
|
-
|
190
|
-
|
265
|
+
|
266
|
+
def process_chat_response(
|
267
|
+
response,
|
268
|
+
request_model,
|
269
|
+
pricing_info,
|
270
|
+
server_port,
|
271
|
+
server_address,
|
272
|
+
environment,
|
273
|
+
application_name,
|
274
|
+
metrics,
|
275
|
+
start_time,
|
276
|
+
span,
|
277
|
+
capture_message_content=False,
|
278
|
+
disable_metrics=False,
|
279
|
+
version="1.0.0",
|
280
|
+
llm_config=None,
|
281
|
+
**kwargs,
|
282
|
+
):
|
191
283
|
"""
|
192
284
|
Process non-streaming chat response and generate telemetry.
|
193
285
|
"""
|
@@ -202,8 +294,15 @@ def process_chat_response(response, request_model, pricing_info, server_port, se
|
|
202
294
|
scope._start_time = start_time
|
203
295
|
scope._end_time = time.time()
|
204
296
|
scope._span = span
|
205
|
-
scope._llmresponse =
|
206
|
-
|
297
|
+
scope._llmresponse = (
|
298
|
+
response_dict.get("output", {})
|
299
|
+
.get("message", {})
|
300
|
+
.get("content", [{}])[0]
|
301
|
+
.get("text", "")
|
302
|
+
)
|
303
|
+
scope._response_role = (
|
304
|
+
response_dict.get("output", {}).get("message", {}).get("role", "assistant")
|
305
|
+
)
|
207
306
|
scope._input_tokens = response_dict.get("usage", {}).get("inputTokens", 0)
|
208
307
|
scope._output_tokens = response_dict.get("usage", {}).get("outputTokens", 0)
|
209
308
|
scope._response_model = request_model
|
@@ -214,8 +313,18 @@ def process_chat_response(response, request_model, pricing_info, server_port, se
|
|
214
313
|
scope._server_address, scope._server_port = server_address, server_port
|
215
314
|
scope._kwargs = kwargs
|
216
315
|
|
217
|
-
common_chat_logic(
|
218
|
-
|
316
|
+
common_chat_logic(
|
317
|
+
scope,
|
318
|
+
pricing_info,
|
319
|
+
environment,
|
320
|
+
application_name,
|
321
|
+
metrics,
|
322
|
+
capture_message_content,
|
323
|
+
disable_metrics,
|
324
|
+
version,
|
325
|
+
llm_config,
|
326
|
+
is_stream=False,
|
327
|
+
)
|
219
328
|
|
220
329
|
return response
|
221
330
|
except Exception as e:
|
@@ -11,6 +11,7 @@ from openlit.instrumentation.chroma.chroma import general_wrap
|
|
11
11
|
|
12
12
|
_instruments = ("chromadb >= 0.4.0",)
|
13
13
|
|
14
|
+
|
14
15
|
class ChromaInstrumentor(BaseInstrumentor):
|
15
16
|
"""
|
16
17
|
An instrumentor for ChromaDB client library.
|
@@ -33,57 +34,129 @@ class ChromaInstrumentor(BaseInstrumentor):
|
|
33
34
|
wrap_function_wrapper(
|
34
35
|
"chromadb.db",
|
35
36
|
"DB.create_collection",
|
36
|
-
general_wrap(
|
37
|
-
|
37
|
+
general_wrap(
|
38
|
+
"chroma.create_collection",
|
39
|
+
version,
|
40
|
+
environment,
|
41
|
+
application_name,
|
42
|
+
tracer,
|
43
|
+
pricing_info,
|
44
|
+
capture_message_content,
|
45
|
+
metrics,
|
46
|
+
disable_metrics,
|
47
|
+
),
|
38
48
|
)
|
39
49
|
|
40
50
|
wrap_function_wrapper(
|
41
51
|
"chromadb",
|
42
52
|
"Collection.add",
|
43
|
-
general_wrap(
|
44
|
-
|
53
|
+
general_wrap(
|
54
|
+
"chroma.add",
|
55
|
+
version,
|
56
|
+
environment,
|
57
|
+
application_name,
|
58
|
+
tracer,
|
59
|
+
pricing_info,
|
60
|
+
capture_message_content,
|
61
|
+
metrics,
|
62
|
+
disable_metrics,
|
63
|
+
),
|
45
64
|
)
|
46
65
|
|
47
66
|
wrap_function_wrapper(
|
48
67
|
"chromadb",
|
49
68
|
"Collection.get",
|
50
|
-
general_wrap(
|
51
|
-
|
69
|
+
general_wrap(
|
70
|
+
"chroma.get",
|
71
|
+
version,
|
72
|
+
environment,
|
73
|
+
application_name,
|
74
|
+
tracer,
|
75
|
+
pricing_info,
|
76
|
+
capture_message_content,
|
77
|
+
metrics,
|
78
|
+
disable_metrics,
|
79
|
+
),
|
52
80
|
)
|
53
81
|
|
54
82
|
wrap_function_wrapper(
|
55
83
|
"chromadb",
|
56
84
|
"Collection.peek",
|
57
|
-
general_wrap(
|
58
|
-
|
85
|
+
general_wrap(
|
86
|
+
"chroma.peek",
|
87
|
+
version,
|
88
|
+
environment,
|
89
|
+
application_name,
|
90
|
+
tracer,
|
91
|
+
pricing_info,
|
92
|
+
capture_message_content,
|
93
|
+
metrics,
|
94
|
+
disable_metrics,
|
95
|
+
),
|
59
96
|
)
|
60
97
|
|
61
98
|
wrap_function_wrapper(
|
62
99
|
"chromadb",
|
63
100
|
"Collection.query",
|
64
|
-
general_wrap(
|
65
|
-
|
101
|
+
general_wrap(
|
102
|
+
"chroma.query",
|
103
|
+
version,
|
104
|
+
environment,
|
105
|
+
application_name,
|
106
|
+
tracer,
|
107
|
+
pricing_info,
|
108
|
+
capture_message_content,
|
109
|
+
metrics,
|
110
|
+
disable_metrics,
|
111
|
+
),
|
66
112
|
)
|
67
113
|
|
68
114
|
wrap_function_wrapper(
|
69
115
|
"chromadb",
|
70
116
|
"Collection.update",
|
71
|
-
general_wrap(
|
72
|
-
|
117
|
+
general_wrap(
|
118
|
+
"chroma.update",
|
119
|
+
version,
|
120
|
+
environment,
|
121
|
+
application_name,
|
122
|
+
tracer,
|
123
|
+
pricing_info,
|
124
|
+
capture_message_content,
|
125
|
+
metrics,
|
126
|
+
disable_metrics,
|
127
|
+
),
|
73
128
|
)
|
74
129
|
|
75
130
|
wrap_function_wrapper(
|
76
131
|
"chromadb",
|
77
132
|
"Collection.upsert",
|
78
|
-
general_wrap(
|
79
|
-
|
133
|
+
general_wrap(
|
134
|
+
"chroma.upsert",
|
135
|
+
version,
|
136
|
+
environment,
|
137
|
+
application_name,
|
138
|
+
tracer,
|
139
|
+
pricing_info,
|
140
|
+
capture_message_content,
|
141
|
+
metrics,
|
142
|
+
disable_metrics,
|
143
|
+
),
|
80
144
|
)
|
81
145
|
|
82
146
|
wrap_function_wrapper(
|
83
147
|
"chromadb",
|
84
148
|
"Collection.delete",
|
85
|
-
general_wrap(
|
86
|
-
|
149
|
+
general_wrap(
|
150
|
+
"chroma.delete",
|
151
|
+
version,
|
152
|
+
environment,
|
153
|
+
application_name,
|
154
|
+
tracer,
|
155
|
+
pricing_info,
|
156
|
+
capture_message_content,
|
157
|
+
metrics,
|
158
|
+
disable_metrics,
|
159
|
+
),
|
87
160
|
)
|
88
161
|
|
89
162
|
def _uninstrument(self, **kwargs):
|
@@ -12,8 +12,18 @@ from openlit.instrumentation.chroma.utils import (
|
|
12
12
|
set_server_address_and_port,
|
13
13
|
)
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
|
16
|
+
def general_wrap(
|
17
|
+
gen_ai_endpoint,
|
18
|
+
version,
|
19
|
+
environment,
|
20
|
+
application_name,
|
21
|
+
tracer,
|
22
|
+
pricing_info,
|
23
|
+
capture_message_content,
|
24
|
+
metrics,
|
25
|
+
disable_metrics,
|
26
|
+
):
|
17
27
|
"""
|
18
28
|
Generates a telemetry wrapper for ChromaDB function calls.
|
19
29
|
"""
|
@@ -43,9 +53,22 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
43
53
|
try:
|
44
54
|
# Process response and generate telemetry
|
45
55
|
response = process_vectordb_response(
|
46
|
-
response,
|
47
|
-
|
48
|
-
|
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
|
+
endpoint=gen_ai_endpoint,
|
71
|
+
**kwargs,
|
49
72
|
)
|
50
73
|
|
51
74
|
except Exception as e:
|
@@ -53,5 +76,4 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
53
76
|
|
54
77
|
return response
|
55
78
|
|
56
|
-
|
57
79
|
return wrapper
|