-
Notifications
You must be signed in to change notification settings - Fork 19
feat: Add OpenTelemetry instrumentation for Google ADK (rebased from PR #57) #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: ralf0131 <[email protected]>
Co-authored-by: ralf0131 <[email protected]>
- 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]>
instrumentation-loongsuite/loongsuite-instrumentation-google-adk/examples/main.py
Dismissed
Show dismissed
Hide dismissed
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| requires-python = ">=3.8" | |
| requires-python = ">=3.9" |
Python 3.8 is no longer supported by OpenTelemetry.
| "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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "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", |
There was a problem hiding this comment.
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:
loongsuite-python-agent/instrumentation-genai/opentelemetry-instrumentation-openai-v2/pyproject.toml
Lines 33 to 36 in e519645
| [project.optional-dependencies] | |
| instruments = [ | |
| "openai >= 1.26.0", | |
| ] |
| "opentelemetry-api ~= 1.27", | ||
| "opentelemetry-sdk ~= 1.27", | ||
| "opentelemetry-semantic-conventions ~= 0.48b0", | ||
| "wrapt >= 1.0.0, < 2.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "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.
| [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", | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| [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:
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) |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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: |
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
Description
This resolves #35
Fixes # (issue)
Type of change
Please delete options that are not relevant.
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
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.