Repository navigation
refactor(observability): simplify AsyncGapicCallable inheritance and forward client_options in resumable stubs - #18596
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors GAPIC method wrapping and tracing in google-api-core and updates the GAPIC generator templates. Key changes include refactoring _AsyncGapicCallable to inherit from _GapicCallable to reduce code duplication, extending exception attribute extraction to support BaseException (enabling proper handling of asyncio.CancelledError), and ensuring process-level interrupts bypass span error logging. Additionally, generator templates were updated to pass client_options to REST fallback transports and conditionally preserve the kind argument depending on the runtime google-api-core version. I have no feedback to provide as there are no review comments.
| stripped for backward compatibility with older `google-api-core` | ||
| versions. | ||
| """ | ||
| if _WRAP_METHOD_SUPPORTS_TRACING: # pragma: NO COVER |
There was a problem hiding this comment.
We added tests to remove the crutch of relying on pragmas.
| compression, pagination, and long-running operations to methods. | ||
| """ | ||
|
|
||
| import asyncio |
There was a problem hiding this comment.
The majority of changes in this code are because AsyncGapicCallable inherits from GapicCallable and can thus erase duplicate code.
…preserve transport kind - Make _AsyncGapicCallable subclass _GapicCallable directly, reusing _prepare_call and _trace_span. - Restore _WRAP_METHOD_SUPPORTS_KIND check in base transport template to preserve kind attribute across Generation 2 google-api-core runtimes. - Restore tests for process-level interrupt bypass and BaseException status message extraction. - Regenerate base transport integration goldens.
…able REST stubs - Pass client_options=getattr(transport, "_client_options", None) when instantiating RestTransport and AsyncRestTransport inside gRPC resumable upload stubs. - Update test template assertion to verify client_options is forwarded. - Regenerate showcase resumable upload service goldens.
…ncient PR reference
…dens - Ensure modern and fallback wrap_method tests monkeypatch tracing support flags to isolate test execution from the installed google-api-core runtime. - Wrap transport instantiation inside mock.patch to avoid calling unmocked wrap_method during transport initialization. - Dynamicize transport kind in unit test comments. - Regenerate all integration goldens.
- Safely handle NotImplementedError when inspecting self.kind in _wrap_method and _wrap_async_method fallback paths of base.py.j2. - Clarify wrap method fallback test naming in test_%service.py.j2 and add test assertions for base transport instances. - Regenerate all integration goldens.
42daf58 to
72af789
Compare
Summary
Follow-up touch-up to PR #18433 to clean up callable inheritance, ensure client configuration options propagate through delegated resumable upload stubs, and harden backward-compatibility transport fallbacks.
Key Changes
google-api-core):_AsyncGapicCallableto inherit directly from_GapicCallable, sharing_prepare_call()and the_trace_span()context manager.gapic-generator):client_optionsto delegatedRestTransportandAsyncRestTransportstubs instantiated byResumableUploadServiceGrpcTransportandResumableUploadServiceGrpcAsyncIOTransport.gapic-generator):kindpreservation during fallback method wrapping for oldergoogle-api-coreruntimes (2.29.0 to 2.35.x).self.kindaccess withtry...except NotImplementedErrorso abstract base transport instances do not raise unhandled errors during fallback wrapping._modern_api_coreand_older_api_core_fallbacks) and added test assertions verifying base transport instances under fallback modes.Notes for Reviewers
_trace_span(), user interrupts (like Ctrl+C) pass through without being marked as RPC errors, while async cancellations (asyncio.CancelledError) are properly recorded on the span.base.py.j2, fallback logic is split into Era 1 (< 2.29.0) and Era 2 (>= 2.29.0, < 2.36.0) to safely maintain REST transport identification on older installed runtimes untilgoogle-api-core < 2.36.0support is dropped.