Skip to content

Commit c09a299

Browse files
michaelsafyanxrmxaabmass
authored
Initial version of instrumentation for the Google GenAI SDK (github.com/googleapis/python-genai) (#3256)
* Begin instrumentation of GenAI SDK. * Snapshot current state. * Created minimal tests and got first test to pass. * Added test for span attributes. * Ensure that token counts work. * Add more tests. * Make it easy to turn off instrumentation for streaming and async to allow for rapid iteration. * Add licenses and fill out main README.rst. * Add a changelog file. * Fill out 'requirements.txt' and 'README.rst' for the manual instrumentation example. * Add missing exporter dependency for the manual instrumentation example. * Fill out rest of the zero-code example. * Add minimal tests for async, streaming cases. * Update sync test to use indirection on top of 'client.models.generate_content' to simplify test reuse. * Fix ruff check issues. * Add subproject to top-level project build mechanism. * Simplify invocation of pylint. * Fix 'make test' command and lint issues. * Add '.dev' suffix to version per feedback on pull request #3256 * Fix README.rst files for the examples. * Add specific versions for the examples. * Revamp 'make test' to not require local 'tox.ini' configuration. * Extend separators per review comment. Co-authored-by: Riccardo Magliocchetti <[email protected]> * Fix version conflict caused by non-hermetic requirements. * Fix typo on the comment line. * Add test for the use of the 'vertex_ai' system, and improve how this system is determined. * Factor out testing logic to enable sharing with the async code. * Addressed minor lint issues. * Make it clearer that nonstreaming_base is a helper module that is not invoked directly. * Integrate feedback from related pull request #3268. * Update workflows with 'tox -e generate-workflows'. * Improve data model and add some rudimentary type checking. * Accept only 'true' for a true value to align with other code. * Update the scope name used. * Add **kwargs to patched methods to prevent future breakage due to the addition of future keyword arguments. * Remove redundant list conversion in call to "sorted". Co-authored-by: Aaron Abbott <[email protected]> * Reformat with 'tox -e ruff'. * Fix failing lint workflow. * Fix failing lint workflow. * Exclude Google GenAI instrumentation from the bootstrap code for now. * Minor improvements to the tooling shell files. * Fix typo flagged by codespell spellchecker. * Increase alignment with broader repo practices. * Add more TODOs and documentation to clarify the intended work scope. * Remove unneeded accessor from OTelWrapper. * Add more comments to the tests. * Reformat with ruff. * Change 'desireable' to 'desirable' per codespell spellchecker. * Make tests pass without pythonpath * Fix new lint errors showing up after change * Revert "Fix new lint errors showing up after change" This reverts commit 567adc6. pylint ignore instead * Add TODO item required/requested from code review. Co-authored-by: Aaron Abbott <[email protected]> * Simplify changelog per PR feedback. * Remove square brackets from model name in span name per PR feedback. * Misc test cleanup. Now that scripts are invoked solely through pytest via tox, remove main functions and hash bang lines. * Improve quality of event logging. * Update operation name to use a constant for consistency. * Reformat with ruff. * Exclude opentelemetry-instrumentation-google-genai from root uv workspace Until #3300 is fixed. --------- Co-authored-by: Riccardo Magliocchetti <[email protected]> Co-authored-by: Aaron Abbott <[email protected]>
1 parent 139f3e5 commit c09a299

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3334
-366
lines changed

.github/workflows/lint_0.yml

+18
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ jobs:
5252
- name: Run tests
5353
run: tox -e lint-instrumentation-vertexai
5454

55+
lint-instrumentation-google-genai:
56+
name: instrumentation-google-genai
57+
runs-on: ubuntu-latest
58+
steps:
59+
- name: Checkout repo @ SHA - ${{ github.sha }}
60+
uses: actions/checkout@v4
61+
62+
- name: Set up Python 3.13
63+
uses: actions/setup-python@v5
64+
with:
65+
python-version: "3.13"
66+
67+
- name: Install tox
68+
run: pip install tox-uv
69+
70+
- name: Run tests
71+
run: tox -e lint-instrumentation-google-genai
72+
5573
lint-resource-detector-container:
5674
name: resource-detector-container
5775
runs-on: ubuntu-latest

.github/workflows/test_0.yml

+180-180
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,186 @@ jobs:
484484
- name: Run tests
485485
run: tox -e py313-test-instrumentation-vertexai-latest -- -ra
486486

487+
py39-test-instrumentation-google-genai-oldest_ubuntu-latest:
488+
name: instrumentation-google-genai-oldest 3.9 Ubuntu
489+
runs-on: ubuntu-latest
490+
steps:
491+
- name: Checkout repo @ SHA - ${{ github.sha }}
492+
uses: actions/checkout@v4
493+
494+
- name: Set up Python 3.9
495+
uses: actions/setup-python@v5
496+
with:
497+
python-version: "3.9"
498+
499+
- name: Install tox
500+
run: pip install tox-uv
501+
502+
- name: Run tests
503+
run: tox -e py39-test-instrumentation-google-genai-oldest -- -ra
504+
505+
py39-test-instrumentation-google-genai-latest_ubuntu-latest:
506+
name: instrumentation-google-genai-latest 3.9 Ubuntu
507+
runs-on: ubuntu-latest
508+
steps:
509+
- name: Checkout repo @ SHA - ${{ github.sha }}
510+
uses: actions/checkout@v4
511+
512+
- name: Set up Python 3.9
513+
uses: actions/setup-python@v5
514+
with:
515+
python-version: "3.9"
516+
517+
- name: Install tox
518+
run: pip install tox-uv
519+
520+
- name: Run tests
521+
run: tox -e py39-test-instrumentation-google-genai-latest -- -ra
522+
523+
py310-test-instrumentation-google-genai-oldest_ubuntu-latest:
524+
name: instrumentation-google-genai-oldest 3.10 Ubuntu
525+
runs-on: ubuntu-latest
526+
steps:
527+
- name: Checkout repo @ SHA - ${{ github.sha }}
528+
uses: actions/checkout@v4
529+
530+
- name: Set up Python 3.10
531+
uses: actions/setup-python@v5
532+
with:
533+
python-version: "3.10"
534+
535+
- name: Install tox
536+
run: pip install tox-uv
537+
538+
- name: Run tests
539+
run: tox -e py310-test-instrumentation-google-genai-oldest -- -ra
540+
541+
py310-test-instrumentation-google-genai-latest_ubuntu-latest:
542+
name: instrumentation-google-genai-latest 3.10 Ubuntu
543+
runs-on: ubuntu-latest
544+
steps:
545+
- name: Checkout repo @ SHA - ${{ github.sha }}
546+
uses: actions/checkout@v4
547+
548+
- name: Set up Python 3.10
549+
uses: actions/setup-python@v5
550+
with:
551+
python-version: "3.10"
552+
553+
- name: Install tox
554+
run: pip install tox-uv
555+
556+
- name: Run tests
557+
run: tox -e py310-test-instrumentation-google-genai-latest -- -ra
558+
559+
py311-test-instrumentation-google-genai-oldest_ubuntu-latest:
560+
name: instrumentation-google-genai-oldest 3.11 Ubuntu
561+
runs-on: ubuntu-latest
562+
steps:
563+
- name: Checkout repo @ SHA - ${{ github.sha }}
564+
uses: actions/checkout@v4
565+
566+
- name: Set up Python 3.11
567+
uses: actions/setup-python@v5
568+
with:
569+
python-version: "3.11"
570+
571+
- name: Install tox
572+
run: pip install tox-uv
573+
574+
- name: Run tests
575+
run: tox -e py311-test-instrumentation-google-genai-oldest -- -ra
576+
577+
py311-test-instrumentation-google-genai-latest_ubuntu-latest:
578+
name: instrumentation-google-genai-latest 3.11 Ubuntu
579+
runs-on: ubuntu-latest
580+
steps:
581+
- name: Checkout repo @ SHA - ${{ github.sha }}
582+
uses: actions/checkout@v4
583+
584+
- name: Set up Python 3.11
585+
uses: actions/setup-python@v5
586+
with:
587+
python-version: "3.11"
588+
589+
- name: Install tox
590+
run: pip install tox-uv
591+
592+
- name: Run tests
593+
run: tox -e py311-test-instrumentation-google-genai-latest -- -ra
594+
595+
py312-test-instrumentation-google-genai-oldest_ubuntu-latest:
596+
name: instrumentation-google-genai-oldest 3.12 Ubuntu
597+
runs-on: ubuntu-latest
598+
steps:
599+
- name: Checkout repo @ SHA - ${{ github.sha }}
600+
uses: actions/checkout@v4
601+
602+
- name: Set up Python 3.12
603+
uses: actions/setup-python@v5
604+
with:
605+
python-version: "3.12"
606+
607+
- name: Install tox
608+
run: pip install tox-uv
609+
610+
- name: Run tests
611+
run: tox -e py312-test-instrumentation-google-genai-oldest -- -ra
612+
613+
py312-test-instrumentation-google-genai-latest_ubuntu-latest:
614+
name: instrumentation-google-genai-latest 3.12 Ubuntu
615+
runs-on: ubuntu-latest
616+
steps:
617+
- name: Checkout repo @ SHA - ${{ github.sha }}
618+
uses: actions/checkout@v4
619+
620+
- name: Set up Python 3.12
621+
uses: actions/setup-python@v5
622+
with:
623+
python-version: "3.12"
624+
625+
- name: Install tox
626+
run: pip install tox-uv
627+
628+
- name: Run tests
629+
run: tox -e py312-test-instrumentation-google-genai-latest -- -ra
630+
631+
py313-test-instrumentation-google-genai-oldest_ubuntu-latest:
632+
name: instrumentation-google-genai-oldest 3.13 Ubuntu
633+
runs-on: ubuntu-latest
634+
steps:
635+
- name: Checkout repo @ SHA - ${{ github.sha }}
636+
uses: actions/checkout@v4
637+
638+
- name: Set up Python 3.13
639+
uses: actions/setup-python@v5
640+
with:
641+
python-version: "3.13"
642+
643+
- name: Install tox
644+
run: pip install tox-uv
645+
646+
- name: Run tests
647+
run: tox -e py313-test-instrumentation-google-genai-oldest -- -ra
648+
649+
py313-test-instrumentation-google-genai-latest_ubuntu-latest:
650+
name: instrumentation-google-genai-latest 3.13 Ubuntu
651+
runs-on: ubuntu-latest
652+
steps:
653+
- name: Checkout repo @ SHA - ${{ github.sha }}
654+
uses: actions/checkout@v4
655+
656+
- name: Set up Python 3.13
657+
uses: actions/setup-python@v5
658+
with:
659+
python-version: "3.13"
660+
661+
- name: Install tox
662+
run: pip install tox-uv
663+
664+
- name: Run tests
665+
run: tox -e py313-test-instrumentation-google-genai-latest -- -ra
666+
487667
py38-test-resource-detector-container_ubuntu-latest:
488668
name: resource-detector-container 3.8 Ubuntu
489669
runs-on: ubuntu-latest
@@ -4335,183 +4515,3 @@ jobs:
43354515

43364516
- name: Run tests
43374517
run: tox -e py310-test-instrumentation-urllib3-0 -- -ra
4338-
4339-
py310-test-instrumentation-urllib3-1_ubuntu-latest:
4340-
name: instrumentation-urllib3-1 3.10 Ubuntu
4341-
runs-on: ubuntu-latest
4342-
steps:
4343-
- name: Checkout repo @ SHA - ${{ github.sha }}
4344-
uses: actions/checkout@v4
4345-
4346-
- name: Set up Python 3.10
4347-
uses: actions/setup-python@v5
4348-
with:
4349-
python-version: "3.10"
4350-
4351-
- name: Install tox
4352-
run: pip install tox-uv
4353-
4354-
- name: Run tests
4355-
run: tox -e py310-test-instrumentation-urllib3-1 -- -ra
4356-
4357-
py311-test-instrumentation-urllib3-0_ubuntu-latest:
4358-
name: instrumentation-urllib3-0 3.11 Ubuntu
4359-
runs-on: ubuntu-latest
4360-
steps:
4361-
- name: Checkout repo @ SHA - ${{ github.sha }}
4362-
uses: actions/checkout@v4
4363-
4364-
- name: Set up Python 3.11
4365-
uses: actions/setup-python@v5
4366-
with:
4367-
python-version: "3.11"
4368-
4369-
- name: Install tox
4370-
run: pip install tox-uv
4371-
4372-
- name: Run tests
4373-
run: tox -e py311-test-instrumentation-urllib3-0 -- -ra
4374-
4375-
py311-test-instrumentation-urllib3-1_ubuntu-latest:
4376-
name: instrumentation-urllib3-1 3.11 Ubuntu
4377-
runs-on: ubuntu-latest
4378-
steps:
4379-
- name: Checkout repo @ SHA - ${{ github.sha }}
4380-
uses: actions/checkout@v4
4381-
4382-
- name: Set up Python 3.11
4383-
uses: actions/setup-python@v5
4384-
with:
4385-
python-version: "3.11"
4386-
4387-
- name: Install tox
4388-
run: pip install tox-uv
4389-
4390-
- name: Run tests
4391-
run: tox -e py311-test-instrumentation-urllib3-1 -- -ra
4392-
4393-
py312-test-instrumentation-urllib3-0_ubuntu-latest:
4394-
name: instrumentation-urllib3-0 3.12 Ubuntu
4395-
runs-on: ubuntu-latest
4396-
steps:
4397-
- name: Checkout repo @ SHA - ${{ github.sha }}
4398-
uses: actions/checkout@v4
4399-
4400-
- name: Set up Python 3.12
4401-
uses: actions/setup-python@v5
4402-
with:
4403-
python-version: "3.12"
4404-
4405-
- name: Install tox
4406-
run: pip install tox-uv
4407-
4408-
- name: Run tests
4409-
run: tox -e py312-test-instrumentation-urllib3-0 -- -ra
4410-
4411-
py312-test-instrumentation-urllib3-1_ubuntu-latest:
4412-
name: instrumentation-urllib3-1 3.12 Ubuntu
4413-
runs-on: ubuntu-latest
4414-
steps:
4415-
- name: Checkout repo @ SHA - ${{ github.sha }}
4416-
uses: actions/checkout@v4
4417-
4418-
- name: Set up Python 3.12
4419-
uses: actions/setup-python@v5
4420-
with:
4421-
python-version: "3.12"
4422-
4423-
- name: Install tox
4424-
run: pip install tox-uv
4425-
4426-
- name: Run tests
4427-
run: tox -e py312-test-instrumentation-urllib3-1 -- -ra
4428-
4429-
py313-test-instrumentation-urllib3-0_ubuntu-latest:
4430-
name: instrumentation-urllib3-0 3.13 Ubuntu
4431-
runs-on: ubuntu-latest
4432-
steps:
4433-
- name: Checkout repo @ SHA - ${{ github.sha }}
4434-
uses: actions/checkout@v4
4435-
4436-
- name: Set up Python 3.13
4437-
uses: actions/setup-python@v5
4438-
with:
4439-
python-version: "3.13"
4440-
4441-
- name: Install tox
4442-
run: pip install tox-uv
4443-
4444-
- name: Run tests
4445-
run: tox -e py313-test-instrumentation-urllib3-0 -- -ra
4446-
4447-
py313-test-instrumentation-urllib3-1_ubuntu-latest:
4448-
name: instrumentation-urllib3-1 3.13 Ubuntu
4449-
runs-on: ubuntu-latest
4450-
steps:
4451-
- name: Checkout repo @ SHA - ${{ github.sha }}
4452-
uses: actions/checkout@v4
4453-
4454-
- name: Set up Python 3.13
4455-
uses: actions/setup-python@v5
4456-
with:
4457-
python-version: "3.13"
4458-
4459-
- name: Install tox
4460-
run: pip install tox-uv
4461-
4462-
- name: Run tests
4463-
run: tox -e py313-test-instrumentation-urllib3-1 -- -ra
4464-
4465-
pypy3-test-instrumentation-urllib3-0_ubuntu-latest:
4466-
name: instrumentation-urllib3-0 pypy-3.8 Ubuntu
4467-
runs-on: ubuntu-latest
4468-
steps:
4469-
- name: Checkout repo @ SHA - ${{ github.sha }}
4470-
uses: actions/checkout@v4
4471-
4472-
- name: Set up Python pypy-3.8
4473-
uses: actions/setup-python@v5
4474-
with:
4475-
python-version: "pypy-3.8"
4476-
4477-
- name: Install tox
4478-
run: pip install tox-uv
4479-
4480-
- name: Run tests
4481-
run: tox -e pypy3-test-instrumentation-urllib3-0 -- -ra
4482-
4483-
pypy3-test-instrumentation-urllib3-1_ubuntu-latest:
4484-
name: instrumentation-urllib3-1 pypy-3.8 Ubuntu
4485-
runs-on: ubuntu-latest
4486-
steps:
4487-
- name: Checkout repo @ SHA - ${{ github.sha }}
4488-
uses: actions/checkout@v4
4489-
4490-
- name: Set up Python pypy-3.8
4491-
uses: actions/setup-python@v5
4492-
with:
4493-
python-version: "pypy-3.8"
4494-
4495-
- name: Install tox
4496-
run: pip install tox-uv
4497-
4498-
- name: Run tests
4499-
run: tox -e pypy3-test-instrumentation-urllib3-1 -- -ra
4500-
4501-
py38-test-instrumentation-requests_ubuntu-latest:
4502-
name: instrumentation-requests 3.8 Ubuntu
4503-
runs-on: ubuntu-latest
4504-
steps:
4505-
- name: Checkout repo @ SHA - ${{ github.sha }}
4506-
uses: actions/checkout@v4
4507-
4508-
- name: Set up Python 3.8
4509-
uses: actions/setup-python@v5
4510-
with:
4511-
python-version: "3.8"
4512-
4513-
- name: Install tox
4514-
run: pip install tox-uv
4515-
4516-
- name: Run tests
4517-
run: tox -e py38-test-instrumentation-requests -- -ra

0 commit comments

Comments
 (0)