openinference-instrumentation-google-adk 0.1.6__tar.gz → 0.1.8__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.6
3
+ Version: 0.1.8
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>
@@ -23,7 +23,7 @@ from google.adk.agents.run_config import RunConfig
23
23
  from google.adk.events import Event
24
24
  from google.adk.models.llm_request import LlmRequest
25
25
  from google.adk.models.llm_response import LlmResponse
26
- from google.adk.tools import BaseTool
26
+ from google.adk.tools.base_tool import BaseTool
27
27
  from google.genai import types
28
28
  from opentelemetry import context as context_api
29
29
  from opentelemetry import trace as trace_api
@@ -159,6 +159,7 @@ class _BaseAgentRunAsync(_WithTracer):
159
159
  name = f"agent_run [{instance.name}]"
160
160
  attributes = dict(get_attributes_from_context())
161
161
  attributes[SpanAttributes.OPENINFERENCE_SPAN_KIND] = OpenInferenceSpanKindValues.AGENT.value
162
+ attributes[SpanAttributes.AGENT_NAME] = instance.name
162
163
 
163
164
  class _AsyncGenerator(wrapt.ObjectProxy): # type: ignore[misc]
164
165
  __wrapped__: AsyncGenerator[Event, None]
@@ -260,7 +261,8 @@ class _TraceCallLlm(_WithTracer):
260
261
  if system_instruction.parts:
261
262
  for k, v in _get_attributes_from_parts(
262
263
  system_instruction.parts,
263
- prefix=f"{SpanAttributes.LLM_INPUT_MESSAGES}.{input_messages_index}.",
264
+ span_attribute=SpanAttributes.LLM_INPUT_MESSAGES,
265
+ message_index=input_messages_index,
264
266
  text_only=True,
265
267
  ):
266
268
  span.set_attribute(k, v)
@@ -273,7 +275,8 @@ class _TraceCallLlm(_WithTracer):
273
275
  for i, content in enumerate(contents, input_messages_index):
274
276
  for k, v in _get_attributes_from_content(
275
277
  content,
276
- prefix=f"{SpanAttributes.LLM_INPUT_MESSAGES}.{i}.",
278
+ span_attribute=SpanAttributes.LLM_INPUT_MESSAGES,
279
+ message_index=i,
277
280
  ):
278
281
  span.set_attribute(k, v)
279
282
  if llm_response:
@@ -372,7 +375,7 @@ def _get_attributes_from_llm_response(
372
375
  yield from _get_attributes_from_usage_metadata(obj.usage_metadata)
373
376
  if obj.content:
374
377
  yield from _get_attributes_from_content(
375
- obj.content, prefix=f"{SpanAttributes.LLM_OUTPUT_MESSAGES}.0."
378
+ obj.content, span_attribute=SpanAttributes.LLM_OUTPUT_MESSAGES, message_index=0
376
379
  )
377
380
 
378
381
 
@@ -425,12 +428,16 @@ def _get_attributes_from_content(
425
428
  obj: types.Content,
426
429
  /,
427
430
  *,
428
- prefix: str = "",
431
+ span_attribute: str = SpanAttributes.LLM_INPUT_MESSAGES,
432
+ message_index: int = 0,
429
433
  ) -> Iterator[tuple[str, AttributeValue]]:
430
434
  role = obj.role or "user"
435
+ prefix = f"{span_attribute}.{message_index}."
431
436
  yield f"{prefix}{MessageAttributes.MESSAGE_ROLE}", role
432
437
  if parts := obj.parts:
433
- yield from _get_attributes_from_parts(parts, prefix=prefix)
438
+ yield from _get_attributes_from_parts(
439
+ parts, span_attribute=span_attribute, message_index=message_index
440
+ )
434
441
 
435
442
 
436
443
  @stop_on_exception
@@ -438,23 +445,27 @@ def _get_attributes_from_parts(
438
445
  obj: Iterable[types.Part],
439
446
  /,
440
447
  *,
441
- prefix: str = "",
448
+ span_attribute: str = SpanAttributes.LLM_INPUT_MESSAGES,
449
+ message_index: int = 0,
442
450
  text_only: bool = False,
443
451
  ) -> Iterator[tuple[str, AttributeValue]]:
444
452
  for i, part in enumerate(obj):
445
453
  if (text := part.text) is not None:
454
+ prefix = f"{span_attribute}.{message_index}.{MessageAttributes.MESSAGE_CONTENTS}.{i}."
446
455
  yield from _get_attributes_from_text_part(
447
456
  text,
448
- prefix=f"{prefix}{MessageAttributes.MESSAGE_CONTENTS}.{i}.",
457
+ prefix=prefix,
449
458
  )
450
459
  elif text_only:
451
460
  continue
452
461
  elif (function_call := part.function_call) is not None:
462
+ prefix = f"{span_attribute}.{message_index}.{MessageAttributes.MESSAGE_TOOL_CALLS}.{i}."
453
463
  yield from _get_attributes_from_function_call(
454
464
  function_call,
455
- prefix=f"{prefix}{MessageAttributes.MESSAGE_TOOL_CALLS}.{i}.",
465
+ prefix=prefix,
456
466
  )
457
467
  elif (function_response := part.function_response) is not None:
468
+ prefix = f"{span_attribute}.{message_index}."
458
469
  yield f"{prefix}{MessageAttributes.MESSAGE_ROLE}", "tool"
459
470
  if function_response.name:
460
471
  yield f"{prefix}{MessageAttributes.MESSAGE_NAME}", function_response.name
@@ -463,6 +474,7 @@ def _get_attributes_from_parts(
463
474
  f"{prefix}{MessageAttributes.MESSAGE_CONTENT}",
464
475
  safe_json_dumps(function_response.response),
465
476
  )
477
+ message_index += 1
466
478
 
467
479
 
468
480
  @stop_on_exception