Skip to content

refactor(observability): simplify AsyncGapicCallable inheritance and forward client_options in resumable stubs - #18596

Merged
chalmerlowe merged 6 commits into
mainfrom
feat/otel-tracing-callable-inheritance-and-touchups
Oct 8, 2026
Merged

chalmerlowe merged 6 commits into
mainfrom
feat/otel-tracing-callable-inheritance-and-touchups

Conversation

@chalmerlowe

@chalmerlowe chalmerlowe commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Callable Inheritance (google-api-core):
    • Refactored _AsyncGapicCallable to inherit directly from _GapicCallable, sharing _prepare_call() and the _trace_span() context manager.
    • Eliminated duplicate metadata handling, call preparation, and tracer initialization between sync and async callables.
  • Client Options Propagation (gapic-generator):
    • Forwarded client_options to delegated RestTransport and AsyncRestTransport stubs instantiated by ResumableUploadServiceGrpcTransport and ResumableUploadServiceGrpcAsyncIOTransport.
  • Defensive Transport Kind Fallback (gapic-generator):
    • Restored transport kind preservation during fallback method wrapping for older google-api-core runtimes (2.29.0 to 2.35.x).
    • Guarded self.kind access with try...except NotImplementedError so abstract base transport instances do not raise unhandled errors during fallback wrapping.
  • Goldens & Unit Tests:
    • Clarified wrap-method test function names (_modern_api_core and _older_api_core_fallbacks) and added test assertions verifying base transport instances under fallback modes.
    • Regenerated all integration goldens.

Notes for Reviewers

  • In _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.
  • In 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 until google-api-core < 2.36.0 support is dropped.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We added tests to remove the crutch of relying on pragmas.

compression, pagination, and long-running operations to methods.
"""

import asyncio

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The majority of changes in this code are because AsyncGapicCallable inherits from GapicCallable and can thus erase duplicate code.

@chalmerlowe
chalmerlowe marked this pull request as ready for review October 8, 2026 13:45
@chalmerlowe
chalmerlowe requested a review from a team as a code owner October 8, 2026 13:45
…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.
…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.
@chalmerlowe
chalmerlowe force-pushed the feat/otel-tracing-callable-inheritance-and-touchups branch from 42daf58 to 72af789 Compare October 8, 2026 16:03
@chalmerlowe chalmerlowe added the automerge Merge the pull request once unit tests and other checks pass. label Oct 8, 2026
@chalmerlowe
chalmerlowe merged commit 4a0bac3 into main Oct 8, 2026
187 checks passed
@chalmerlowe
chalmerlowe deleted the feat/otel-tracing-callable-inheritance-and-touchups branch October 8, 2026 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge Merge the pull request once unit tests and other checks pass.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants