opentelemetry-instrumentation-vertexai 0.16.5__tar.gz → 0.16.7__tar.gz

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.

Potentially problematic release.


This version of opentelemetry-instrumentation-vertexai might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: opentelemetry-instrumentation-vertexai
3
- Version: 0.16.5
3
+ Version: 0.16.7
4
4
  Summary: OpenTelemetry Vertex AI instrumentation
5
5
  Home-page: https://github.com/traceloop/openllmetry/tree/main/packages/opentelemetry-instrumentation-vertexai
6
6
  License: Apache-2.0
@@ -1,8 +1,11 @@
1
1
  """OpenTelemetry Vertex AI instrumentation"""
2
+
2
3
  import logging
3
4
  import os
4
5
  import types
5
6
  from typing import Collection
7
+ from opentelemetry.instrumentation.vertexai.config import Config
8
+ from opentelemetry.instrumentation.vertexai.utils import dont_throw
6
9
  from wrapt import wrap_function_wrapper
7
10
 
8
11
  from opentelemetry import context as context_api
@@ -142,6 +145,7 @@ def _set_input_attributes(span, args, kwargs):
142
145
  return
143
146
 
144
147
 
148
+ @dont_throw
145
149
  def _set_response_attributes(span, response):
146
150
  _set_span_attribute(span, SpanAttributes.LLM_RESPONSE_MODEL, llm_model)
147
151
 
@@ -214,28 +218,17 @@ async def _abuild_from_streaming_response(span, response):
214
218
  span.end()
215
219
 
216
220
 
221
+ @dont_throw
217
222
  def _handle_request(span, args, kwargs):
218
- try:
219
- if span.is_recording():
220
- _set_input_attributes(span, args, kwargs)
221
-
222
- except Exception as ex: # pylint: disable=broad-except
223
- logger.warning(
224
- "Failed to set input attributes for VertexAI span, error: %s", str(ex)
225
- )
223
+ if span.is_recording():
224
+ _set_input_attributes(span, args, kwargs)
226
225
 
227
226
 
227
+ @dont_throw
228
228
  def _handle_response(span, response):
229
- try:
230
- if span.is_recording():
231
- _set_response_attributes(span, response)
232
-
233
- except Exception as ex: # pylint: disable=broad-except
234
- logger.warning(
235
- "Failed to set response attributes for VertexAI span, error: %s",
236
- str(ex),
237
- )
238
229
  if span.is_recording():
230
+ _set_response_attributes(span, response)
231
+
239
232
  span.set_status(Status(StatusCode.OK))
240
233
 
241
234
 
@@ -344,6 +337,10 @@ def _wrap(tracer, to_wrap, wrapped, instance, args, kwargs):
344
337
  class VertexAIInstrumentor(BaseInstrumentor):
345
338
  """An instrumentor for VertextAI's client library."""
346
339
 
340
+ def __init__(self, exception_logger=None):
341
+ super().__init__()
342
+ Config.exception_logger = exception_logger
343
+
347
344
  def instrumentation_dependencies(self) -> Collection[str]:
348
345
  return _instruments
349
346
 
@@ -358,7 +355,11 @@ class VertexAIInstrumentor(BaseInstrumentor):
358
355
  wrap_function_wrapper(
359
356
  wrap_package,
360
357
  f"{wrap_object}.{wrap_method}",
361
- _awrap(tracer, wrapped_method) if wrap_method == 'predict_async' else _wrap(tracer, wrapped_method),
358
+ (
359
+ _awrap(tracer, wrapped_method)
360
+ if wrap_method == "predict_async"
361
+ else _wrap(tracer, wrapped_method)
362
+ ),
362
363
  )
363
364
 
364
365
  def _uninstrument(self, **kwargs):
@@ -0,0 +1,2 @@
1
+ class Config:
2
+ exception_logger = None
@@ -0,0 +1,24 @@
1
+ import logging
2
+
3
+ from opentelemetry.instrumentation.vertexai.config import Config
4
+
5
+
6
+ def dont_throw(func):
7
+ """
8
+ A decorator that wraps the passed in function and logs exceptions instead of throwing them.
9
+
10
+ @param func: The function to wrap
11
+ @return: The wrapper function
12
+ """
13
+ # Obtain a logger specific to the function's module
14
+ logger = logging.getLogger(func.__module__)
15
+
16
+ def wrapper(*args, **kwargs):
17
+ try:
18
+ return func(*args, **kwargs)
19
+ except Exception as e:
20
+ logger.warning("Failed to execute %s, error: %s", func.__name__, str(e))
21
+ if Config.exception_logger:
22
+ Config.exception_logger(e)
23
+
24
+ return wrapper
@@ -8,7 +8,7 @@ show_missing = true
8
8
 
9
9
  [tool.poetry]
10
10
  name = "opentelemetry-instrumentation-vertexai"
11
- version = "0.16.5"
11
+ version = "0.16.7"
12
12
  description = "OpenTelemetry Vertex AI instrumentation"
13
13
  authors = [
14
14
  "Gal Kleinman <gal@traceloop.com>",