Repository navigation
feat(google-api-core): extend ErrorInfo dict accessors, centralize status code extraction, and update StructuredLogFormatter #18884
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
Open
chalmerlowe
wants to merge
1
commit into
main
Choose a base branch
from
feat/otel-logging-m1-foundation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -844,56 +844,6 @@ def test_wrap_method_otel_tracing_records_gcp_error_attributes(mock_otel): | |
| mock_otel.span.set_attribute.assert_any_call("status.message", "quota exceeded") | ||
|
|
||
|
|
||
| def test_extract_status_code_variations(): | ||
| """Proves that _extract_status_code handles grpc status, callable/non-callable codes, ints, and exceptions.""" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test stack has been improved and moved to |
||
| import types | ||
|
|
||
| from google.api_core.gapic_v1.method import _extract_status_code | ||
|
|
||
| # 1. grpc_status exists but has no name or name is None | ||
| exc1 = types.SimpleNamespace(grpc_status_code=types.SimpleNamespace(name=None)) | ||
| assert _extract_status_code(exc1) == "SimpleNamespace" | ||
|
|
||
| # 2. callable code_fn returns object with name | ||
| exc2 = types.SimpleNamespace(code=lambda: types.SimpleNamespace(name="CANCELLED")) | ||
| assert _extract_status_code(exc2) == "CANCELLED" | ||
|
|
||
| # 3. callable code_fn returns object without name | ||
| exc3 = types.SimpleNamespace(code=lambda: types.SimpleNamespace(name=None)) | ||
| assert _extract_status_code(exc3) == "SimpleNamespace" | ||
|
|
||
| # 4. callable code_fn raises Exception | ||
| def raising_code(): | ||
| raise RuntimeError("boom") | ||
|
|
||
| exc4 = types.SimpleNamespace(code=raising_code) | ||
| assert _extract_status_code(exc4) == "SimpleNamespace" | ||
|
|
||
| # 5. non-callable code_fn with name | ||
| exc5 = types.SimpleNamespace(code=types.SimpleNamespace(name="DEADLINE_EXCEEDED")) | ||
| assert _extract_status_code(exc5) == "DEADLINE_EXCEEDED" | ||
|
|
||
| # 6. non-callable code_fn that is an int in _INT_TO_GRPC_CODE (5 -> NOT_FOUND) | ||
| exc6 = types.SimpleNamespace(code=5) | ||
| assert _extract_status_code(exc6) == "NOT_FOUND" | ||
|
|
||
| # 7. non-callable code_fn that is an int not in _INT_TO_GRPC_CODE (999) | ||
| exc7 = types.SimpleNamespace(code=999) | ||
| assert _extract_status_code(exc7) == "999" | ||
|
|
||
| # 8. non-callable code_fn that is not an int and has no name | ||
| exc8 = types.SimpleNamespace(code="unknown_code") | ||
| assert _extract_status_code(exc8) == "SimpleNamespace" | ||
|
|
||
| # 9. None exception | ||
| assert _extract_status_code(None) == "" | ||
|
|
||
| # 10. __cause__ chaining fallback | ||
| inner_exc = types.SimpleNamespace(code=5) | ||
| outer_exc = types.SimpleNamespace(__cause__=inner_exc) | ||
| assert _extract_status_code(outer_exc) == "NOT_FOUND" | ||
|
|
||
|
|
||
| def test_extract_error_attributes_variations(): | ||
| """Proves that _extract_error_attributes handles __cause__, gRPC error details parsing, and direct fallbacks.""" | ||
| import types | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
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.
NOTE: To reviewer: we are moving this function out of
method.pyand intoexceptions.pybecause it is primarily focused on error code extraction.