Skip to content

feat(google_genai): [MLOB-2932] add apm tracing for google-genai #13650

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

Draft
wants to merge 73 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
0f7eb0f
skeleton for google gen ai integration
maxzhangdd Jun 9, 2025
fc11773
more skeleton, added to settings/_config.py
maxzhangdd Jun 10, 2025
4bc8e81
get span attributes from request
maxzhangdd Jun 10, 2025
b6774bf
add skeleton methods to GoogleGenAI Integration
maxzhangdd Jun 10, 2025
245dd33
incremental progress on tagging request response
maxzhangdd Jun 10, 2025
88a6346
updated tag_response
maxzhangdd Jun 11, 2025
dbe7406
added llmobs_set_tags to traced_generate
maxzhangdd Jun 11, 2025
3c0bffd
changed normalize_contents, progress on tag_response and tag_request
maxzhangdd Jun 11, 2025
d8abc0c
simplify code to just apm tracing, also added provider extraction
maxzhangdd Jun 11, 2025
37cda72
change CODEOWNERS
maxzhangdd Jun 11, 2025
4183303
add tests
maxzhangdd Jun 13, 2025
95365d6
add test for extract_provider_and_model_name_genai
maxzhangdd Jun 13, 2025
c8963b6
linting, add ignore arg on snapshot
maxzhangdd Jun 13, 2025
aa3eaab
fix bare except
maxzhangdd Jun 13, 2025
f6549b4
more linting checks
maxzhangdd Jun 13, 2025
545c3a5
modified suitespec
maxzhangdd Jun 13, 2025
a9e197b
add google_genai component
maxzhangdd Jun 13, 2025
72ae21b
change google_genai component
maxzhangdd Jun 13, 2025
fd72fa7
fix min_compatible_versions, changed config, changed doc
maxzhangdd Jun 13, 2025
b9d5720
lint fix
maxzhangdd Jun 13, 2025
977ac43
ruff
maxzhangdd Jun 13, 2025
7f6e417
add supported versions
maxzhangdd Jun 13, 2025
87952f2
lint
maxzhangdd Jun 13, 2025
a6ee277
add _supported_versions as a method
maxzhangdd Jun 13, 2025
2115a0a
change to match module name
maxzhangdd Jun 13, 2025
15b759f
addded ignore error.message
maxzhangdd Jun 13, 2025
156c69c
fixed ignore error.message
maxzhangdd Jun 13, 2025
e5e9341
wrap generate_content_stream
maxzhangdd Jun 16, 2025
c6e8389
testing for generate_content_stream
maxzhangdd Jun 16, 2025
29fd0e5
linting
maxzhangdd Jun 16, 2025
d462cde
update doc
maxzhangdd Jun 16, 2025
dc9d313
Merge branch 'main' into maxzhang/google-genai-integration
maxzhangdd Jun 16, 2025
58c73e0
release note
maxzhangdd Jun 16, 2025
465e701
added to integrations.rst
maxzhangdd Jun 16, 2025
24d19ac
Update ddtrace/contrib/_google_genai.py
maxzhangdd Jun 16, 2025
6b74729
Update ddtrace/contrib/_google_genai.py
maxzhangdd Jun 16, 2025
769cdb9
Update ddtrace/llmobs/_integrations/google_genai.py
maxzhangdd Jun 16, 2025
05e50fe
Update ddtrace/contrib/internal/google_genai/_utils.py
maxzhangdd Jun 16, 2025
7659f71
Update ddtrace/contrib/internal/google_genai/_utils.py
maxzhangdd Jun 16, 2025
062a6aa
add async generate and generate_stream
maxzhangdd Jun 16, 2025
72b6109
fix comments, more async changes
maxzhangdd Jun 16, 2025
505be8b
testing for async and async streaming
maxzhangdd Jun 16, 2025
7b8564a
linting + add a missed cassette
maxzhangdd Jun 16, 2025
caa7c24
linting
maxzhangdd Jun 17, 2025
cd2ed4f
add test for vertex
maxzhangdd Jun 17, 2025
d4e3bf7
set env vars
maxzhangdd Jun 17, 2025
1dc8558
ignore metadata requests
maxzhangdd Jun 17, 2025
7b448e0
linting
maxzhangdd Jun 17, 2025
ae82d6f
stop ignoring auths, blank out secrets
maxzhangdd Jun 17, 2025
a9aee36
testing changes for vertex
maxzhangdd Jun 17, 2025
1a1e7cf
try mocking gce to prevent remote credential check
maxzhangdd Jun 17, 2025
25e7c73
linting
maxzhangdd Jun 17, 2025
5a8b350
Update ddtrace/contrib/_google_genai.py
maxzhangdd Jun 17, 2025
f0a8d0e
Update ddtrace/contrib/internal/google_genai/_utils.py
maxzhangdd Jun 17, 2025
ed9d83d
Update ddtrace/contrib/internal/google_genai/_utils.py
maxzhangdd Jun 17, 2025
370dcf5
Update ddtrace/contrib/internal/google_genai/_utils.py
maxzhangdd Jun 17, 2025
e0bbe1f
Update tests/contrib/google_genai/test_google_genai.py
maxzhangdd Jun 17, 2025
c70af6e
Update ddtrace/contrib/internal/google_genai/patch.py
maxzhangdd Jun 17, 2025
cfd96ff
Update ddtrace/contrib/internal/google_genai/patch.py
maxzhangdd Jun 17, 2025
c9694cc
Update tests/contrib/google_genai/conftest.py
maxzhangdd Jun 17, 2025
eb33c02
Update tests/contrib/google_genai/conftest.py
maxzhangdd Jun 17, 2025
f16b9b5
Update tests/contrib/google_genai/conftest.py
maxzhangdd Jun 17, 2025
2aef56b
resolving comments
maxzhangdd Jun 17, 2025
ade4b18
change riotfile, deduplicate cassettes and snapshots
maxzhangdd Jun 17, 2025
5457a43
linting
maxzhangdd Jun 17, 2025
9410a72
Merge branch 'main' into maxzhang/google-genai-integration
maxzhangdd Jun 17, 2025
ff784fa
linting
maxzhangdd Jun 17, 2025
2504406
fix spelling, supported versions
maxzhangdd Jun 17, 2025
23ab599
change supported_verions
maxzhangdd Jun 17, 2025
efdb368
Merge branch 'main' into maxzhang/google-genai-integration
maxzhangdd Jun 18, 2025
977aa82
potential fix for vertex test
maxzhangdd Jun 18, 2025
0fcd51e
Merge branch 'main' into maxzhang/google-genai-integration
maxzhangdd Jun 18, 2025
66a350a
add message on vertex cassette
maxzhangdd Jun 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ ddtrace/contrib/internal/anthropic @DataDog/ml-observ
ddtrace/contrib/_anthropic.py @DataDog/ml-observability
ddtrace/contrib/internal/google_generativeai @DataDog/ml-observability
ddtrace/contrib/_google_generativeai.py @DataDog/ml-observability
ddtrace/contrib/internal/google_genai @DataDog/ml-observability
ddtrace/contrib/_google_genai.py @DataDog/ml-observability
ddtrace/contrib/internal/vertexai @DataDog/ml-observability
ddtrace/contrib/_vertexai.py @DataDog/ml-observability
ddtrace/contrib/internal/langgraph @DataDog/ml-observability
Expand Down
48 changes: 48 additions & 0 deletions .riot/requirements/1de4a65.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/1de4a65.in
#
annotated-types==0.7.0
anyio==4.9.0
attrs==25.3.0
cachetools==5.5.2
certifi==2025.4.26
charset-normalizer==3.4.2
coverage[toml]==7.9.0
google-auth==2.40.3
google-genai==1.20.0
h11==0.16.0
httpcore==1.0.9
httpx==0.28.1
hypothesis==6.45.0
idna==3.10
iniconfig==2.1.0
mock==5.2.0
multidict==6.4.4
opentracing==2.4.0
packaging==25.0
pluggy==1.6.0
propcache==0.3.2
pyasn1==0.6.1
pyasn1-modules==0.4.2
pydantic==2.11.5
pydantic-core==2.33.2
pygments==2.19.1
pytest==8.4.0
pytest-asyncio==1.0.0
pytest-cov==6.2.1
pytest-mock==3.14.1
pyyaml==6.0.2
requests==2.32.4
rsa==4.9.1
sniffio==1.3.1
sortedcontainers==2.4.0
typing-extensions==4.14.0
typing-inspection==0.4.1
urllib3==2.4.0
vcrpy==7.0.0
websockets==15.0.1
wrapt==1.17.2
yarl==1.20.1
50 changes: 50 additions & 0 deletions .riot/requirements/7d83e7d.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/7d83e7d.in
#
annotated-types==0.7.0
anyio==4.9.0
attrs==25.3.0
cachetools==5.5.2
certifi==2025.4.26
charset-normalizer==3.4.2
coverage[toml]==7.9.0
exceptiongroup==1.3.0
google-auth==2.40.3
google-genai==1.20.0
h11==0.16.0
httpcore==1.0.9
httpx==0.28.1
hypothesis==6.45.0
idna==3.10
iniconfig==2.1.0
mock==5.2.0
multidict==6.4.4
opentracing==2.4.0
packaging==25.0
pluggy==1.6.0
propcache==0.3.2
pyasn1==0.6.1
pyasn1-modules==0.4.2
pydantic==2.11.5
pydantic-core==2.33.2
pygments==2.19.1
pytest==8.4.0
pytest-asyncio==1.0.0
pytest-cov==6.2.1
pytest-mock==3.14.1
pyyaml==6.0.2
requests==2.32.4
rsa==4.9.1
sniffio==1.3.1
sortedcontainers==2.4.0
tomli==2.2.1
typing-extensions==4.14.0
typing-inspection==0.4.1
urllib3==2.4.0
vcrpy==7.0.0
websockets==15.0.1
wrapt==1.17.2
yarl==1.20.1
48 changes: 48 additions & 0 deletions .riot/requirements/97b1ae2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# This file is autogenerated by pip-compile with Python 3.13
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/97b1ae2.in
#
annotated-types==0.7.0
anyio==4.9.0
attrs==25.3.0
cachetools==5.5.2
certifi==2025.6.15
charset-normalizer==3.4.2
coverage[toml]==7.9.1
google-auth==2.40.3
google-genai==1.20.0
h11==0.16.0
httpcore==1.0.9
httpx==0.28.1
hypothesis==6.45.0
idna==3.10
iniconfig==2.1.0
mock==5.2.0
multidict==6.5.0
opentracing==2.4.0
packaging==25.0
pluggy==1.6.0
propcache==0.3.2
pyasn1==0.6.1
pyasn1-modules==0.4.2
pydantic==2.11.7
pydantic-core==2.33.2
pygments==2.19.1
pytest==8.4.0
pytest-asyncio==1.0.0
pytest-cov==6.2.1
pytest-mock==3.14.1
pyyaml==6.0.2
requests==2.32.4
rsa==4.9.1
sniffio==1.3.1
sortedcontainers==2.4.0
typing-extensions==4.14.0
typing-inspection==0.4.1
urllib3==2.4.0
vcrpy==7.0.0
websockets==15.0.1
wrapt==1.17.2
yarl==1.20.1
48 changes: 48 additions & 0 deletions .riot/requirements/ce785c0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/ce785c0.in
#
annotated-types==0.7.0
anyio==4.9.0
attrs==25.3.0
cachetools==5.5.2
certifi==2025.4.26
charset-normalizer==3.4.2
coverage[toml]==7.9.0
google-auth==2.40.3
google-genai==1.20.0
h11==0.16.0
httpcore==1.0.9
httpx==0.28.1
hypothesis==6.45.0
idna==3.10
iniconfig==2.1.0
mock==5.2.0
multidict==6.4.4
opentracing==2.4.0
packaging==25.0
pluggy==1.6.0
propcache==0.3.2
pyasn1==0.6.1
pyasn1-modules==0.4.2
pydantic==2.11.5
pydantic-core==2.33.2
pygments==2.19.1
pytest==8.4.0
pytest-asyncio==1.0.0
pytest-cov==6.2.1
pytest-mock==3.14.1
pyyaml==6.0.2
requests==2.32.4
rsa==4.9.1
sniffio==1.3.1
sortedcontainers==2.4.0
typing-extensions==4.14.0
typing-inspection==0.4.1
urllib3==2.4.0
vcrpy==7.0.0
websockets==15.0.1
wrapt==1.17.2
yarl==1.20.1
50 changes: 50 additions & 0 deletions .riot/requirements/f5e518d.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/f5e518d.in
#
annotated-types==0.7.0
anyio==4.9.0
attrs==25.3.0
cachetools==5.5.2
certifi==2025.4.26
charset-normalizer==3.4.2
coverage[toml]==7.9.0
exceptiongroup==1.3.0
google-auth==2.40.3
google-genai==1.20.0
h11==0.16.0
httpcore==1.0.9
httpx==0.28.1
hypothesis==6.45.0
idna==3.10
iniconfig==2.1.0
mock==5.2.0
multidict==6.4.4
opentracing==2.4.0
packaging==25.0
pluggy==1.6.0
propcache==0.3.2
pyasn1==0.6.1
pyasn1-modules==0.4.2
pydantic==2.11.5
pydantic-core==2.33.2
pygments==2.19.1
pytest==8.4.0
pytest-asyncio==1.0.0
pytest-cov==6.2.1
pytest-mock==3.14.1
pyyaml==6.0.2
requests==2.32.4
rsa==4.9.1
sniffio==1.3.1
sortedcontainers==2.4.0
tomli==2.2.1
typing-extensions==4.14.0
typing-inspection==0.4.1
urllib3==1.26.20
vcrpy==7.0.0
websockets==15.0.1
wrapt==1.17.2
yarl==1.20.1
2 changes: 2 additions & 0 deletions ddtrace/_monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"futures": True,
"freezegun": True,
"google_generativeai": True,
"google_genai": True,
"gevent": True,
"graphql": True,
"grpc": True,
Expand Down Expand Up @@ -160,6 +161,7 @@
"httplib": ("http.client",),
"kafka": ("confluent_kafka",),
"google_generativeai": ("google.generativeai",),
"google_genai": ("google.genai",),
"langgraph": (
"langgraph",
"langgraph.graph",
Expand Down
48 changes: 48 additions & 0 deletions ddtrace/contrib/_google_genai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
The Google GenAI integration instruments the Google GenAI Python SDK to trace LLM requests made to
Gemini and VertexAI models.

All traces submitted from the Google GenAI integration are tagged by:

- ``service``, ``env``, ``version``: see the `Unified Service Tagging docs <https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging>`_.
- model used in the request.
- provider used in the request.


Enabling
~~~~~~~~

The Google GenAI integration is enabled automatically when you use
:ref:`ddtrace-run<ddtracerun>` or :ref:`import ddtrace.auto<ddtraceauto>`.

Alternatively, use :func:`patch() <ddtrace.patch>` to manually enable the Google GenAI integration::

from ddtrace import config, patch

patch(google_genai=True)

Global Configuration
~~~~~~~~~~~~~~~~~~~~

.. py:data:: ddtrace.config.google_genai["service"]

The service name reported by default for Google GenAI requests.

Alternatively, you can set this option with the ``DD_SERVICE`` or ``DD_GOOGLE_GENAI_SERVICE`` environment
variables.

Default: ``DD_SERVICE``


Instance Configuration
~~~~~~~~~~~~~~~~~~~~~~

To configure the Google GenAI integration on a per-instance basis use the
``Pin`` API::

from google import genai
from ddtrace import config
from ddtrace.trace import Pin

Pin.override(genai, service="my-google-genai-service")
"""
10 changes: 10 additions & 0 deletions ddtrace/contrib/integration_registry/registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,16 @@ integrations:
min: 20.12.1
max: 24.11.1

- integration_name: google_genai
is_external_package: true
is_tested: true
dependency_names:
- google-genai
tested_versions_by_dependency:
google-genai:
min: 1.19.0
max: 1.20.0

- integration_name: google_generativeai
is_external_package: true
is_tested: true
Expand Down
Loading
Loading