GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(api_core): add error logging feature gate and shared transport attempt logging helpers by chalmerlowe · Pull Request #19009 · googleapis/google-cloud-python

Conversation

@chalmerlowe

@chalmerlowe chalmerlowe commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Problem / Context

Google Cloud Python client libraries require opt-in OpenTelemetry-correlated Production Error Logging (PEL) that can be enabled via GOOGLE_SDK_EXPERIMENTAL_PYTHON_LOGGING_ENABLED and client_options.logger_provider, as well as shared helpers to resolve service-scoped loggers and format structured DEBUG log payloads for failed transport wire attempts.

Bug: b/479827845

Solution

  • Add is_error_logging_enabled(client_options) and _LOGGER_PROVIDER feature gating in google/api_core/client_logging.py.
  • Add _get_service_logger, _is_failed_attempt, _build_attempt_log_extra, log_transport_attempt, and _capture_grpc_attempt_exception in google/api_core/_observability.py.
  • Add shared mock_logger and mock_service_logger pytest fixtures in tests/conftest.py.
  • Add unit tests in tests/unit/test_client_logging.py and tests/unit/test_observability.py covering feature flag gating, service logger resolution, no-op fast paths on disabled or 2xx/OK attempts, structured DEBUG log emission, and fail-open exception resilience.

Verification

Relying on GitHub Actions CI for full matrix verification, alongside local unit test (unit-3.14) and lint verification.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gemini-code-assist[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction
gemini-code-assist[bot]
gemini-code-assist Bot reviewed Nov 6, 2026
View reviewed changes

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

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

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 introduces OpenTelemetry-correlated Production Error Logging (PEL) to google-api-core, adding utility functions and a context manager to log failed transport attempts and capture gRPC exceptions. Feedback on the changes highlights two key improvements: updating the HTTP success status threshold from < 400 to < 300 to ensure redirects are logged as failed attempts in accordance with the docstring, and catching Exception instead of BaseException in _capture_grpc_attempt_exception to prevent system-level interrupts from being logged as transport failures.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/google-api-core/google/api_core/_observability.py
return True
if norm_status is None or norm_status == "OK":
return False
return not (norm_status.isdecimal() and int(norm_status) < 400)

@gemini-code-assist gemini-code-assist Bot Nov 6, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

medium

The docstring for log_transport_attempt states that successful transport attempts are defined as "2xx HTTP or OK gRPC", and that it emits logs for "retry/redirect/failure" attempts. However, using < 400 treats HTTP 3xx redirect status codes as successful attempts, causing them to return early and not be logged. To align the implementation with the docstring and ensure redirects are logged, the threshold should be < 300.

Suggested change
return not (norm_status.isdecimal() and int(norm_status) < 400)
return not (norm_status.isdecimal() and int(norm_status) < 300)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@chalmerlowe chalmerlowe Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The < 400 threshold in _is_failed_attempt is intentional: per OpenTelemetry HTTP semantic conventions (and Google Cloud APIs that use 308 Resume Incomplete), only HTTP status codes >= 400 represent failed HTTP wire attempts. Updated the log_transport_attempt docstring to clarify < 400 HTTP or OK gRPC.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/google-api-core/google/api_core/_observability.py
"""
try:
yield
except BaseException as exc:

@gemini-code-assist gemini-code-assist Bot Nov 6, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

medium

Catching BaseException will capture system-level interrupts such as KeyboardInterrupt and SystemExit, logging them as failed transport attempts. It is safer and more precise to catch Exception instead, ensuring that only actual runtime errors are logged while system interrupts propagate cleanly without side-effects.

Suggested change
except BaseException as exc:
except Exception as exc:

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@chalmerlowe chalmerlowe Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Added an explicit except (KeyboardInterrupt, SystemExit, GeneratorExit): raise pre-guard before except BaseException as exc: (matching _GapicCallable._trace_span) so process-level interrupts propagate without emitting transport attempt logs while still capturing asyncio.CancelledError.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@chalmerlowe
chalmerlowe force-pushed the feat/otel-logging-m3-s2-logging-helpers branch from f3d197a to 866406e Compare November 6, 2026 15:45
@chalmerlowe chalmerlowe mentioned this pull request Nov 6, 2026
feat(api_core): implement L2/L3 method error logging and L4 transport attempt logging #19000
Closed
chalmerlowe added 3 commits November 9, 2026 19:14
@chalmerlowe
test(api_core): add boundary tests for _extract_http_status_code and …
d128bd2
…_resolve_rpc_system and refine docstrings
@chalmerlowe
feat(api_core): add error logging feature gate and shared transport a…
b20dc27
…ttempt logging helpers
@chalmerlowe
fix(api_core): bypass system interrupts in _capture_grpc_attempt_exce…
56c1e04
…ption and clarify docstring
@chalmerlowe
chalmerlowe force-pushed the feat/otel-logging-m3-s2-logging-helpers branch from 866406e to 56c1e04 Compare November 10, 2026 00:17

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@gemini-code-assist gemini-code-assist[bot] gemini-code-assist[bot] left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@chalmerlowe
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.