From 6cc8d982c878f70d37898c396e3a684f39ff3d72 Mon Sep 17 00:00:00 2001 From: daavoo Date: Wed, 30 Apr 2025 15:38:31 +0200 Subject: [PATCH 1/7] feat: google-adk instrumentation. Closes #1506 --- .../LICENSE | 201 +++++++++++++++++ .../README.md | 120 ++++++++++ .../examples/basic.py | 49 +++++ .../examples/tools.py | 73 ++++++ .../pyproject.toml | 98 +++++++++ .../instrumentation/google_adk/__init__.py | 98 +++++++++ .../instrumentation/google_adk/_callback.py | 207 ++++++++++++++++++ .../instrumentation/google_adk/py.typed | 0 .../instrumentation/google_adk/version.py | 1 + .../test-requirements.txt | 3 + .../tests/__init__.py | 0 .../tests/test_instrumentor.py | 81 +++++++ python/tox.ini | 7 + 13 files changed, 938 insertions(+) create mode 100644 python/instrumentation/openinference-instrumentation-google-adk/LICENSE create mode 100644 python/instrumentation/openinference-instrumentation-google-adk/README.md create mode 100644 python/instrumentation/openinference-instrumentation-google-adk/examples/basic.py create mode 100644 python/instrumentation/openinference-instrumentation-google-adk/examples/tools.py create mode 100644 python/instrumentation/openinference-instrumentation-google-adk/pyproject.toml create mode 100644 python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/__init__.py create mode 100644 python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/_callback.py create mode 100644 python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/py.typed create mode 100644 python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/version.py create mode 100644 python/instrumentation/openinference-instrumentation-google-adk/test-requirements.txt create mode 100644 python/instrumentation/openinference-instrumentation-google-adk/tests/__init__.py create mode 100644 python/instrumentation/openinference-instrumentation-google-adk/tests/test_instrumentor.py diff --git a/python/instrumentation/openinference-instrumentation-google-adk/LICENSE b/python/instrumentation/openinference-instrumentation-google-adk/LICENSE new file mode 100644 index 000000000..1525436c1 --- /dev/null +++ b/python/instrumentation/openinference-instrumentation-google-adk/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright The OpenInference Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/python/instrumentation/openinference-instrumentation-google-adk/README.md b/python/instrumentation/openinference-instrumentation-google-adk/README.md new file mode 100644 index 000000000..eae7fd834 --- /dev/null +++ b/python/instrumentation/openinference-instrumentation-google-adk/README.md @@ -0,0 +1,120 @@ +# OpenInference Google ADK Instrumentation + +[![pypi](https://badge.fury.io/py/openinference-instrumentation-google-adk.svg)](https://pypi.org/project/openinference-instrumentation-google-adk/) + +Python auto-instrumentation library for Google ADK. + +The traces emitted by this instrumentation are fully OpenTelemetry compatible and can be sent to an OpenTelemetry collector for viewing, such as [`arize-phoenix`](https://github.com/Arize-ai/phoenix) + +## Installation + +```shell +pip install openinference-instrumentation-google-adk +``` + +## Quickstart + +In this example we will instrument a small program that uses OpenAI and observe the traces via [`arize-phoenix`](https://github.com/Arize-ai/phoenix). + +Install packages. + +```shell +pip install openinference-instrumentation-google-adk arize-phoenix opentelemetry-sdk opentelemetry-exporter-otlp +``` + +Start the phoenix server so that it is ready to collect traces. +The Phoenix server runs entirely on your machine and does not send data over the internet. + +```shell +phoenix serve +``` + +In a python file, set up the `GoogleADKInstrumentor` and configure the tracer to send traces to Phoenix. + +```python +import asyncio + +from google.adk.agents import Agent +from google.adk.runners import InMemoryRunner +from google.genai import types + +from openinference.instrumentation.google_adk import GoogleADKInstrumentor +from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter +from opentelemetry.sdk import trace as trace_sdk +from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor + +endpoint = "http://127.0.0.1:6006/v1/traces" +tracer_provider = trace_sdk.TracerProvider() +tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint))) +# Optionally, you can also print the spans to the console. +tracer_provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter())) + +GoogleADKInstrumentor().instrument(tracer_provider=tracer_provider) + +def get_weather(city: str) -> dict: + """Retrieves the current weather report for a specified city. + + Args: + city (str): The name of the city for which to retrieve the weather report. + + Returns: + dict: status and result or error msg. + """ + if city.lower() == "new york": + return { + "status": "success", + "report": ( + "The weather in New York is sunny with a temperature of 25 degrees" + " Celsius (77 degrees Fahrenheit)." + ), + } + else: + return { + "status": "error", + "error_message": f"Weather information for '{city}' is not available.", + } + +agent = Agent( + name="test_agent", + model="gemini-2.0-flash-exp", + description="Agent to answer questions using tools.", + instruction="You must use the available tools to find an answer.", + tools=[get_weather] +) + +async def main(): + app_name = "test_instrumentation" + user_id = "test_user" + session_id = "test_session" + runner = InMemoryRunner(agent=agent, app_name=app_name) + session_service = runner.session_service + session_service.create_session( + app_name=app_name, + user_id=user_id, + session_id=session_id + ) + async for event in runner.run_async( + user_id=user_id, + session_id=session_id, + new_message=types.Content(role="user", parts=[ + types.Part(text="What is the weather in New York?")] + ) + ): + if event.is_final_response(): + print(event.content.parts[0].text.strip()) + +if __name__ == "__main__": + asyncio.run(main()) +``` + +Since we are using Gemini, we must set the `GOOGLE_API_KEY` environment variable to authenticate with the Gemini API. + +```shell +export GOOGLE_API_KEY=your-api-key +``` + +Now simply run the python file and observe the traces in Phoenix. + +```shell +python your_file.py +``` diff --git a/python/instrumentation/openinference-instrumentation-google-adk/examples/basic.py b/python/instrumentation/openinference-instrumentation-google-adk/examples/basic.py new file mode 100644 index 000000000..f77699e1c --- /dev/null +++ b/python/instrumentation/openinference-instrumentation-google-adk/examples/basic.py @@ -0,0 +1,49 @@ +import asyncio + +from google.adk.agents import Agent +from google.adk.runners import InMemoryRunner +from google.genai import types + +from openinference.instrumentation.google_adk import GoogleADKInstrumentor +from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter +from opentelemetry.sdk import trace as trace_sdk +from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor + +endpoint = "http://127.0.0.1:6006/v1/traces" +tracer_provider = trace_sdk.TracerProvider() +tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint))) +# Optionally, you can also print the spans to the console. +tracer_provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter())) + +GoogleADKInstrumentor().instrument(tracer_provider=tracer_provider) + +agent = Agent( + name="Assistant", + model="gemini-2.0-flash-exp", + description="A helpful assistant.", + instruction="You are a helpful assistant.", +) + +async def main(): + app_name = "test_instrumentation" + user_id = "test_user" + session_id = "test_session" + runner = InMemoryRunner(agent=agent, app_name=app_name) + session_service = runner.session_service + session_service.create_session( + app_name=app_name, + user_id=user_id, + session_id=session_id + ) + async for event in runner.run_async( + user_id=user_id, + session_id=session_id, + new_message=types.Content(role="user", parts=[ + types.Part(text="Write a haiku about recursion in programming.")] + ) + ): + if event.is_final_response(): + print(event.content.parts[0].text.strip()) + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/python/instrumentation/openinference-instrumentation-google-adk/examples/tools.py b/python/instrumentation/openinference-instrumentation-google-adk/examples/tools.py new file mode 100644 index 000000000..6476e81eb --- /dev/null +++ b/python/instrumentation/openinference-instrumentation-google-adk/examples/tools.py @@ -0,0 +1,73 @@ +import asyncio + +from google.adk.agents import Agent +from google.adk.runners import InMemoryRunner +from google.genai import types + +from openinference.instrumentation.google_adk import GoogleADKInstrumentor +from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter +from opentelemetry.sdk import trace as trace_sdk +from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor + +endpoint = "http://127.0.0.1:6006/v1/traces" +tracer_provider = trace_sdk.TracerProvider() +tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint))) +# Optionally, you can also print the spans to the console. +tracer_provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter())) + +GoogleADKInstrumentor().instrument(tracer_provider=tracer_provider) + +def get_weather(city: str) -> dict: + """Retrieves the current weather report for a specified city. + + Args: + city (str): The name of the city for which to retrieve the weather report. + + Returns: + dict: status and result or error msg. + """ + if city.lower() == "new york": + return { + "status": "success", + "report": ( + "The weather in New York is sunny with a temperature of 25 degrees" + " Celsius (77 degrees Fahrenheit)." + ), + } + else: + return { + "status": "error", + "error_message": f"Weather information for '{city}' is not available.", + } + +agent = Agent( + name="test_agent", + model="gemini-2.0-flash-exp", + description="Agent to answer questions using tools.", + instruction="You must use the available tools to find an answer.", + tools=[get_weather] +) + +async def main(): + app_name = "test_instrumentation" + user_id = "test_user" + session_id = "test_session" + runner = InMemoryRunner(agent=agent, app_name=app_name) + session_service = runner.session_service + session_service.create_session( + app_name=app_name, + user_id=user_id, + session_id=session_id + ) + async for event in runner.run_async( + user_id=user_id, + session_id=session_id, + new_message=types.Content(role="user", parts=[ + types.Part(text="What is the weather in New York?")] + ) + ): + if event.is_final_response(): + print(event.content.parts[0].text.strip()) + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/python/instrumentation/openinference-instrumentation-google-adk/pyproject.toml b/python/instrumentation/openinference-instrumentation-google-adk/pyproject.toml new file mode 100644 index 000000000..d4c677858 --- /dev/null +++ b/python/instrumentation/openinference-instrumentation-google-adk/pyproject.toml @@ -0,0 +1,98 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "openinference-instrumentation-google-adk" +dynamic = ["version"] +description = "OpenInference OpenAI Agents Instrumentation" +readme = "README.md" +license = "Apache-2.0" +requires-python = ">=3.9, <3.14" +authors = [ + { name = "OpenInference Authors", email = "oss@arize.com" }, +] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python", + "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", +] +dependencies = [ + "opentelemetry-api", + "opentelemetry-instrumentation", + "opentelemetry-semantic-conventions", + "openinference-instrumentation>=0.1.27", + "openinference-semantic-conventions>=0.1.12", + "typing-extensions", + "wrapt", +] + +[project.optional-dependencies] +instruments = [ + "google-adk >= 0.3.0", +] + +[project.entry-points.opentelemetry_instrumentor] +google_adk = "openinference.instrumentation.google_adk:GoogleADKInstrumentor" + +[project.entry-points.openinference_instrumentor] +google_adk = "openinference.instrumentation.google_adk:GoogleADKInstrumentor" + +[project.urls] +Homepage = "https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-google-adk" + +[tool.hatch.version] +path = "src/openinference/instrumentation/google_adk/version.py" + +[tool.hatch.build.targets.sdist] +include = [ + "/src", +] + +[tool.hatch.build.targets.wheel] +packages = ["src/openinference"] + +[tool.pytest.ini_options] +asyncio_mode = "auto" +asyncio_default_fixture_loop_scope = "function" +testpaths = [ + "tests", +] + +[tool.mypy] +strict = true +explicit_package_bases = true +exclude = [ + "examples", + "dist", + "sdist", + "tests" +] + +[[tool.mypy.overrides]] +ignore_missing_imports = true +module = [ + "wrapt", + "google.*", +] + +[tool.ruff] +line-length = 100 +target-version = "py38" + +[tool.ruff.lint.per-file-ignores] +"*.ipynb" = ["E402", "E501"] +"examples/*" = ["E501"] + +[tool.ruff.lint] +select = ["E", "F", "W", "I"] + +[tool.ruff.lint.isort] +force-single-line = false diff --git a/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/__init__.py b/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/__init__.py new file mode 100644 index 000000000..4f791bbfe --- /dev/null +++ b/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/__init__.py @@ -0,0 +1,98 @@ +import logging +from typing import Any, Collection + +from opentelemetry import trace as trace_api +from opentelemetry.instrumentation.instrumentor import BaseInstrumentor #type: ignore[attr-defined] +from wrapt import wrap_object_attribute + +from openinference.instrumentation import OITracer, TraceConfig +from openinference.instrumentation.google_adk.version import __version__ + +logger = logging.getLogger(__name__) +logger.addHandler(logging.NullHandler()) + +_instruments = ("google-adk >= 0.3.0",) + + +class GoogleADKInstrumentor(BaseInstrumentor): # type: ignore + """ + An instrumentor for google-adk + """ + + def instrumentation_dependencies(self) -> Collection[str]: + return _instruments + + def _instrument(self, **kwargs: Any) -> None: + if not (tracer_provider := kwargs.get("tracer_provider")): + tracer_provider = trace_api.get_tracer_provider() + if not (config := kwargs.get("config")): + config = TraceConfig() + else: + assert isinstance(config, TraceConfig) + + self._tracer = OITracer( + trace_api.get_tracer(__name__, __version__, tracer_provider), + config=config, + ) + + from openinference.instrumentation.google_adk._callback import ( + GoogleADKTracingCallback, + ) + + callback = GoogleADKTracingCallback(tracer=self._tracer) + + def callback_factory(value, *args, **kwargs): #type: ignore[no-untyped-def] + # Honor any callback passed by the user + kwargs["callback_parent"]._original_value = value + return kwargs["callback_wrapper"] + + wrap_object_attribute( + module="google.adk.agents.llm_agent", + name="LlmAgent.before_agent_callback", + factory=callback_factory, + kwargs={ + "callback_parent": callback, + "callback_wrapper": callback.before_agent_callback, + }, + ) + + wrap_object_attribute( + module="google.adk.agents.llm_agent", + name="LlmAgent.before_model_callback", + factory=callback_factory, + kwargs={ + "callback_parent": callback, + "callback_wrapper": callback.before_model_callback, + }, + ) + + wrap_object_attribute( + module="google.adk.agents.llm_agent", + name="LlmAgent.before_tool_callback", + factory=callback_factory, + kwargs={"callback_parent": callback, "callback_wrapper": callback.before_tool_callback}, + ) + + wrap_object_attribute( + module="google.adk.agents.llm_agent", + name="LlmAgent.after_agent_callback", + factory=callback_factory, + kwargs={"callback_parent": callback, "callback_wrapper": callback.after_agent_callback}, + ) + + wrap_object_attribute( + module="google.adk.agents.llm_agent", + name="LlmAgent.after_model_callback", + factory=callback_factory, + kwargs={"callback_parent": callback, "callback_wrapper": callback.after_model_callback}, + ) + + wrap_object_attribute( + module="google.adk.agents.llm_agent", + name="LlmAgent.after_tool_callback", + factory=callback_factory, + kwargs={"callback_parent": callback, "callback_wrapper": callback.after_tool_callback}, + ) + + def _uninstrument(self, **kwargs: Any) -> None: + pass diff --git a/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/_callback.py b/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/_callback.py new file mode 100644 index 000000000..20d7bbf92 --- /dev/null +++ b/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/_callback.py @@ -0,0 +1,207 @@ +from __future__ import annotations + +import logging +from typing import TYPE_CHECKING, Any, Dict, Optional + +from opentelemetry.trace import Span as OtelSpan +from opentelemetry.trace import StatusCode, set_span_in_context + +from openinference.instrumentation.helpers import safe_json_dumps +from openinference.semconv.trace import ( + OpenInferenceLLMSystemValues, + OpenInferenceMimeTypeValues, + OpenInferenceSpanKindValues, + SpanAttributes, +) + +if TYPE_CHECKING: + from google.adk.agents.callback_context import CallbackContext + from google.adk.models.llm_request import LlmRequest + from google.adk.models.llm_response import LlmResponse + from google.adk.tools.base_tool import BaseTool + from google.adk.tools.tool_context import ToolContext + from openinference.instrumentation import OITracer + + +logger = logging.getLogger(__name__) + + +AGENT = OpenInferenceSpanKindValues.AGENT.value +LLM = OpenInferenceSpanKindValues.LLM.value +LLM_SYSTEM = SpanAttributes.LLM_SYSTEM +TOOL = OpenInferenceSpanKindValues.TOOL.value + + +class GoogleADKTracingCallback: + def __init__(self, tracer: OITracer) -> None: + self._tracer = tracer + self._original_value = None + self._current_spans: Dict[str, OtelSpan] = {} + + def before_agent_callback( + self, + callback_context: "CallbackContext", + ) -> Optional[Any]: + otel_span: OtelSpan = self._tracer.start_span( + name=f"{callback_context.agent_name}-{AGENT}", + attributes={ + SpanAttributes.OPENINFERENCE_SPAN_KIND: AGENT, + LLM_SYSTEM: OpenInferenceLLMSystemValues.VERTEXAI.value, + }, + ) + self._current_spans[AGENT] = otel_span + + if callable(self._original_value): + return self._original_value(callback_context) + + return None + + def before_model_callback( + self, + callback_context: "CallbackContext", + llm_request: "LlmRequest", + ) -> Optional[Any]: + context = ( + set_span_in_context(self._current_spans[AGENT]) if self._current_spans[AGENT] else None + ) + otel_span: OtelSpan = self._tracer.start_span( + name=f"{callback_context.agent_name}-{LLM}", + context=context, + attributes={ + SpanAttributes.OPENINFERENCE_SPAN_KIND: LLM, + LLM_SYSTEM: OpenInferenceLLMSystemValues.VERTEXAI.value, + }, + ) + otel_span.set_attributes( + { + SpanAttributes.INPUT_VALUE: safe_json_dumps( + [content.model_dump(exclude_none=True) for content in llm_request.contents] + ), + SpanAttributes.INPUT_MIME_TYPE: OpenInferenceMimeTypeValues.JSON.value, + SpanAttributes.LLM_INVOCATION_PARAMETERS: safe_json_dumps( + llm_request.config.model_dump(exclude_none=True) + ), + SpanAttributes.LLM_MODEL_NAME: llm_request.model, + SpanAttributes.LLM_TOOLS: safe_json_dumps( + [ + { + SpanAttributes.TOOL_NAME: tool.name, + SpanAttributes.TOOL_DESCRIPTION: tool.description, + } + for tool in llm_request.tools_dict.values() + ] + ), + } + ) + self._current_spans[LLM] = otel_span + + if callable(self._original_value): + return self._original_value(callback_context, llm_request) + + return None + + def before_tool_callback( + self, + tool: "BaseTool", + args: Dict[str, Any], + tool_context: "ToolContext", + ) -> Optional[Any]: + context = ( + set_span_in_context(self._current_spans[AGENT]) if self._current_spans[AGENT] else None + ) + otel_span: OtelSpan = self._tracer.start_span( + name=f"{tool_context.agent_name}-{TOOL}", + context=context, + attributes={ + SpanAttributes.OPENINFERENCE_SPAN_KIND: TOOL, + LLM_SYSTEM: OpenInferenceLLMSystemValues.VERTEXAI.value, + }, + ) + otel_span.set_attributes( + { + SpanAttributes.INPUT_VALUE: safe_json_dumps(args), + SpanAttributes.INPUT_MIME_TYPE: OpenInferenceMimeTypeValues.JSON.value, + SpanAttributes.TOOL_NAME: tool.name, + SpanAttributes.TOOL_DESCRIPTION: tool.description, + } + ) + self._current_spans[TOOL] = otel_span + + if callable(self._original_value): + return self._original_value(tool, args, tool_context) + + return None + + def after_agent_callback( + self, + callback_context: "CallbackContext", + ) -> Optional[Any]: + otel_span = self._current_spans[AGENT] + otel_span.set_status(StatusCode.OK) + otel_span.end() + + del self._current_spans[AGENT] + + if callable(self._original_value): + return self._original_value(callback_context) + + return None + + def after_model_callback( + self, + callback_context: "CallbackContext", + llm_response: "LlmResponse", + ) -> Optional[Any]: + otel_span = self._current_spans[LLM] + + if llm_response.content.parts[0].text: + otel_span.set_attributes( + { + SpanAttributes.OUTPUT_VALUE: llm_response.content.parts[0].text, + SpanAttributes.OUTPUT_MIME_TYPE: OpenInferenceMimeTypeValues.TEXT.value, + } + ) + else: + # Function calls + otel_span.set_attributes( + { + SpanAttributes.OUTPUT_VALUE: safe_json_dumps( + llm_response.content.model_dump(exclude_none=True), + ), + SpanAttributes.OUTPUT_MIME_TYPE: OpenInferenceMimeTypeValues.JSON.value, + } + ) + + otel_span.set_status(StatusCode.OK) + otel_span.end() + del self._current_spans[LLM] + + if callable(self._original_value): + return self._original_value(callback_context, llm_response) + + return None + + def after_tool_callback( + self, + tool: "BaseTool", + args: Dict[str, Any], + tool_context: "ToolContext", + tool_response: Dict[Any, Any], + ) -> Optional[Any]: + otel_span = self._current_spans[TOOL] + + otel_span.set_attributes( + { + SpanAttributes.OUTPUT_VALUE: safe_json_dumps(tool_response), + SpanAttributes.OUTPUT_MIME_TYPE: OpenInferenceMimeTypeValues.JSON.value, + } + ) + otel_span.set_status(StatusCode.OK) + otel_span.end() + + del self._current_spans[TOOL] + + if callable(self._original_value): + return self._original_value(tool, args, tool_context, tool_response) + + return None diff --git a/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/py.typed b/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/py.typed new file mode 100644 index 000000000..e69de29bb diff --git a/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/version.py b/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/version.py new file mode 100644 index 000000000..3dc1f76bc --- /dev/null +++ b/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/version.py @@ -0,0 +1 @@ +__version__ = "0.1.0" diff --git a/python/instrumentation/openinference-instrumentation-google-adk/test-requirements.txt b/python/instrumentation/openinference-instrumentation-google-adk/test-requirements.txt new file mode 100644 index 000000000..262a5783a --- /dev/null +++ b/python/instrumentation/openinference-instrumentation-google-adk/test-requirements.txt @@ -0,0 +1,3 @@ +google-adk>=0.3.0 +opentelemetry-sdk +pytest \ No newline at end of file diff --git a/python/instrumentation/openinference-instrumentation-google-adk/tests/__init__.py b/python/instrumentation/openinference-instrumentation-google-adk/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/python/instrumentation/openinference-instrumentation-google-adk/tests/test_instrumentor.py b/python/instrumentation/openinference-instrumentation-google-adk/tests/test_instrumentor.py new file mode 100644 index 000000000..68152be8b --- /dev/null +++ b/python/instrumentation/openinference-instrumentation-google-adk/tests/test_instrumentor.py @@ -0,0 +1,81 @@ +from typing import Iterator +from unittest.mock import MagicMock + +import pytest +from opentelemetry import trace as trace_api +from opentelemetry.sdk import trace as trace_sdk +from opentelemetry.sdk.trace.export import SimpleSpanProcessor +from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter +from opentelemetry.util._importlib_metadata import entry_points + +from openinference.instrumentation.google_adk import GoogleADKInstrumentor + + +@pytest.fixture +def in_memory_span_exporter() -> InMemorySpanExporter: + return InMemorySpanExporter() + + +@pytest.fixture +def tracer_provider( + in_memory_span_exporter: InMemorySpanExporter, +) -> trace_api.TracerProvider: + tracer_provider = trace_sdk.TracerProvider() + span_processor = SimpleSpanProcessor(span_exporter=in_memory_span_exporter) + tracer_provider.add_span_processor(span_processor=span_processor) + return tracer_provider + + +@pytest.fixture +def instrument( + tracer_provider: trace_api.TracerProvider, + in_memory_span_exporter: InMemorySpanExporter, +) -> Iterator[None]: + GoogleADKInstrumentor().instrument(tracer_provider=tracer_provider) + yield + GoogleADKInstrumentor().uninstrument() + + +def test_entrypoint_for_opentelemetry_instrument() -> None: + (instrumentor_entrypoint,) = entry_points(group="opentelemetry_instrumentor", name="google_adk") + instrumentor = instrumentor_entrypoint.load()() + assert isinstance(instrumentor, GoogleADKInstrumentor) + + +def test_google_adk_instrumentor(instrument, in_memory_span_exporter: InMemorySpanExporter): + from google.adk.agents.llm_agent import LlmAgent + + agent = LlmAgent(name="agent") + context = MagicMock() + context.agent_name = "agent" + + llm_request = MagicMock() + llm_request.model = "model" + + llm_response = MagicMock() + llm_response.content.model_dump.return_value = {"response": "yes"} + + tool = MagicMock() + tool.name = "tool" + + agent.before_agent_callback(context) + + agent.before_model_callback(context, llm_request) + agent.after_model_callback(context, llm_response) + + agent.before_tool_callback(tool, {}, context) + agent.after_tool_callback(tool, {}, context, "tool response") + + agent.after_agent_callback(context) + + assert len(in_memory_span_exporter._finished_spans) == 3 + assert in_memory_span_exporter._finished_spans[0].name == "agent-LLM" + assert in_memory_span_exporter._finished_spans[1].name == "agent-TOOL" + assert in_memory_span_exporter._finished_spans[2].name == "agent-AGENT" + + assert in_memory_span_exporter._finished_spans[0].attributes["llm.model_name"] == "model" + assert in_memory_span_exporter._finished_spans[1].attributes["tool.name"] == "tool" + + parent_id = in_memory_span_exporter._finished_spans[2].context.span_id + assert in_memory_span_exporter._finished_spans[0].parent.span_id == parent_id + assert in_memory_span_exporter._finished_spans[1].parent.span_id == parent_id diff --git a/python/tox.ini b/python/tox.ini index 92f50e6e2..bb7c82ae0 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -8,6 +8,7 @@ envlist = py3{9,13}-ci-{mistralai,mistralai-latest} py3{9,13}-ci-{openai,openai-latest} py3{9,13}-ci-{openai_agents,openai_agents-latest} + py3{9,13}-ci-{google_adk,google_adk-latest} py3{9,13}-ci-{vertexai,vertexai-latest} py3{9,13}-ci-{llama_index,llama_index-latest} py3{9,13}-ci-{dspy,dspy-latest} @@ -39,6 +40,7 @@ changedir = mistralai: instrumentation/openinference-instrumentation-mistralai/ openai: instrumentation/openinference-instrumentation-openai/ openai_agents: instrumentation/openinference-instrumentation-openai-agents/ + google_adk: instrumentation/openinference-instrumentation-google-adk/ vertexai: instrumentation/openinference-instrumentation-vertexai/ llama_index: instrumentation/openinference-instrumentation-llama-index/ dspy: instrumentation/openinference-instrumentation-dspy/ @@ -75,6 +77,11 @@ commands_pre = openai_agents: python -c 'import openinference.instrumentation.openai_agents' openai_agents: uv pip install -r test-requirements.txt openai_agents-latest: uv pip install -U openai_agents + google_adk: uv pip uninstall -r test-requirements.txt + google_adk: uv pip install --reinstall-package openinference-instrumentation-google-adk . + google_adk: python -c 'import openinference.instrumentation.google_adk' + google_adk: uv pip install -r test-requirements.txt + google_adk-latest: uv pip install -U google_adk vertexai: uv pip install --reinstall {toxinidir}/instrumentation/openinference-instrumentation-vertexai[test] vertexai-latest: uv pip install -U vertexai llama_index: uv pip uninstall -r test-requirements.txt From efcc02766211a2ad7c01a0bc97c1d46b5d077cc2 Mon Sep 17 00:00:00 2001 From: daavoo Date: Wed, 30 Apr 2025 15:42:52 +0200 Subject: [PATCH 2/7] Fix OpenAI copy-paste --- .../openinference-instrumentation-google-adk/README.md | 2 +- .../openinference-instrumentation-google-adk/pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/instrumentation/openinference-instrumentation-google-adk/README.md b/python/instrumentation/openinference-instrumentation-google-adk/README.md index eae7fd834..cfc1d46d7 100644 --- a/python/instrumentation/openinference-instrumentation-google-adk/README.md +++ b/python/instrumentation/openinference-instrumentation-google-adk/README.md @@ -14,7 +14,7 @@ pip install openinference-instrumentation-google-adk ## Quickstart -In this example we will instrument a small program that uses OpenAI and observe the traces via [`arize-phoenix`](https://github.com/Arize-ai/phoenix). +In this example we will instrument a small program that uses Gemini and observe the traces via [`arize-phoenix`](https://github.com/Arize-ai/phoenix). Install packages. diff --git a/python/instrumentation/openinference-instrumentation-google-adk/pyproject.toml b/python/instrumentation/openinference-instrumentation-google-adk/pyproject.toml index d4c677858..bab670616 100644 --- a/python/instrumentation/openinference-instrumentation-google-adk/pyproject.toml +++ b/python/instrumentation/openinference-instrumentation-google-adk/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "hatchling.build" [project] name = "openinference-instrumentation-google-adk" dynamic = ["version"] -description = "OpenInference OpenAI Agents Instrumentation" +description = "OpenInference Google ADK Instrumentation" readme = "README.md" license = "Apache-2.0" requires-python = ">=3.9, <3.14" From 5481382a99f9f60258899337d841ae55806a3fa1 Mon Sep 17 00:00:00 2001 From: daavoo Date: Wed, 30 Apr 2025 15:46:41 +0200 Subject: [PATCH 3/7] ruff format --- .../examples/basic.py | 22 +++++++--------- .../examples/tools.py | 26 +++++++++---------- .../instrumentation/google_adk/__init__.py | 4 +-- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/python/instrumentation/openinference-instrumentation-google-adk/examples/basic.py b/python/instrumentation/openinference-instrumentation-google-adk/examples/basic.py index f77699e1c..920aea725 100644 --- a/python/instrumentation/openinference-instrumentation-google-adk/examples/basic.py +++ b/python/instrumentation/openinference-instrumentation-google-adk/examples/basic.py @@ -18,32 +18,30 @@ GoogleADKInstrumentor().instrument(tracer_provider=tracer_provider) agent = Agent( - name="Assistant", - model="gemini-2.0-flash-exp", - description="A helpful assistant.", - instruction="You are a helpful assistant.", + name="Assistant", + model="gemini-2.0-flash-exp", + description="A helpful assistant.", + instruction="You are a helpful assistant.", ) + async def main(): app_name = "test_instrumentation" user_id = "test_user" session_id = "test_session" runner = InMemoryRunner(agent=agent, app_name=app_name) session_service = runner.session_service - session_service.create_session( - app_name=app_name, - user_id=user_id, - session_id=session_id - ) + session_service.create_session(app_name=app_name, user_id=user_id, session_id=session_id) async for event in runner.run_async( user_id=user_id, session_id=session_id, - new_message=types.Content(role="user", parts=[ - types.Part(text="Write a haiku about recursion in programming.")] - ) + new_message=types.Content( + role="user", parts=[types.Part(text="Write a haiku about recursion in programming.")] + ), ): if event.is_final_response(): print(event.content.parts[0].text.strip()) + if __name__ == "__main__": asyncio.run(main()) diff --git a/python/instrumentation/openinference-instrumentation-google-adk/examples/tools.py b/python/instrumentation/openinference-instrumentation-google-adk/examples/tools.py index 6476e81eb..de80f6e51 100644 --- a/python/instrumentation/openinference-instrumentation-google-adk/examples/tools.py +++ b/python/instrumentation/openinference-instrumentation-google-adk/examples/tools.py @@ -17,6 +17,7 @@ GoogleADKInstrumentor().instrument(tracer_provider=tracer_provider) + def get_weather(city: str) -> dict: """Retrieves the current weather report for a specified city. @@ -40,34 +41,33 @@ def get_weather(city: str) -> dict: "error_message": f"Weather information for '{city}' is not available.", } + agent = Agent( - name="test_agent", - model="gemini-2.0-flash-exp", - description="Agent to answer questions using tools.", - instruction="You must use the available tools to find an answer.", - tools=[get_weather] + name="test_agent", + model="gemini-2.0-flash-exp", + description="Agent to answer questions using tools.", + instruction="You must use the available tools to find an answer.", + tools=[get_weather], ) + async def main(): app_name = "test_instrumentation" user_id = "test_user" session_id = "test_session" runner = InMemoryRunner(agent=agent, app_name=app_name) session_service = runner.session_service - session_service.create_session( - app_name=app_name, - user_id=user_id, - session_id=session_id - ) + session_service.create_session(app_name=app_name, user_id=user_id, session_id=session_id) async for event in runner.run_async( user_id=user_id, session_id=session_id, - new_message=types.Content(role="user", parts=[ - types.Part(text="What is the weather in New York?")] - ) + new_message=types.Content( + role="user", parts=[types.Part(text="What is the weather in New York?")] + ), ): if event.is_final_response(): print(event.content.parts[0].text.strip()) + if __name__ == "__main__": asyncio.run(main()) diff --git a/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/__init__.py b/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/__init__.py index 4f791bbfe..7f7a9221d 100644 --- a/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/__init__.py +++ b/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/__init__.py @@ -2,7 +2,7 @@ from typing import Any, Collection from opentelemetry import trace as trace_api -from opentelemetry.instrumentation.instrumentor import BaseInstrumentor #type: ignore[attr-defined] +from opentelemetry.instrumentation.instrumentor import BaseInstrumentor # type: ignore[attr-defined] from wrapt import wrap_object_attribute from openinference.instrumentation import OITracer, TraceConfig @@ -41,7 +41,7 @@ def _instrument(self, **kwargs: Any) -> None: callback = GoogleADKTracingCallback(tracer=self._tracer) - def callback_factory(value, *args, **kwargs): #type: ignore[no-untyped-def] + def callback_factory(value, *args, **kwargs): # type: ignore[no-untyped-def] # Honor any callback passed by the user kwargs["callback_parent"]._original_value = value return kwargs["callback_wrapper"] From 869b2d9da5b11cb75b437aaaa4bce280bf7a365d Mon Sep 17 00:00:00 2001 From: daavoo Date: Wed, 30 Apr 2025 15:47:25 +0200 Subject: [PATCH 4/7] ruff check --- .../examples/basic.py | 4 ++-- .../examples/tools.py | 4 ++-- .../src/openinference/instrumentation/google_adk/__init__.py | 4 +++- .../src/openinference/instrumentation/google_adk/_callback.py | 1 + 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/python/instrumentation/openinference-instrumentation-google-adk/examples/basic.py b/python/instrumentation/openinference-instrumentation-google-adk/examples/basic.py index 920aea725..2453b6e0a 100644 --- a/python/instrumentation/openinference-instrumentation-google-adk/examples/basic.py +++ b/python/instrumentation/openinference-instrumentation-google-adk/examples/basic.py @@ -3,12 +3,12 @@ from google.adk.agents import Agent from google.adk.runners import InMemoryRunner from google.genai import types - -from openinference.instrumentation.google_adk import GoogleADKInstrumentor from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter from opentelemetry.sdk import trace as trace_sdk from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor +from openinference.instrumentation.google_adk import GoogleADKInstrumentor + endpoint = "http://127.0.0.1:6006/v1/traces" tracer_provider = trace_sdk.TracerProvider() tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint))) diff --git a/python/instrumentation/openinference-instrumentation-google-adk/examples/tools.py b/python/instrumentation/openinference-instrumentation-google-adk/examples/tools.py index de80f6e51..15b71a59a 100644 --- a/python/instrumentation/openinference-instrumentation-google-adk/examples/tools.py +++ b/python/instrumentation/openinference-instrumentation-google-adk/examples/tools.py @@ -3,12 +3,12 @@ from google.adk.agents import Agent from google.adk.runners import InMemoryRunner from google.genai import types - -from openinference.instrumentation.google_adk import GoogleADKInstrumentor from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter from opentelemetry.sdk import trace as trace_sdk from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor +from openinference.instrumentation.google_adk import GoogleADKInstrumentor + endpoint = "http://127.0.0.1:6006/v1/traces" tracer_provider = trace_sdk.TracerProvider() tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint))) diff --git a/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/__init__.py b/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/__init__.py index 7f7a9221d..c577d2a11 100644 --- a/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/__init__.py +++ b/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/__init__.py @@ -2,7 +2,9 @@ from typing import Any, Collection from opentelemetry import trace as trace_api -from opentelemetry.instrumentation.instrumentor import BaseInstrumentor # type: ignore[attr-defined] +from opentelemetry.instrumentation.instrumentor import ( + BaseInstrumentor, # type: ignore[attr-defined] +) from wrapt import wrap_object_attribute from openinference.instrumentation import OITracer, TraceConfig diff --git a/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/_callback.py b/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/_callback.py index 20d7bbf92..270e57dec 100644 --- a/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/_callback.py +++ b/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/_callback.py @@ -20,6 +20,7 @@ from google.adk.models.llm_response import LlmResponse from google.adk.tools.base_tool import BaseTool from google.adk.tools.tool_context import ToolContext + from openinference.instrumentation import OITracer From d62d85a9c7ebbc80ef46e2a83830858de4a5124f Mon Sep 17 00:00:00 2001 From: daavoo Date: Wed, 30 Apr 2025 15:48:24 +0200 Subject: [PATCH 5/7] Fix type ignore --- .../src/openinference/instrumentation/google_adk/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/__init__.py b/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/__init__.py index c577d2a11..8add5788d 100644 --- a/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/__init__.py +++ b/python/instrumentation/openinference-instrumentation-google-adk/src/openinference/instrumentation/google_adk/__init__.py @@ -2,8 +2,8 @@ from typing import Any, Collection from opentelemetry import trace as trace_api -from opentelemetry.instrumentation.instrumentor import ( - BaseInstrumentor, # type: ignore[attr-defined] +from opentelemetry.instrumentation.instrumentor import ( # type: ignore[attr-defined] + BaseInstrumentor, ) from wrapt import wrap_object_attribute From 2b95e9d36f886a436992174d68fae2ffdbef01de Mon Sep 17 00:00:00 2001 From: Mikyo King Date: Mon, 5 May 2025 23:11:22 -0600 Subject: [PATCH 6/7] add release please --- release-please-config.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/release-please-config.json b/release-please-config.json index a49aef6e6..287d2938d 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -94,6 +94,10 @@ "python/instrumentation/openinference-instrumentation-google-genai": { "package-name": "python-openinference-instrumentation-google-genai", "release-type": "python" + }, + "python/instrumentation/openinference-instrumentation-google-adk": { + "package-name": "python-openinference-instrumentation-google-adk", + "release-type": "python" } } } From 8cf7b96b855dc4c2e60c68b3f05101d5e925e8e4 Mon Sep 17 00:00:00 2001 From: Mikyo King Date: Mon, 5 May 2025 23:18:28 -0600 Subject: [PATCH 7/7] add to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5a0eee532..bd7705ef5 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ OpenInference provides a set of instrumentations for popular machine learning SD | [`openinference-instrumentation-anthropic`](./python/instrumentation/openinference-instrumentation-anthropic) | OpenInference Instrumentation for Anthropic. | [![PyPI Version](https://img.shields.io/pypi/v/openinference-instrumentation-anthropic.svg)](https://pypi.python.org/pypi/openinference-instrumentation-anthropic) | | [`openinference-instrumentation-beeai`](./python/instrumentation/openinference-instrumentation-beeai) | OpenInference Instrumentation for BeeAI. | [![PyPI Version](https://img.shields.io/pypi/v/openinference-instrumentation-beeai.svg)](https://pypi.python.org/pypi/openinference-instrumentation-beeai) | | [`openinference-instrumentation-google-genai`](./python/instrumentation/openinference-instrumentation-google-genai) | OpenInference Instrumentation for Google GenAI. | [![PyPI Version](https://img.shields.io/pypi/v/openinference-instrumentation-google-genai.svg)](https://pypi.python.org/pypi/openinference-instrumentation-google-genai) | +| [`openinference-instrumentation-google-adk`](./python/instrumentation/openinference-instrumentation-google-adk) | OpenInference Instrumentation for Google ADK. | [![PyPI Version](https://img.shields.io/pypi/v/openinference-instrumentation-google-adk.svg)](https://pypi.python.org/pypi/openinference-instrumentation-google-adk) | ### Examples