Skip to content

Conversation

@ralf0131
Copy link
Collaborator

@ralf0131 ralf0131 commented Nov 26, 2025

Description

  • Introduced a new package for OpenTelemetry instrumentation specifically for Google Agent Development Kit (ADK).
  • Added pyproject.toml for package management and dependencies.
  • Implemented core observability features, including metrics and tracing, following OpenTelemetry GenAI semantic conventions.
  • Created example tools and a demo application to showcase usage.
  • Updated .gitignore to exclude Python bytecode and coverage files.
  • Added comprehensive tests for metrics and plugin integration to ensure compliance with OpenTelemetry standards.

This resolves #35

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Unit tests covered in the pull request.

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

ralf0131 and others added 6 commits November 26, 2025 03:55
- Add package.py to define instrumentation metadata
- Update instrumentation-genai/README.md with google-adk entry
- Fixes CI generate task failure

Change-Id: I2534d42f3d6538a4842d3b19b449e927685371e3
Co-developed-by: Cursor <[email protected]>
- Add google-adk >= 0.1.0 to libraries list
- Generated by running scripts/generate_instrumentation_bootstrap.py
- Fixes CI generate check failure

Change-Id: I9c80405105cc795c8a2c66d7bb02b5e1934e81e9
Co-developed-by: Cursor <[email protected]>
- Rename from opentelemetry-instrumentation-google-adk to loongsuite-instrumentation-google-adk
- Move from instrumentation-genai/ to instrumentation-loongsuite/
- Update pyproject.toml with loongsuite naming conventions
  - Change package name to loongsuite-instrumentation-google-adk
  - Use dynamic version from version.py
  - Update authors to LoongSuite Python Agent Authors
  - Update homepage URL to point to specific subdirectory
- Update instrumentation-genai/README.md (remove google-adk entry)
- Update instrumentation-loongsuite/README.md (add google-adk entry)
- Update bootstrap_gen.py (remove google-adk as it's now loongsuite-specific)

This aligns google-adk with other loongsuite-specific instrumentations.

Change-Id: Ia1c1807731cb5ba8ba8ada0632a749dedd8a453b
Co-developed-by: Cursor <[email protected]>
Change-Id: I088389a1c453e068e29bdd64f5e18f5bcce60787
Co-developed-by: Cursor <[email protected]>
- Introduced a global instance of GoogleAdkObservabilityPlugin to facilitate both manual and auto instrumentation.
- Updated the GoogleAdkInstrumentor to utilize the global plugin, ensuring consistent observability across multiple instances.
- Added a wrapper function for Runner initialization to automatically inject the observability plugin.
- Improved documentation for usage and functionality of the instrumentation methods.

This update streamlines the instrumentation process and enhances compatibility with various usage scenarios.

Change-Id: I8a7934626fd8e8deac1f595da66174b6ca8dd7bb
Co-developed-by: Cursor <[email protected]>
Change-Id: [insert-change-id-here]
Change-Id: Ibe84196785ff3c9869feaa5de1ff60582aa2eea3
Co-developed-by: Cursor <[email protected]>
… files

- Reordered and grouped import statements for better readability in main.py and tools.py.
- Updated import statements to use consistent quotation styles.
- Removed unnecessary blank lines and improved formatting for clarity.
- Enhanced the organization of code in internal modules to align with best practices.

This refactoring improves code maintainability and readability across the Google ADK instrumentation files.

Change-Id: I3e9723b4870ea0f062a044ea7d2c6c1e7bee39da
Co-developed-by: Cursor <[email protected]>
Change-Id: If5dbb7ad8f67a9e51ff95398b79f59982020bf5a
Co-developed-by: Cursor <[email protected]>
description = "OpenTelemetry instrumentation for Google Agent Development Kit (ADK)"
readme = "README.md"
license = "Apache-2.0"
requires-python = ">=3.8"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
requires-python = ">=3.8"
requires-python = ">=3.9"

Python 3.8 is no longer supported by OpenTelemetry.

Comment on lines +20 to +25
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",

"opentelemetry-sdk ~= 1.27",
"opentelemetry-semantic-conventions ~= 0.48b0",
"wrapt >= 1.0.0, < 2.0.0",
"google-adk >= 0.1.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

google-adk should be set as an optional dependency. See instrumentation-openai:

[project.optional-dependencies]
instruments = [
"openai >= 1.26.0",
]

Comment on lines +29 to +32
"opentelemetry-api ~= 1.27",
"opentelemetry-sdk ~= 1.27",
"opentelemetry-semantic-conventions ~= 0.48b0",
"wrapt >= 1.0.0, < 2.0.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"opentelemetry-api ~= 1.27",
"opentelemetry-sdk ~= 1.27",
"opentelemetry-semantic-conventions ~= 0.48b0",
"wrapt >= 1.0.0, < 2.0.0",
"opentelemetry-api ~= 1.27",
"opentelemetry-instrumentation ~= 0.48b0",
"opentelemetry-semantic-conventions ~= 0.48b0",

opentelemetry-sdk and wrapt should be indirect dependencies imported by opentelemetry-instrumentation.

Comment on lines +65 to +83
[tool.pytest.ini_options]
minversion = "7.0"
testpaths = ["tests"]
asyncio_mode = "auto"
addopts = "--cov=opentelemetry/instrumentation/google_adk --cov-report=term-missing --cov-report=html"

[tool.coverage.run]
source = ["src"]
branch = true

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"raise AssertionError",
"raise NotImplementedError",
"if __name__ == .__main__.:",
"@abstractmethod",
]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
[tool.pytest.ini_options]
minversion = "7.0"
testpaths = ["tests"]
asyncio_mode = "auto"
addopts = "--cov=opentelemetry/instrumentation/google_adk --cov-report=term-missing --cov-report=html"
[tool.coverage.run]
source = ["src"]
branch = true
[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"raise AssertionError",
"raise NotImplementedError",
"if __name__ == .__main__.:",
"@abstractmethod",
]

You need to add tests env into tox-loongsuite.ini like what mem0 does. See https://github.com/alibaba/loongsuite-python-agent/blob/main/CONTRIBUTING-zh.md#instrumentation-%E6%8C%87%E5%8D%97 for more information.

Here is an example:

https://github.com/alibaba/loongsuite-python-agent/pull/67/files#diff-21192417e3274190429c0789f83b05b671f0a31c31b13716f9049bb3c04d2058

After add test envs, don't forget to run tox -e generate_workflow and tox -e precommit for necessary check.

)

try:
user_id = getattr(invocation_context, "user_id", None)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's necessary to check that if there's an attribute named user_id explicitly declared in InvocationContext? Or if this is a common behavior that many users may follow?

If not so, I think we shouldn't capture user_id in google adk.

except Exception as e:
_logger.debug(f"Failed to extract input messages: {e}")

attrs["input.mime_type"] = "application/json"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
attrs["input.mime_type"] = "application/json"

Remove this attribute.

_logger.exception(f"Error extracting tool attributes: {e}")
return self.extract_common_attributes("execute_tool")

def _extract_provider_name(self, model_name: str) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not reasonable to extract provider name from the model name - providers may host different models. I will create a common converter in "genai-util" and will replace this implementation soon. So feel free to leave it here.

}

# Non-standard attributes that should NOT be present
NON_STANDARD_ATTRIBUTES = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need these checks here.

self.span_exporter.clear()

@pytest.mark.asyncio
async def test_llm_span_attributes_semantic_conventions(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

You may write tests with pytest.vcr, with which you could recording the HTTP communications for real model service and replay them in subsequent tests. You could refer to open-ai tests before I publish a document how to write a test for generative instrumentation.

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.

[feat] Add support for Google ADK

4 participants