Skip to content

[chore] Address TODO to migrate to VCRpy and remove bespoke RequestMocker code in Google GenAI SDK instrumentation #3344

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9d5b390
Remove bespoke request mocker. Replace with direct mocking of the und…
michaelsafyan Mar 5, 2025
82ea24a
Refactor fake credentials to enable reuse.
michaelsafyan Mar 5, 2025
3f621c2
Add module to test end to end with a real client.
michaelsafyan Mar 5, 2025
4424465
Add redaction and minimal OTel mocking/testing in the e2e test.
michaelsafyan Mar 6, 2025
1425789
Fix wording of the documentation.
michaelsafyan Mar 6, 2025
7b5605b
Remove vcr migration from TODOs.
michaelsafyan Mar 6, 2025
ed424fd
Merge branch 'main' into google_genai_test_improvements
michaelsafyan Mar 6, 2025
38be0b1
Improve redaction and test naming.
michaelsafyan Mar 6, 2025
6fdb82e
Merge branch 'main' into google_genai_test_improvements
michaelsafyan Mar 7, 2025
6a366d0
Minor tweaks in the code generation. Add casette files.
michaelsafyan Mar 7, 2025
1692b9e
Reformat with ruff.
michaelsafyan Mar 7, 2025
cdbb960
Merge branch 'main' into google_genai_test_improvements
michaelsafyan Mar 10, 2025
97d64b0
Merge branch 'main' into google_genai_test_improvements
michaelsafyan Mar 12, 2025
1e1def0
Merge branch 'main' into google_genai_test_improvements
michaelsafyan Mar 13, 2025
e7eb450
Fix lint and gzip issue.
michaelsafyan Mar 14, 2025
0ddc644
Reformat with ruff.
michaelsafyan Mar 14, 2025
60e09fa
Merge branch 'main' into google_genai_test_improvements
michaelsafyan Mar 14, 2025
6e35583
Prevent fix for Python 3.9 from breaking tests in other versions.
michaelsafyan Mar 14, 2025
2793544
Record update in changelog.
michaelsafyan Mar 14, 2025
c7ed0bb
Don't double iterate when redacting by changing the value.
michaelsafyan Mar 19, 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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Restructure tests to keep in line with repository conventions ([#3344](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3344))

## Version 0.1b0 (2025-03-05)

- Add support for async and streaming.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Here are some TODO items required to achieve stability for this package:
- Additional cleanup/improvement tasks such as:
- Adoption of 'wrapt' instead of 'functools.wraps'
- Bolstering test coverage
- Migrate tests to use VCR.py

## Future

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright The OpenTelemetry 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.

import google.auth.credentials


class FakeCredentials(google.auth.credentials.AnonymousCredentials):
def refresh(self, request):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,22 @@

import google.genai

from .auth import FakeCredentials
from .instrumentation_context import InstrumentationContext
from .otel_mocker import OTelMocker
from .requests_mocker import RequestsMocker


class _FakeCredentials(google.auth.credentials.AnonymousCredentials):
def refresh(self, request):
pass


class TestCase(unittest.TestCase):
def setUp(self):
self._otel = OTelMocker()
self._otel.install()
self._requests = RequestsMocker()
self._requests.install()
self._instrumentation_context = None
self._api_key = "test-api-key"
self._project = "test-project"
self._location = "test-location"
self._client = None
self._uses_vertex = False
self._credentials = _FakeCredentials()
self._credentials = FakeCredentials()

def _lazy_init(self):
self._instrumentation_context = InstrumentationContext()
Expand All @@ -51,17 +44,22 @@ def client(self):
self._client = self._create_client()
return self._client

@property
def requests(self):
return self._requests

@property
def otel(self):
return self._otel

def set_use_vertex(self, use_vertex):
self._uses_vertex = use_vertex

def reset_client(self):
self._client = None

def reset_instrumentation(self):
if self._instrumentation_context is None:
return
self._instrumentation_context.uninstall()
self._instrumentation_context = None

def _create_client(self):
self._lazy_init()
if self._uses_vertex:
Expand All @@ -72,10 +70,9 @@ def _create_client(self):
location=self._location,
credentials=self._credentials,
)
return google.genai.Client(api_key=self._api_key)
return google.genai.Client(vertexai=False, api_key=self._api_key)

def tearDown(self):
if self._instrumentation_context is not None:
self._instrumentation_context.uninstall()
self._requests.uninstall()
self._otel.uninstall()

This file was deleted.

Loading