openinference-instrumentation-google-adk 0.1.8__tar.gz → 0.1.9__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openinference-instrumentation-google-adk
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Summary: OpenInference Google ADK Instrumentation
5
5
  Project-URL: Homepage, https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-google-adk
6
6
  Author-email: OpenInference Authors <oss@arize.com>
@@ -80,6 +80,7 @@ exclude = [
80
80
  ignore_missing_imports = true
81
81
  module = [
82
82
  "wrapt",
83
+ "requests",
83
84
  ]
84
85
 
85
86
  [tool.ruff]
@@ -25,6 +25,7 @@ from google.adk.models.llm_request import LlmRequest
25
25
  from google.adk.models.llm_response import LlmResponse
26
26
  from google.adk.tools.base_tool import BaseTool
27
27
  from google.genai import types
28
+ from google.genai.types import Blob
28
29
  from opentelemetry import context as context_api
29
30
  from opentelemetry import trace as trace_api
30
31
  from opentelemetry.context import _SUPPRESS_INSTRUMENTATION_KEY
@@ -39,6 +40,7 @@ from openinference.instrumentation import (
39
40
  using_user,
40
41
  )
41
42
  from openinference.semconv.trace import (
43
+ ImageAttributes,
42
44
  MessageAttributes,
43
45
  MessageContentAttributes,
44
46
  OpenInferenceLLMProviderValues,
@@ -440,6 +442,27 @@ def _get_attributes_from_content(
440
442
  )
441
443
 
442
444
 
445
+ def _get_attributes_from_inline_data(
446
+ inline_data: Blob, prefix: str = ""
447
+ ) -> Iterator[tuple[str, AttributeValue]]:
448
+ # inline_data is typically a Blob-like object with `.data` (bytes)
449
+ # and `.mime_type` (str). Encode the bytes as base64 and record
450
+ # it as an image content attribute, along with the mime type.
451
+ try:
452
+ mime_type = inline_data.mime_type
453
+ data = inline_data.data
454
+ if data and mime_type and "image" in mime_type:
455
+ image_url = f"data:{inline_data.mime_type};base64,{base64.b64encode(data).decode()}"
456
+ yield (
457
+ f"{prefix}{MessageContentAttributes.MESSAGE_CONTENT_IMAGE}.{ImageAttributes.IMAGE_URL}",
458
+ image_url,
459
+ )
460
+ yield f"{prefix}{MessageContentAttributes.MESSAGE_CONTENT_TYPE}", "image"
461
+
462
+ except Exception:
463
+ logger.debug("Failed to extract file data attributes.")
464
+
465
+
443
466
  @stop_on_exception
444
467
  def _get_attributes_from_parts(
445
468
  obj: Iterable[types.Part],
@@ -475,6 +498,9 @@ def _get_attributes_from_parts(
475
498
  safe_json_dumps(function_response.response),
476
499
  )
477
500
  message_index += 1
501
+ elif inline_data := part.inline_data:
502
+ prefix = f"{span_attribute}.{message_index}.{MESSAGE_CONTENTS}.{i}."
503
+ yield from _get_attributes_from_inline_data(inline_data, prefix)
478
504
 
479
505
 
480
506
  @stop_on_exception
@@ -555,3 +581,6 @@ def _default(obj: Any) -> Any:
555
581
  if isinstance(obj, bytes):
556
582
  return base64.b64encode(obj).decode()
557
583
  return str(obj)
584
+
585
+
586
+ MESSAGE_CONTENTS = MessageAttributes.MESSAGE_CONTENTS