openlit 1.33.8__py3-none-any.whl → 1.33.10__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 +88 -0
- openlit/__init__.py +4 -3
- openlit/instrumentation/ag2/ag2.py +5 -5
- openlit/instrumentation/ai21/__init__.py +4 -4
- openlit/instrumentation/ai21/ai21.py +370 -319
- openlit/instrumentation/ai21/async_ai21.py +371 -319
- openlit/instrumentation/anthropic/__init__.py +4 -4
- openlit/instrumentation/anthropic/anthropic.py +321 -189
- openlit/instrumentation/anthropic/async_anthropic.py +323 -190
- openlit/instrumentation/assemblyai/__init__.py +1 -1
- openlit/instrumentation/assemblyai/assemblyai.py +59 -43
- openlit/instrumentation/astra/astra.py +9 -9
- openlit/instrumentation/astra/async_astra.py +9 -9
- openlit/instrumentation/azure_ai_inference/__init__.py +4 -4
- openlit/instrumentation/azure_ai_inference/async_azure_ai_inference.py +406 -252
- openlit/instrumentation/azure_ai_inference/azure_ai_inference.py +406 -252
- openlit/instrumentation/bedrock/__init__.py +1 -1
- openlit/instrumentation/bedrock/bedrock.py +115 -58
- openlit/instrumentation/chroma/chroma.py +9 -9
- openlit/instrumentation/cohere/__init__.py +33 -10
- openlit/instrumentation/cohere/async_cohere.py +610 -0
- openlit/instrumentation/cohere/cohere.py +410 -219
- openlit/instrumentation/controlflow/controlflow.py +5 -5
- openlit/instrumentation/crawl4ai/async_crawl4ai.py +5 -5
- openlit/instrumentation/crawl4ai/crawl4ai.py +5 -5
- openlit/instrumentation/crewai/crewai.py +6 -4
- openlit/instrumentation/dynamiq/dynamiq.py +5 -5
- openlit/instrumentation/elevenlabs/async_elevenlabs.py +71 -46
- openlit/instrumentation/elevenlabs/elevenlabs.py +71 -51
- openlit/instrumentation/embedchain/embedchain.py +9 -9
- openlit/instrumentation/firecrawl/firecrawl.py +5 -5
- openlit/instrumentation/google_ai_studio/__init__.py +9 -9
- openlit/instrumentation/google_ai_studio/async_google_ai_studio.py +183 -219
- openlit/instrumentation/google_ai_studio/google_ai_studio.py +183 -220
- openlit/instrumentation/gpt4all/__init__.py +2 -2
- openlit/instrumentation/gpt4all/gpt4all.py +345 -220
- openlit/instrumentation/gpu/__init__.py +5 -5
- openlit/instrumentation/groq/__init__.py +2 -2
- openlit/instrumentation/groq/async_groq.py +356 -240
- openlit/instrumentation/groq/groq.py +356 -240
- openlit/instrumentation/haystack/haystack.py +5 -5
- openlit/instrumentation/julep/async_julep.py +5 -5
- openlit/instrumentation/julep/julep.py +5 -5
- openlit/instrumentation/langchain/__init__.py +13 -7
- openlit/instrumentation/langchain/async_langchain.py +384 -0
- openlit/instrumentation/langchain/langchain.py +105 -492
- openlit/instrumentation/letta/letta.py +11 -9
- openlit/instrumentation/litellm/__init__.py +4 -5
- openlit/instrumentation/litellm/async_litellm.py +318 -247
- openlit/instrumentation/litellm/litellm.py +314 -243
- openlit/instrumentation/llamaindex/llamaindex.py +5 -5
- openlit/instrumentation/mem0/mem0.py +5 -5
- openlit/instrumentation/milvus/milvus.py +9 -9
- openlit/instrumentation/mistral/__init__.py +6 -6
- openlit/instrumentation/mistral/async_mistral.py +423 -250
- openlit/instrumentation/mistral/mistral.py +420 -246
- openlit/instrumentation/multion/async_multion.py +6 -4
- openlit/instrumentation/multion/multion.py +6 -4
- openlit/instrumentation/ollama/__init__.py +8 -30
- openlit/instrumentation/ollama/async_ollama.py +385 -417
- openlit/instrumentation/ollama/ollama.py +384 -417
- openlit/instrumentation/openai/__init__.py +11 -230
- openlit/instrumentation/openai/async_openai.py +433 -410
- openlit/instrumentation/openai/openai.py +414 -394
- openlit/instrumentation/phidata/phidata.py +6 -4
- openlit/instrumentation/pinecone/pinecone.py +9 -9
- openlit/instrumentation/premai/__init__.py +2 -2
- openlit/instrumentation/premai/premai.py +262 -213
- openlit/instrumentation/qdrant/async_qdrant.py +9 -9
- openlit/instrumentation/qdrant/qdrant.py +9 -9
- openlit/instrumentation/reka/__init__.py +2 -2
- openlit/instrumentation/reka/async_reka.py +90 -52
- openlit/instrumentation/reka/reka.py +90 -52
- openlit/instrumentation/together/__init__.py +4 -4
- openlit/instrumentation/together/async_together.py +278 -236
- openlit/instrumentation/together/together.py +278 -236
- openlit/instrumentation/transformers/__init__.py +1 -1
- openlit/instrumentation/transformers/transformers.py +76 -45
- openlit/instrumentation/vertexai/__init__.py +14 -64
- openlit/instrumentation/vertexai/async_vertexai.py +330 -987
- openlit/instrumentation/vertexai/vertexai.py +330 -987
- openlit/instrumentation/vllm/__init__.py +1 -1
- openlit/instrumentation/vllm/vllm.py +66 -36
- openlit/otel/metrics.py +98 -7
- openlit/semcov/__init__.py +113 -80
- {openlit-1.33.8.dist-info → openlit-1.33.10.dist-info}/METADATA +1 -1
- openlit-1.33.10.dist-info/RECORD +122 -0
- {openlit-1.33.8.dist-info → openlit-1.33.10.dist-info}/WHEEL +1 -1
- openlit/instrumentation/openai/async_azure_openai.py +0 -900
- openlit/instrumentation/openai/azure_openai.py +0 -898
- openlit-1.33.8.dist-info/RECORD +0 -122
- {openlit-1.33.8.dist-info → openlit-1.33.10.dist-info}/LICENSE +0 -0
@@ -28,7 +28,7 @@ class TransformersInstrumentor(BaseInstrumentor):
|
|
28
28
|
wrap_function_wrapper(
|
29
29
|
"transformers",
|
30
30
|
"TextGenerationPipeline.__call__",
|
31
|
-
text_wrap(
|
31
|
+
text_wrap(version, environment, application_name,
|
32
32
|
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
33
33
|
)
|
34
34
|
|
@@ -1,18 +1,24 @@
|
|
1
|
-
# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument
|
2
1
|
"""
|
3
2
|
Module for monitoring ChromaDB.
|
4
3
|
"""
|
5
4
|
|
6
5
|
import logging
|
6
|
+
import time
|
7
7
|
from opentelemetry.trace import SpanKind, Status, StatusCode
|
8
|
-
from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
|
9
|
-
from openlit.__helpers import
|
8
|
+
from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
|
9
|
+
from openlit.__helpers import (
|
10
|
+
get_chat_model_cost,
|
11
|
+
handle_exception,
|
12
|
+
general_tokens,
|
13
|
+
create_metrics_attributes,
|
14
|
+
set_server_address_and_port
|
15
|
+
)
|
10
16
|
from openlit.semcov import SemanticConvetion
|
11
17
|
|
12
18
|
# Initialize logger for logging potential issues and operations
|
13
19
|
logger = logging.getLogger(__name__)
|
14
20
|
|
15
|
-
def text_wrap(
|
21
|
+
def text_wrap(version, environment, application_name,
|
16
22
|
tracer, pricing_info, trace_content, metrics, disable_metrics):
|
17
23
|
"""
|
18
24
|
Creates a wrapper around a function call to trace and log its execution metrics.
|
@@ -21,7 +27,6 @@ def text_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
21
27
|
log its operation, and trace its execution using OpenTelemetry.
|
22
28
|
|
23
29
|
Parameters:
|
24
|
-
- gen_ai_endpoint (str): A descriptor or name for the endpoint being traced.
|
25
30
|
- version (str): The version of the Langchain application.
|
26
31
|
- environment (str): The deployment environment (e.g., 'production', 'development').
|
27
32
|
- application_name (str): Name of the Langchain application.
|
@@ -55,8 +60,15 @@ def text_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
55
60
|
errors are handled and logged appropriately.
|
56
61
|
"""
|
57
62
|
|
58
|
-
|
63
|
+
server_address, server_port = set_server_address_and_port(instance, "127.0.0.1", 80)
|
64
|
+
request_model = instance.model.config.name_or_path
|
65
|
+
|
66
|
+
span_name = f"{SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
|
67
|
+
|
68
|
+
with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:
|
69
|
+
start_time = time.time()
|
59
70
|
response = wrapped(*args, **kwargs)
|
71
|
+
end_time = time.time()
|
60
72
|
|
61
73
|
# pylint: disable=protected-access
|
62
74
|
forward_params = instance._forward_params
|
@@ -67,27 +79,40 @@ def text_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
67
79
|
else:
|
68
80
|
prompt = kwargs.get("args", "")
|
69
81
|
|
70
|
-
|
82
|
+
input_tokens = general_tokens(prompt[0])
|
71
83
|
|
72
84
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
73
|
-
span.set_attribute(SemanticConvetion.
|
74
|
-
|
85
|
+
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
|
86
|
+
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
|
75
87
|
span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
|
76
88
|
SemanticConvetion.GEN_AI_SYSTEM_HUGGING_FACE)
|
77
|
-
span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
|
78
|
-
environment)
|
79
|
-
span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
|
80
|
-
application_name)
|
81
|
-
span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
|
82
|
-
SemanticConvetion.GEN_AI_TYPE_CHAT)
|
83
89
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
|
84
|
-
|
90
|
+
request_model)
|
85
91
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
|
86
92
|
forward_params.get("temperature", "null"))
|
87
93
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
|
88
94
|
forward_params.get("top_p", "null"))
|
89
95
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
|
90
96
|
forward_params.get("max_length", -1))
|
97
|
+
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,
|
98
|
+
input_tokens)
|
99
|
+
span.set_attribute(SemanticConvetion.SERVER_ADDRESS,
|
100
|
+
server_address)
|
101
|
+
span.set_attribute(SemanticConvetion.SERVER_PORT,
|
102
|
+
server_port)
|
103
|
+
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL,
|
104
|
+
request_model)
|
105
|
+
|
106
|
+
span.set_attribute(DEPLOYMENT_ENVIRONMENT,
|
107
|
+
environment)
|
108
|
+
span.set_attribute(SERVICE_NAME,
|
109
|
+
application_name)
|
110
|
+
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
111
|
+
False)
|
112
|
+
span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TTFT,
|
113
|
+
end_time - start_time)
|
114
|
+
span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,
|
115
|
+
version)
|
91
116
|
if trace_content:
|
92
117
|
span.add_event(
|
93
118
|
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
@@ -95,11 +120,9 @@ def text_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
95
120
|
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
96
121
|
},
|
97
122
|
)
|
98
|
-
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
|
99
|
-
prompt_tokens)
|
100
123
|
|
101
124
|
i = 0
|
102
|
-
|
125
|
+
output_tokens = 0
|
103
126
|
for completion in response:
|
104
127
|
if len(response) > 1:
|
105
128
|
attribute_name = f"gen_ai.content.completion.{i}"
|
@@ -115,43 +138,51 @@ def text_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
115
138
|
span.add_event(
|
116
139
|
name=attribute_name,
|
117
140
|
attributes={
|
118
|
-
# pylint: disable=line-too-long
|
119
141
|
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llm_response,
|
120
142
|
},
|
121
143
|
)
|
122
|
-
|
144
|
+
output_tokens += general_tokens(llm_response)
|
123
145
|
|
124
146
|
i=i+1
|
125
|
-
span.set_attribute(SemanticConvetion.
|
126
|
-
|
147
|
+
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS,
|
148
|
+
output_tokens)
|
127
149
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
|
128
|
-
|
150
|
+
input_tokens + output_tokens)
|
151
|
+
|
152
|
+
# Calculate cost of the operation
|
153
|
+
cost = get_chat_model_cost(request_model,
|
154
|
+
pricing_info, input_tokens,
|
155
|
+
output_tokens)
|
156
|
+
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
157
|
+
cost)
|
158
|
+
|
129
159
|
span.set_status(Status(StatusCode.OK))
|
130
160
|
|
131
161
|
if disable_metrics is False:
|
132
|
-
attributes =
|
133
|
-
|
134
|
-
|
135
|
-
SemanticConvetion.
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
SemanticConvetion.GEN_AI_TYPE_CHAT,
|
143
|
-
SemanticConvetion.GEN_AI_REQUEST_MODEL:
|
144
|
-
instance.model.config.name_or_path
|
145
|
-
}
|
162
|
+
attributes = create_metrics_attributes(
|
163
|
+
service_name=application_name,
|
164
|
+
deployment_environment=environment,
|
165
|
+
operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
|
166
|
+
system=SemanticConvetion.GEN_AI_SYSTEM_HUGGING_FACE,
|
167
|
+
request_model=request_model,
|
168
|
+
server_address=server_address,
|
169
|
+
server_port=server_port,
|
170
|
+
response_model=request_model,
|
171
|
+
)
|
146
172
|
|
173
|
+
metrics["genai_client_usage_tokens"].record(
|
174
|
+
input_tokens + output_tokens, attributes
|
175
|
+
)
|
176
|
+
metrics["genai_client_operation_duration"].record(
|
177
|
+
end_time - start_time, attributes
|
178
|
+
)
|
179
|
+
metrics["genai_server_ttft"].record(
|
180
|
+
end_time - start_time, attributes
|
181
|
+
)
|
147
182
|
metrics["genai_requests"].add(1, attributes)
|
148
|
-
metrics["
|
149
|
-
|
150
|
-
|
151
|
-
metrics["genai_completion_tokens"].add(
|
152
|
-
completion_tokens, attributes)
|
153
|
-
metrics["genai_prompt_tokens"].add(
|
154
|
-
prompt_tokens, attributes)
|
183
|
+
metrics["genai_completion_tokens"].add(output_tokens, attributes)
|
184
|
+
metrics["genai_prompt_tokens"].add(input_tokens, attributes)
|
185
|
+
metrics["genai_cost"].record(cost, attributes)
|
155
186
|
|
156
187
|
# Return original response
|
157
188
|
return response
|
@@ -7,16 +7,10 @@ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
|
7
7
|
from wrapt import wrap_function_wrapper
|
8
8
|
|
9
9
|
from openlit.instrumentation.vertexai.vertexai import (
|
10
|
-
|
11
|
-
send_message, start_chat, start_chat_streaming,
|
12
|
-
embeddings
|
10
|
+
send_message
|
13
11
|
)
|
14
12
|
from openlit.instrumentation.vertexai.async_vertexai import (
|
15
|
-
|
16
|
-
predict_streaming_async,
|
17
|
-
send_message_async,
|
18
|
-
start_chat_async, start_chat_streaming_async,
|
19
|
-
embeddings_async
|
13
|
+
async_send_message
|
20
14
|
)
|
21
15
|
|
22
16
|
|
@@ -44,49 +38,28 @@ class VertexAIInstrumentor(BaseInstrumentor):
|
|
44
38
|
wrap_function_wrapper(
|
45
39
|
"vertexai.generative_models",
|
46
40
|
"GenerativeModel.generate_content",
|
47
|
-
|
41
|
+
send_message(version, environment, application_name,
|
48
42
|
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
49
43
|
)
|
50
44
|
|
51
45
|
wrap_function_wrapper(
|
52
46
|
"vertexai.generative_models",
|
53
47
|
"ChatSession.send_message",
|
54
|
-
send_message(
|
55
|
-
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
56
|
-
)
|
57
|
-
|
58
|
-
wrap_function_wrapper(
|
59
|
-
"vertexai.language_models",
|
60
|
-
"TextGenerationModel.predict",
|
61
|
-
predict("vertexai.predict", version, environment, application_name,
|
62
|
-
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
63
|
-
)
|
64
|
-
|
65
|
-
wrap_function_wrapper(
|
66
|
-
"vertexai.language_models",
|
67
|
-
"TextGenerationModel.predict_streaming",
|
68
|
-
predict_streaming("vertexai.predict", version, environment, application_name,
|
48
|
+
send_message(version, environment, application_name,
|
69
49
|
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
70
50
|
)
|
71
51
|
|
72
52
|
wrap_function_wrapper(
|
73
53
|
"vertexai.language_models",
|
74
54
|
"ChatSession.send_message",
|
75
|
-
|
55
|
+
send_message(version, environment, application_name,
|
76
56
|
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
77
57
|
)
|
78
58
|
|
79
59
|
wrap_function_wrapper(
|
80
60
|
"vertexai.language_models",
|
81
61
|
"ChatSession.send_message_streaming",
|
82
|
-
|
83
|
-
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
84
|
-
)
|
85
|
-
|
86
|
-
wrap_function_wrapper(
|
87
|
-
"vertexai.language_models",
|
88
|
-
"TextEmbeddingModel.get_embeddings",
|
89
|
-
embeddings("vertexai.get_embeddings", version, environment, application_name,
|
62
|
+
send_message(version, environment, application_name,
|
90
63
|
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
91
64
|
)
|
92
65
|
|
@@ -94,52 +67,29 @@ class VertexAIInstrumentor(BaseInstrumentor):
|
|
94
67
|
wrap_function_wrapper(
|
95
68
|
"vertexai.generative_models",
|
96
69
|
"GenerativeModel.generate_content_async",
|
97
|
-
|
98
|
-
|
99
|
-
metrics, disable_metrics),
|
70
|
+
async_send_message(version, environment, application_name,
|
71
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
100
72
|
)
|
101
73
|
|
102
74
|
wrap_function_wrapper(
|
103
75
|
"vertexai.generative_models",
|
104
76
|
"ChatSession.send_message_async",
|
105
|
-
|
106
|
-
|
107
|
-
)
|
108
|
-
|
109
|
-
wrap_function_wrapper(
|
110
|
-
"vertexai.language_models",
|
111
|
-
"TextGenerationModel.predict_async",
|
112
|
-
predict_async("vertexai.predict", version, environment, application_name,
|
113
|
-
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
114
|
-
)
|
115
|
-
|
116
|
-
wrap_function_wrapper(
|
117
|
-
"vertexai.language_models",
|
118
|
-
"TextGenerationModel.predict_streaming_async",
|
119
|
-
predict_streaming_async("vertexai.predict", version, environment, application_name,
|
120
|
-
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
77
|
+
async_send_message(version, environment, application_name,
|
78
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
121
79
|
)
|
122
80
|
|
123
81
|
wrap_function_wrapper(
|
124
82
|
"vertexai.language_models",
|
125
83
|
"ChatSession.send_message_async",
|
126
|
-
|
127
|
-
|
84
|
+
async_send_message(version, environment, application_name,
|
85
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
128
86
|
)
|
129
87
|
|
130
88
|
wrap_function_wrapper(
|
131
89
|
"vertexai.language_models",
|
132
90
|
"ChatSession.send_message_streaming_async",
|
133
|
-
|
134
|
-
|
135
|
-
metrics, disable_metrics),
|
136
|
-
)
|
137
|
-
|
138
|
-
wrap_function_wrapper(
|
139
|
-
"vertexai.language_models",
|
140
|
-
"TextEmbeddingModel.get_embeddings_async",
|
141
|
-
embeddings_async("vertexai.get_embeddings", version, environment, application_name,
|
142
|
-
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
91
|
+
async_send_message(version, environment, application_name,
|
92
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
143
93
|
)
|
144
94
|
|
145
95
|
def _uninstrument(self, **kwargs):
|