feat(google-genai): instrumentation for google-genai
Fixes #2675
- [X] I have added tests that cover my changes.
- [X] If adding a new instrumentation or changing an existing one, I've added screenshots from some observability platform showing the change.
- [X] PR name follows conventional commits format:
feat(instrumentation): ...orfix(instrumentation): .... - [X] (If applicable) I have updated the documentation accordingly. --> I checked and it looks like the README already claims we instrument Google gemini
[!IMPORTANT] Introduces Google GenAI instrumentation with tracing capabilities, configuration, utilities, and comprehensive tests, along with project setup and version update.
- New Instrumentation:
- Adds
GoogleGenAiInstrumentorin__init__.pyfor tracing Google GenAI API calls.- Supports synchronous and asynchronous methods for
generate_contentandgenerate_content_stream.- Attributes like model, temperature, and token usage are captured.
- Configuration and Utilities:
- Adds
Configclass inconfig.pyfor exception logging.- Utility functions in
utils.pyfor handling span attributes and exceptions.- Testing:
- Adds unit tests in
test_generate_content.pyfor various scenarios including async and streaming.- Uses VCR cassettes for HTTP request recording in
tests/cassettes/.- Project Setup:
- Adds
pyproject.toml,poetry.toml, andproject.jsonfor project configuration.- Includes
.flake8for linting configuration.- Version Update:
- Updates version in
version.pyto0.39.2.This description was created by
for f9c0b0edf1d8bc2b27595a1f25635ac3bf8a6d25. You can customize this summary. It will automatically update as commits are pushed.
Does this share / reuse the instrumentation in the contrib repo?
https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation-genai/opentelemetry-instrumentation-google-genai
@michaelsafyan No, but I guess it should.
My PR does instrument google_genai, but is certainly worse (both the code quality and functionality) than the contrib library mentioned. However, it sends the prompt/completion contents as attributes, while the new library does so as log events (accepted semconv).
I don't think it's easy to mix up two instrumentors for the same library. @nirga What are your thoughts on this? I remember, you mentioned a potential mechanism that would convert log events to span attributes, is there a prototype? Feel free to close this PR in favor of the contrib library
I think it would be better to have Traceloop wrap/invoke the OTel Contrib instrumentation. That way, more (joint) effort can be put into improving the (shared) instrumentation for the Google Gen AI instrumentation library rather than competing efforts. That work could include adding options to support multiple different kinds of output formats.
I completely agree, @michaelsafyan! The main blocker right now is aligning on the attribute format, since we can't use the current events format that's implemented. Once we finalize that, we can move forward with switching to the contrib implementation.
Mind adding them?
Sure will do