Skip to content

feat: use GenAI util for Google ADK spans#199

Open
sipercai wants to merge 1 commit into
mainfrom
feat/google-adk-genai-util
Open

feat: use GenAI util for Google ADK spans#199
sipercai wants to merge 1 commit into
mainfrom
feat/google-adk-genai-util

Conversation

@sipercai
Copy link
Copy Markdown
Collaborator

Description

This PR updates the LoongSuite Google ADK instrumentation to construct GenAI spans through the shared GenAI util lifecycle, preserving streaming state, concurrent invocations, response metadata, and gen_ai.span.kind attributes for agent/tool/LLM spans. It also adds a local otel-gui smoke example covering non-streaming, streaming, and concurrent Google ADK calls, updates documentation, and expands tests for callback concurrency and runner span finalization.

Fixes # (N/A)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • tox -e precommit
  • OTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_latest_experimental OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_ONLY python -m tox -c tox-loongsuite.ini -e py312-test-loongsuite-instrumentation-google-adk-latest
  • OTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_latest_experimental OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_ONLY python -m tox -c tox-loongsuite.ini -e py39-test-loongsuite-instrumentation-google-adk-latest
  • python -m tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-google-adk
  • python instrumentation-loongsuite/loongsuite-instrumentation-google-adk/examples/otelgui_smoke.py --scenario all

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the LoongSuite Google ADK instrumentation to route AGENT, LLM, and TOOL span lifecycles through the shared opentelemetry-util-genai utilities, improving correctness for streaming responses, concurrent invocations, and GenAI semantic convention attributes (including gen_ai.span.kind). It also adds a local otel-gui smoke script, refreshes docs, and expands integration tests around concurrency and runner finalization.

Changes:

  • Refactor the Google ADK plugin to use GenAI util invocation objects/handler for span lifecycle, streaming output accumulation, and span-kind attributes.
  • Add new test coverage for streaming TTFT, concurrent LLM/tool/agent callbacks, and runner span finalization on root “final” events.
  • Update README + changelog and add an otelgui_smoke.py example for local trace verification.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
instrumentation-loongsuite/loongsuite-instrumentation-google-adk/src/opentelemetry/instrumentation/google_adk/internal/_plugin.py Refactors span lifecycle management to GenAI util patterns; adds streaming + concurrency handling helpers.
instrumentation-loongsuite/loongsuite-instrumentation-google-adk/tests/test_plugin_integration.py Expands tests for gen_ai.span.kind, runner finalization, streaming TTFT, and concurrency isolation.
instrumentation-loongsuite/loongsuite-instrumentation-google-adk/tests/test_integration.py Adds metric datapoint helper and strengthens metrics assertions; removes a weak/placeholder error-span test.
instrumentation-loongsuite/loongsuite-instrumentation-google-adk/examples/otelgui_smoke.py Adds a standalone smoke scenario script for non-streaming, streaming, and concurrent runs.
instrumentation-loongsuite/loongsuite-instrumentation-google-adk/README.md Updates env var guidance for GenAI semconv opt-in and message capture modes; documents smoke scenarios.
instrumentation-loongsuite/loongsuite-instrumentation-google-adk/pyproject.toml Aligns opentelemetry-util-genai dependency declaration with other packages.
instrumentation-loongsuite/loongsuite-instrumentation-google-adk/CHANGELOG.md Documents the span lifecycle/attribute changes and streaming/concurrency fixes.
Comments suppressed due to low confidence (1)

instrumentation-loongsuite/loongsuite-instrumentation-google-adk/src/opentelemetry/instrumentation/google_adk/internal/_plugin.py:816

  • _resolve_model_name declares request_key: str, but callers pass the request_key returned from _find_active_llm_invocation, which can be None. The current implementation happens to guard request_key usage, but the annotation/docstring should be updated to Optional[str] to reflect actual call sites and avoid type-checking confusion.
    def _resolve_model_name(
        self,
        llm_response: LlmResponse,
        request_key: str,
        invocation: LLMInvocation,
    ) -> str:

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 394 to +400
self._handler.start_llm(invocation)
self._detach_current_context(invocation)

# Store invocation for later use
session_id = callback_context._invocation_context.session.id
request_key = f"llm_{id(llm_request)}_{session_id}"
request_key = self._llm_key(callback_context, llm_request)
self._active_llm_invocations[request_key] = invocation
_ACTIVE_LLM_REQUEST_KEY.set(request_key)
if invocation.context_token is None:
return
try:
otel_context.detach(invocation.context_token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants