openlit 1.19.0__py3-none-any.whl → 1.20.0__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/__init__.py CHANGED
@@ -33,6 +33,7 @@ from openlit.instrumentation.ollama import OllamaInstrumentor
33
33
  from openlit.instrumentation.gpt4all import GPT4AllInstrumentor
34
34
  from openlit.instrumentation.elevenlabs import ElevenLabsInstrumentor
35
35
  from openlit.instrumentation.vllm import VLLMInstrumentor
36
+ from openlit.instrumentation.google_ai_studio import GoogleAIStudioInstrumentor
36
37
  from openlit.instrumentation.langchain import LangChainInstrumentor
37
38
  from openlit.instrumentation.llamaindex import LlamaIndexInstrumentor
38
39
  from openlit.instrumentation.haystack import HaystackInstrumentor
@@ -196,6 +197,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
196
197
  "gpt4all": "gpt4all",
197
198
  "elevenlabs": "elevenlabs",
198
199
  "vllm": "vllm",
200
+ "google-ai-studio": "google.generativeai",
199
201
  "langchain": "langchain",
200
202
  "llama_index": "llama_index",
201
203
  "haystack": "haystack",
@@ -273,6 +275,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
273
275
  "gpt4all": GPT4AllInstrumentor(),
274
276
  "elevenlabs": ElevenLabsInstrumentor(),
275
277
  "vllm": VLLMInstrumentor(),
278
+ "google-ai-studio": GoogleAIStudioInstrumentor(),
276
279
  "langchain": LangChainInstrumentor(),
277
280
  "llama_index": LlamaIndexInstrumentor(),
278
281
  "haystack": HaystackInstrumentor(),
@@ -0,0 +1,56 @@
1
+ # pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
2
+ """Initializer of Auto Instrumentation of Google AI Studio Functions"""
3
+
4
+ from typing import Collection
5
+ import importlib.metadata
6
+ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
7
+ from wrapt import wrap_function_wrapper
8
+
9
+ from openlit.instrumentation.google_ai_studio.google_ai_studio import (
10
+ generate
11
+ )
12
+
13
+ from openlit.instrumentation.google_ai_studio.async_google_ai_studio import (
14
+ async_generate
15
+ )
16
+
17
+ _instruments = ("google-generativeai >= 0.2.0",)
18
+
19
+ class GoogleAIStudioInstrumentor(BaseInstrumentor):
20
+ """
21
+ An instrumentor for google-generativeai's client library.
22
+ """
23
+
24
+ def instrumentation_dependencies(self) -> Collection[str]:
25
+ return _instruments
26
+
27
+ def _instrument(self, **kwargs):
28
+ application_name = kwargs.get("application_name", "default_application")
29
+ environment = kwargs.get("environment", "default_environment")
30
+ tracer = kwargs.get("tracer")
31
+ metrics = kwargs.get("metrics_dict")
32
+ pricing_info = kwargs.get("pricing_info", {})
33
+ trace_content = kwargs.get("trace_content", False)
34
+ disable_metrics = kwargs.get("disable_metrics")
35
+ version = importlib.metadata.version("ollama")
36
+
37
+ # sync generate
38
+ wrap_function_wrapper(
39
+ "google.generativeai.generative_models",
40
+ "GenerativeModel.generate_content",
41
+ generate("google_ai_studio.generate_content", version, environment, application_name,
42
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
43
+ )
44
+
45
+ # async generate
46
+ wrap_function_wrapper(
47
+ "google.generativeai.generative_models",
48
+ "GenerativeModel.generate_content_async",
49
+ async_generate("google_ai_studio.generate_content", version, environment,
50
+ application_name, tracer, pricing_info, trace_content, metrics,
51
+ disable_metrics),
52
+ )
53
+
54
+ def _uninstrument(self, **kwargs):
55
+ # Proper uninstrumentation logic to revert patched methods
56
+ pass
@@ -0,0 +1,259 @@
1
+ # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, possibly-used-before-assignment, protected-access
2
+ """
3
+ Module for monitoring Ollama API calls.
4
+ """
5
+
6
+ import logging
7
+ from opentelemetry.trace import SpanKind, Status, StatusCode
8
+ from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
9
+ from openlit.__helpers import (
10
+ handle_exception,
11
+ get_chat_model_cost,
12
+ )
13
+ from openlit.semcov import SemanticConvetion
14
+
15
+ # Initialize logger for logging potential issues and operations
16
+ logger = logging.getLogger(__name__)
17
+
18
+ def async_generate(gen_ai_endpoint, version, environment, application_name,
19
+ tracer, pricing_info, trace_content, metrics, disable_metrics):
20
+ """
21
+ Generates a telemetry wrapper for chat to collect metrics.
22
+
23
+ Args:
24
+ gen_ai_endpoint: Endpoint identifier for logging and tracing.
25
+ version: Version of the monitoring package.
26
+ environment: Deployment environment (e.g., production, staging).
27
+ application_name: Name of the application using the Ollama API.
28
+ tracer: OpenTelemetry tracer for creating spans.
29
+ pricing_info: Information used for calculating the cost of Ollama usage.
30
+ trace_content: Flag indicating whether to trace the actual content.
31
+
32
+ Returns:
33
+ A function that wraps the chat method to add telemetry.
34
+ """
35
+
36
+ async def wrapper(wrapped, instance, args, kwargs):
37
+ """
38
+ Wraps the 'chat' API call to add telemetry.
39
+
40
+ This collects metrics such as execution time, cost, and token usage, and handles errors
41
+ gracefully, adding details to the trace for observability.
42
+
43
+ Args:
44
+ wrapped: The original 'chat' method to be wrapped.
45
+ instance: The instance of the class where the original method is defined.
46
+ args: Positional arguments for the 'chat' method.
47
+ kwargs: Keyword arguments for the 'chat' method.
48
+
49
+ Returns:
50
+ The response from the original 'chat' method.
51
+ """
52
+ # pylint: disable=no-else-return
53
+ if kwargs.get('stream', False) is True:
54
+ # Special handling for streaming response to accommodate the nature of data flow
55
+ async def stream_generator():
56
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
57
+ # Placeholder for aggregating streaming response
58
+ llmresponse = ""
59
+
60
+ # Loop through streaming events capturing relevant details
61
+ async for chunk in await wrapped(*args, **kwargs):
62
+ # Collect message IDs and aggregated response from events
63
+ content = chunk.text
64
+ if content:
65
+ llmresponse += content
66
+
67
+ input_tokens = chunk.usage_metadata.prompt_token_count
68
+ output_tokens = chunk.usage_metadata.candidates_token_count
69
+ yield chunk
70
+
71
+ # Handling exception ensure observability without disrupting operation
72
+ try:
73
+ prompt = ""
74
+ for arg in args:
75
+ if isinstance(arg, str):
76
+ prompt = f"{prompt}{arg}\n"
77
+ elif isinstance(arg, list):
78
+ for subarg in arg:
79
+ prompt = f"{prompt}{subarg}\n"
80
+ if hasattr(instance, "_model_id"):
81
+ model = instance._model_id
82
+ if hasattr(instance, "_model_name"):
83
+ model = instance._model_name.replace("publishers/google/models/", "")
84
+
85
+ total_tokens = input_tokens + output_tokens
86
+ # Calculate cost of the operation
87
+ cost = get_chat_model_cost(kwargs.get("model", "gpt-3.5-turbo"),
88
+ pricing_info, input_tokens,
89
+ output_tokens)
90
+
91
+ # Set Span attributes
92
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
93
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
94
+ SemanticConvetion.GEN_AI_SYSTEM_GOOGLE_AI_STUDIO)
95
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
96
+ SemanticConvetion.GEN_AI_TYPE_CHAT)
97
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
98
+ gen_ai_endpoint)
99
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
100
+ environment)
101
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
102
+ application_name)
103
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
104
+ model)
105
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
106
+ True)
107
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
108
+ input_tokens)
109
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
110
+ output_tokens)
111
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
112
+ total_tokens)
113
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
114
+ cost)
115
+ if trace_content:
116
+ span.add_event(
117
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
118
+ attributes={
119
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
120
+ },
121
+ )
122
+ span.add_event(
123
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
124
+ attributes={
125
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
126
+ },
127
+ )
128
+
129
+ span.set_status(Status(StatusCode.OK))
130
+
131
+ if disable_metrics is False:
132
+ attributes = {
133
+ TELEMETRY_SDK_NAME:
134
+ "openlit",
135
+ SemanticConvetion.GEN_AI_APPLICATION_NAME:
136
+ application_name,
137
+ SemanticConvetion.GEN_AI_SYSTEM:
138
+ SemanticConvetion.GEN_AI_SYSTEM_GOOGLE_AI_STUDIO,
139
+ SemanticConvetion.GEN_AI_ENVIRONMENT:
140
+ environment,
141
+ SemanticConvetion.GEN_AI_TYPE:
142
+ SemanticConvetion.GEN_AI_TYPE_CHAT,
143
+ SemanticConvetion.GEN_AI_REQUEST_MODEL:
144
+ model
145
+ }
146
+
147
+ metrics["genai_requests"].add(1, attributes)
148
+ metrics["genai_total_tokens"].add(
149
+ total_tokens, attributes
150
+ )
151
+ metrics["genai_completion_tokens"].add(output_tokens, attributes)
152
+ metrics["genai_prompt_tokens"].add(input_tokens, attributes)
153
+ metrics["genai_cost"].record(cost, attributes)
154
+
155
+ except Exception as e:
156
+ handle_exception(span, e)
157
+ logger.error("Error in trace creation: %s", e)
158
+
159
+ return stream_generator()
160
+ else:
161
+ # pylint: disable=line-too-long
162
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
163
+ response = await wrapped(*args, **kwargs)
164
+
165
+ try:
166
+ prompt = ""
167
+ for arg in args:
168
+ if isinstance(arg, str):
169
+ prompt = f"{prompt}{arg}\n"
170
+ elif isinstance(arg, list):
171
+ for subarg in arg:
172
+ prompt = f"{prompt}{subarg}\n"
173
+ if hasattr(instance, "_model_id"):
174
+ model = instance._model_id
175
+ if hasattr(instance, "_model_name"):
176
+ model = instance._model_name.replace("publishers/google/models/", "")
177
+
178
+ # Set base span attribues
179
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
180
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
181
+ SemanticConvetion.GEN_AI_SYSTEM_GOOGLE_AI_STUDIO)
182
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
183
+ SemanticConvetion.GEN_AI_TYPE_CHAT)
184
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
185
+ gen_ai_endpoint)
186
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
187
+ environment)
188
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
189
+ application_name)
190
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
191
+ model)
192
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
193
+ False)
194
+
195
+ if trace_content:
196
+ span.add_event(
197
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
198
+ attributes={
199
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
200
+ },
201
+ )
202
+ span.add_event(
203
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
204
+ attributes={
205
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.text,
206
+ },
207
+ )
208
+
209
+ prompt_tokens = response.usage_metadata.prompt_token_count
210
+ completion_tokens = response.usage_metadata.candidates_token_count
211
+ total_tokens = response.usage_metadata.total_token_count
212
+ # Calculate cost of the operation
213
+ cost = get_chat_model_cost(kwargs.get("model", "llama3"),
214
+ pricing_info, prompt_tokens, completion_tokens)
215
+
216
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
217
+ prompt_tokens)
218
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
219
+ completion_tokens)
220
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
221
+ total_tokens)
222
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
223
+ cost)
224
+
225
+ span.set_status(Status(StatusCode.OK))
226
+
227
+ if disable_metrics is False:
228
+ attributes = {
229
+ TELEMETRY_SDK_NAME:
230
+ "openlit",
231
+ SemanticConvetion.GEN_AI_APPLICATION_NAME:
232
+ application_name,
233
+ SemanticConvetion.GEN_AI_SYSTEM:
234
+ SemanticConvetion.GEN_AI_SYSTEM_OLLAMA,
235
+ SemanticConvetion.GEN_AI_ENVIRONMENT:
236
+ environment,
237
+ SemanticConvetion.GEN_AI_TYPE:
238
+ SemanticConvetion.GEN_AI_TYPE_CHAT,
239
+ SemanticConvetion.GEN_AI_REQUEST_MODEL:
240
+ kwargs.get("model", "llama3")
241
+ }
242
+
243
+ metrics["genai_requests"].add(1, attributes)
244
+ metrics["genai_total_tokens"].add(total_tokens, attributes)
245
+ metrics["genai_completion_tokens"].add(completion_tokens, attributes)
246
+ metrics["genai_prompt_tokens"].add(prompt_tokens, attributes)
247
+ metrics["genai_cost"].record(cost, attributes)
248
+
249
+ # Return original response
250
+ return response
251
+
252
+ except Exception as e:
253
+ handle_exception(span, e)
254
+ logger.error("Error in trace creation: %s", e)
255
+
256
+ # Return original response
257
+ return response
258
+
259
+ return wrapper
@@ -0,0 +1,261 @@
1
+ # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, possibly-used-before-assignment, protected-access
2
+ """
3
+ Module for monitoring Ollama API calls.
4
+ """
5
+
6
+ import logging
7
+ from opentelemetry.trace import SpanKind, Status, StatusCode
8
+ from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
9
+ from openlit.__helpers import (
10
+ handle_exception,
11
+ get_chat_model_cost,
12
+ )
13
+ from openlit.semcov import SemanticConvetion
14
+
15
+ # Initialize logger for logging potential issues and operations
16
+ logger = logging.getLogger(__name__)
17
+
18
+ def generate(gen_ai_endpoint, version, environment, application_name,
19
+ tracer, pricing_info, trace_content, metrics, disable_metrics):
20
+ """
21
+ Generates a telemetry wrapper for chat to collect metrics.
22
+
23
+ Args:
24
+ gen_ai_endpoint: Endpoint identifier for logging and tracing.
25
+ version: Version of the monitoring package.
26
+ environment: Deployment environment (e.g., production, staging).
27
+ application_name: Name of the application using the Ollama API.
28
+ tracer: OpenTelemetry tracer for creating spans.
29
+ pricing_info: Information used for calculating the cost of Ollama usage.
30
+ trace_content: Flag indicating whether to trace the actual content.
31
+
32
+ Returns:
33
+ A function that wraps the chat method to add telemetry.
34
+ """
35
+
36
+ def wrapper(wrapped, instance, args, kwargs):
37
+ """
38
+ Wraps the 'chat' API call to add telemetry.
39
+
40
+ This collects metrics such as execution time, cost, and token usage, and handles errors
41
+ gracefully, adding details to the trace for observability.
42
+
43
+ Args:
44
+ wrapped: The original 'chat' method to be wrapped.
45
+ instance: The instance of the class where the original method is defined.
46
+ args: Positional arguments for the 'chat' method.
47
+ kwargs: Keyword arguments for the 'chat' method.
48
+
49
+ Returns:
50
+ The response from the original 'chat' method.
51
+ """
52
+ # pylint: disable=no-else-return
53
+ if kwargs.get("stream", False) is True:
54
+ # Special handling for streaming response to accommodate the nature of data flow
55
+ def stream_generator():
56
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
57
+ # Placeholder for aggregating streaming response
58
+ llmresponse = ""
59
+
60
+ # Loop through streaming events capturing relevant details
61
+ for chunk in wrapped(*args, **kwargs):
62
+ # Collect message IDs and aggregated response from events
63
+ content = chunk.text
64
+ if content:
65
+ llmresponse += content
66
+
67
+ input_tokens = chunk.usage_metadata.prompt_token_count
68
+ output_tokens = chunk.usage_metadata.candidates_token_count
69
+ yield chunk
70
+
71
+ # Handling exception ensure observability without disrupting operation
72
+ try:
73
+ prompt = ""
74
+ for arg in args:
75
+ if isinstance(arg, str):
76
+ prompt = f"{prompt}{arg}\n"
77
+ elif isinstance(arg, list):
78
+ for subarg in arg:
79
+ prompt = f"{prompt}{subarg}\n"
80
+ if hasattr(instance, "_model_id"):
81
+ model = instance._model_id
82
+ if hasattr(instance, "_model_name"):
83
+ model = instance._model_name.replace("publishers/google/models/", "")
84
+
85
+ total_tokens = input_tokens + output_tokens
86
+ # Calculate cost of the operation
87
+ cost = get_chat_model_cost(kwargs.get("model", "gpt-3.5-turbo"),
88
+ pricing_info, input_tokens,
89
+ output_tokens)
90
+
91
+ # Set Span attributes
92
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
93
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
94
+ SemanticConvetion.GEN_AI_SYSTEM_GOOGLE_AI_STUDIO)
95
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
96
+ SemanticConvetion.GEN_AI_TYPE_CHAT)
97
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
98
+ gen_ai_endpoint)
99
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
100
+ environment)
101
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
102
+ application_name)
103
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
104
+ model)
105
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
106
+ True)
107
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
108
+ input_tokens)
109
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
110
+ output_tokens)
111
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
112
+ total_tokens)
113
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
114
+ cost)
115
+ if trace_content:
116
+ span.add_event(
117
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
118
+ attributes={
119
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
120
+ },
121
+ )
122
+ span.add_event(
123
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
124
+ attributes={
125
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
126
+ },
127
+ )
128
+
129
+ span.set_status(Status(StatusCode.OK))
130
+
131
+ if disable_metrics is False:
132
+ attributes = {
133
+ TELEMETRY_SDK_NAME:
134
+ "openlit",
135
+ SemanticConvetion.GEN_AI_APPLICATION_NAME:
136
+ application_name,
137
+ SemanticConvetion.GEN_AI_SYSTEM:
138
+ SemanticConvetion.GEN_AI_SYSTEM_GOOGLE_AI_STUDIO,
139
+ SemanticConvetion.GEN_AI_ENVIRONMENT:
140
+ environment,
141
+ SemanticConvetion.GEN_AI_TYPE:
142
+ SemanticConvetion.GEN_AI_TYPE_CHAT,
143
+ SemanticConvetion.GEN_AI_REQUEST_MODEL:
144
+ model
145
+ }
146
+
147
+ metrics["genai_requests"].add(1, attributes)
148
+ metrics["genai_total_tokens"].add(
149
+ total_tokens, attributes
150
+ )
151
+ metrics["genai_completion_tokens"].add(output_tokens, attributes)
152
+ metrics["genai_prompt_tokens"].add(input_tokens, attributes)
153
+ metrics["genai_cost"].record(cost, attributes)
154
+
155
+ except Exception as e:
156
+ handle_exception(span, e)
157
+ logger.error("Error in trace creation: %s", e)
158
+
159
+ return stream_generator()
160
+ else:
161
+ # pylint: disable=line-too-long
162
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
163
+ response = wrapped(*args, **kwargs)
164
+
165
+ # print(instance._system_instruction.__dict__["_pb"].parts[0].text)
166
+ try:
167
+ prompt = ""
168
+ for arg in args:
169
+ if isinstance(arg, str):
170
+ prompt = f"{prompt}{arg}\n"
171
+ elif isinstance(arg, list):
172
+ for subarg in arg:
173
+ prompt = f"{prompt}{subarg}\n"
174
+
175
+ if hasattr(instance, "_model_id"):
176
+ model = instance._model_id
177
+ if hasattr(instance, "_model_name"):
178
+ model = instance._model_name.replace("publishers/google/models/", "")
179
+
180
+ # Set base span attribues
181
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
182
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
183
+ SemanticConvetion.GEN_AI_SYSTEM_GOOGLE_AI_STUDIO)
184
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
185
+ SemanticConvetion.GEN_AI_TYPE_CHAT)
186
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
187
+ gen_ai_endpoint)
188
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
189
+ environment)
190
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
191
+ application_name)
192
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
193
+ model)
194
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
195
+ False)
196
+
197
+ if trace_content:
198
+ span.add_event(
199
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
200
+ attributes={
201
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
202
+ },
203
+ )
204
+ span.add_event(
205
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
206
+ attributes={
207
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.text,
208
+ },
209
+ )
210
+
211
+ prompt_tokens = response.usage_metadata.prompt_token_count
212
+ completion_tokens = response.usage_metadata.candidates_token_count
213
+ total_tokens = response.usage_metadata.total_token_count
214
+ # Calculate cost of the operation
215
+ cost = get_chat_model_cost(kwargs.get("model", "llama3"),
216
+ pricing_info, prompt_tokens, completion_tokens)
217
+
218
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
219
+ prompt_tokens)
220
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
221
+ completion_tokens)
222
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
223
+ total_tokens)
224
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
225
+ cost)
226
+
227
+ span.set_status(Status(StatusCode.OK))
228
+
229
+ if disable_metrics is False:
230
+ attributes = {
231
+ TELEMETRY_SDK_NAME:
232
+ "openlit",
233
+ SemanticConvetion.GEN_AI_APPLICATION_NAME:
234
+ application_name,
235
+ SemanticConvetion.GEN_AI_SYSTEM:
236
+ SemanticConvetion.GEN_AI_SYSTEM_OLLAMA,
237
+ SemanticConvetion.GEN_AI_ENVIRONMENT:
238
+ environment,
239
+ SemanticConvetion.GEN_AI_TYPE:
240
+ SemanticConvetion.GEN_AI_TYPE_CHAT,
241
+ SemanticConvetion.GEN_AI_REQUEST_MODEL:
242
+ kwargs.get("model", "llama3")
243
+ }
244
+
245
+ metrics["genai_requests"].add(1, attributes)
246
+ metrics["genai_total_tokens"].add(total_tokens, attributes)
247
+ metrics["genai_completion_tokens"].add(completion_tokens, attributes)
248
+ metrics["genai_prompt_tokens"].add(prompt_tokens, attributes)
249
+ metrics["genai_cost"].record(cost, attributes)
250
+
251
+ # Return original response
252
+ return response
253
+
254
+ except Exception as e:
255
+ handle_exception(span, e)
256
+ logger.error("Error in trace creation: %s", e)
257
+
258
+ # Return original response
259
+ return response
260
+
261
+ return wrapper
@@ -102,6 +102,7 @@ class SemanticConvetion:
102
102
  GEN_AI_SYSTEM_GPT4ALL = "gpt4all"
103
103
  GEN_AI_SYSTEM_ELEVENLABS = "elevenlabs"
104
104
  GEN_AI_SYSTEM_VLLM = "vLLM"
105
+ GEN_AI_SYSTEM_GOOGLE_AI_STUDIO = "google-ai-studio"
105
106
  GEN_AI_SYSTEM_LANGCHAIN = "langchain"
106
107
  GEN_AI_SYSTEM_LLAMAINDEX = "llama_index"
107
108
  GEN_AI_SYSTEM_HAYSTACK = "haystack"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: openlit
3
- Version: 1.19.0
3
+ Version: 1.20.0
4
4
  Summary: OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications and GPUs, facilitating the integration of observability into your GenAI-driven projects
5
5
  Home-page: https://github.com/openlit/openlit/tree/main/openlit/python
6
6
  Keywords: OpenTelemetry,otel,otlp,llm,tracing,openai,anthropic,claude,cohere,llm monitoring,observability,monitoring,gpt,Generative AI,chatGPT,gpu
@@ -60,7 +60,7 @@ This project adheres to the [Semantic Conventions](https://github.com/open-telem
60
60
  | [✅ Ollama](https://docs.openlit.io/latest/integrations/ollama) | [✅ Pinecone](https://docs.openlit.io/latest/integrations/pinecone) | [✅ LiteLLM](https://docs.openlit.io/latest/integrations/litellm) | |
61
61
  | [✅ Anthropic](https://docs.openlit.io/latest/integrations/anthropic) | [✅ Qdrant](https://docs.openlit.io/latest/integrations/qdrant) | [✅ LlamaIndex](https://docs.openlit.io/latest/integrations/llama-index) | |
62
62
  | [✅ GPT4All](https://docs.openlit.io/latest/integrations/gpt4all) | [✅ Milvus](https://docs.openlit.io/latest/integrations/milvus) | [✅ Haystack](https://docs.openlit.io/latest/integrations/haystack) | |
63
- | [✅ Cohere](https://docs.openlit.io/latest/integrations/cohere) | | [✅ EmbedChain](https://docs.openlit.io/latest/integrations/embedchain) | |
63
+ | [✅ Cohere](https://docs.openlit.io/latest/integrations/cohere) | | [✅ EmbedChain](https://docs.openlit.io/latest/integrations/embedchain) | |
64
64
  | [✅ Mistral](https://docs.openlit.io/latest/integrations/mistral) | | [✅ Guardrails](https://docs.openlit.io/latest/integrations/guardrails) | |
65
65
  | [✅ Azure OpenAI](https://docs.openlit.io/latest/integrations/azure-openai) | | | |
66
66
  | [✅ HuggingFace Transformers](https://docs.openlit.io/latest/integrations/huggingface) | | | |
@@ -70,6 +70,7 @@ This project adheres to the [Semantic Conventions](https://github.com/open-telem
70
70
  | [✅ ElevenLabs](https://docs.openlit.io/latest/integrations/elevenlabs) | | | |
71
71
  | [✅ vLLM](https://docs.openlit.io/latest/integrations/vllm) | | | |
72
72
  | [✅ OLA Krutrim](https://docs.openlit.io/latest/integrations/krutrim) | | | |
73
+ | [✅ Google AI Studio](https://docs.openlit.io/latest/integrations/google-ai-studio) | | | |
73
74
 
74
75
  ## Supported Destinations
75
76
  - [✅ OpenTelemetry Collector](https://docs.openlit.io/latest/connections/otelcol)
@@ -1,5 +1,5 @@
1
1
  openlit/__helpers.py,sha256=lrn4PBs9owDudiCY2NBoVbAi7AU_HtUpyOj0oqPBsPY,5545
2
- openlit/__init__.py,sha256=LfU5w-D62u5pY70DdNbv5_DGtqeL1Yb0TlY-l0NAn8I,15103
2
+ openlit/__init__.py,sha256=fqeMFg76VYEX4VdxTn76Fh-0kbrN5_Sk8ahlm7Xlp9k,15296
3
3
  openlit/instrumentation/anthropic/__init__.py,sha256=oaU53BOPyfUKbEzYvLr1DPymDluurSnwo4Hernf2XdU,1955
4
4
  openlit/instrumentation/anthropic/anthropic.py,sha256=y7CEGhKOGHWt8G_5Phr4qPJTfPGRJIAr9Yk6nM3CcvM,16775
5
5
  openlit/instrumentation/anthropic/async_anthropic.py,sha256=Zz1KRKIG9wGn0quOoLvjORC-49IvHQpJ6GBdB-4PfCQ,16816
@@ -14,6 +14,9 @@ openlit/instrumentation/elevenlabs/async_elevenlabs.py,sha256=yMYACh95SFr5EYklKn
14
14
  openlit/instrumentation/elevenlabs/elevenlabs.py,sha256=mFnD7sgT47OxaXJz0Vc1nrNjXEpcGQDj5run3gA48Lw,6089
15
15
  openlit/instrumentation/embedchain/__init__.py,sha256=8TYk1OEbz46yF19dr-gB_x80VZMagU3kJ8-QihPXTeA,1929
16
16
  openlit/instrumentation/embedchain/embedchain.py,sha256=SLlr7qieT3kp4M6OYSRy8FaVCXQ2t3oPyIiE99ioNE4,7892
17
+ openlit/instrumentation/google_ai_studio/__init__.py,sha256=vG4WzaavOiiwI3r5stDMotM5TSBxdcxQhC3W4XjJIG8,2146
18
+ openlit/instrumentation/google_ai_studio/async_google_ai_studio.py,sha256=cEy5FNu92gvdmsKKVDrUcY5LpY4hHzWwJl9yezxN-Zo,13404
19
+ openlit/instrumentation/google_ai_studio/google_ai_studio.py,sha256=mLABvD756GEgVfAjiYsfLYWATT1AxPuWDuElwpX4voo,13453
17
20
  openlit/instrumentation/gpt4all/__init__.py,sha256=-59CP2B3-HGZJ_vC-fI9Dt-0BuQXRhSCWCjnaGeU15Q,1802
18
21
  openlit/instrumentation/gpt4all/gpt4all.py,sha256=dbxqZeuTrv_y6wyDOIEmC8-Dc4iCGgLpj3l5JiodLMI,18787
19
22
  openlit/instrumentation/gpu/__init__.py,sha256=Dj2MLar0DB20-t6W3pfR-3jfR_mwg4SYwhzIrH_n9sU,5596
@@ -52,8 +55,8 @@ openlit/instrumentation/vllm/__init__.py,sha256=OVWalQ1dXvip1DUsjUGaHX4J-2FrSp-T
52
55
  openlit/instrumentation/vllm/vllm.py,sha256=lDzM7F5pgxvh8nKL0dcKB4TD0Mc9wXOWeXOsOGN7Wd8,6527
53
56
  openlit/otel/metrics.py,sha256=O7NoaDz0bY19mqpE4-0PcKwEe-B-iJFRgOCaanAuZAc,4291
54
57
  openlit/otel/tracing.py,sha256=vL1ifMbARPBpqK--yXYsCM6y5dSu5LFIKqkhZXtYmUc,3712
55
- openlit/semcov/__init__.py,sha256=EvoNOKtc7UKwLZ3Gp0-B1zwmeTcAIbx8O7wvAw8wXP4,7498
56
- openlit-1.19.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
57
- openlit-1.19.0.dist-info/METADATA,sha256=7P2h2TmPkrD-DTeqa0qqaC_oiqp8LdcEZ-pjuVepCjY,14746
58
- openlit-1.19.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
59
- openlit-1.19.0.dist-info/RECORD,,
58
+ openlit/semcov/__init__.py,sha256=56daxsJtWFqp87TTT3R5OxSeMH7eOZqb4k-7AELirTI,7554
59
+ openlit-1.20.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
60
+ openlit-1.20.0.dist-info/METADATA,sha256=DvK9Dt8ZvBBvdPc_Fdbi7HxkCu9Kp-Z4IkzCOuynkg4,14934
61
+ openlit-1.20.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
62
+ openlit-1.20.0.dist-info/RECORD,,