GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat(core): add request hook to enrich T4 network spans with GCP resource attributes (E) by chalmerlowe · Pull Request #18272 · googleapis/google-cloud-python Conversation
|
| endpoint = getattr(client_options, "api_endpoint", None) | ||
|
|
||
| if endpoint and isinstance(endpoint, str): | ||
| clean = endpoint.replace("http://", "").replace("https://", "").strip("/") |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Replaced the manual approach with urllib.parse. Great catch. Thnaks!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| attrs["gcp.grpc.resend_count"] = resend_count | ||
|
|
||
| name = getattr(request, "name", None) | ||
| if isinstance(name, str) and name: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
When would you expect this to be non-string? Are you sure we should fall back to the parent in that case?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is OBE.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| else: | ||
| parent = getattr(request, "parent", None) | ||
| if isinstance(parent, str) and parent: | ||
| attrs["gcp.resource.destination.id"] = parent |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
nit: we could reduce some duplication here:
resource_id = getattr(request, "name", None) or getattr(request, "parent", None)
if isinstance(resource_id, str) and resource_id:
attrs["gcp.resource.destination.id"] = resource_id
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is OBE. We no longer process "gcp.resource.destination.id"
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| _make_grpc_client_request_hook(endpoint_attrs) | ||
| if endpoint_attrs | ||
| else _grpc_client_request_hook | ||
| ) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
nit: can't this just be _make_grpc_client_request_hook(endpoint_attrs)? It seems like the implementation already handles empty endpoint_attrs, so I'm not sure we need to handle both cases here
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Simplified. Good catch. Appreciate it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| return False | ||
|
|
||
|
|
||
| _STATUS_CODE_NAMES = { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
In the PR description, you say " Without request- and response-level enrichment, spans cannot identify ... normalized string status codes".
Can you expand on that? Does the default instrumenter add code numbers, but not strings? It feels strange that we would have to add the cost of an extra callback layer to do that kind of transformation
Could we add this somewhere else in the stack? Or just stick with error numbers instead of names?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
the PR description was outdated and described an earlier prototype where the response hook was trying to do too much.
To answer your questions directly:
Does the default instrumenter add code numbers, but not strings?
Yes. Upstream opentelemetry-instrumentation-grpc sets rpc.grpc.status_code as an integer (0, 5, etc.) per OTel gRPC conventions. It does not set rpc.response.status_code at all.
Can we do this elsewhere / avoid callback translation overhead?
Yes, we moved error resolution out of this hook. All error status mapping ("NOT_FOUND", "RESOURCE_EXHAUSTED", etc.) and gcp.errors.* attributes are handled directly on the client method span in google.api_core.gapic_v1.method (PR feat(gapic): add OpenTelemetry T3 client method span wrapping in gapic_v1.method (D) #18274) where exceptions are caught naturally.
What _grpc_client_response_hook actually does in this PR:
The response hook here does zero error parsing, zero translation, and zero dictionary lookups. It only stamps rpc.response.status_code = "OK" on successful wire spans (checking span.status first to bail out if an error occurred).
I've updated the PR description to reflect the current, simplified implementation.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
My main comment is around the response callback. Are you sure it can do what we need? And do we really need a callback for status names?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
051b3d7 to
2460284
Compare
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| if request is None: | ||
| return attrs | ||
|
|
||
| resend_count = getattr(request, "resend_count", None) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that request will be a protobuf message, which wouldn't have this field. What do you expect it to be? Can we have any clearer typing here?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
DONE:
processing of the resend_count attribute has been removed.
it is in the deferred category so not required for the MVP.
Handling of:
attrs: dict[str, Any] = {
"rpc.system.name": "grpc",
}
is now moved to client_request_hook() within _make_grpc_client_request_hook()
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
b1d7f5d to
67c8ae7
Compare
b3931e9 to
99a4d3d
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sorry, something went wrong.
There was an error while loading. Please reload this page.
… hook - Add rpc.system.name: 'grpc' - Extract server.address and server.port from client options endpoint - Extract gcp.grpc.resend_count from request resend count - Extract gcp.resource.destination.id from request name or parent - Add _client_response_hook for status code, error.type, and status.message - Plumb response_hook into get_otel_interceptor and get_otel_async_interceptor
- Test endpoint attribute parsing across host/port variations - Test destination id and resend count extraction - Test client request and response hooks covering all status and error cases - Test interceptor creation and custom endpoint attribute propagation - Achieve 100% statement and branch coverage on _observability.py
…and hooks - Rename _extract_t4_attributes to _extract_grpc_request_attributes - Rename _make_client_request_hook to _make_grpc_client_request_hook - Rename _client_request_hook to _grpc_client_request_hook - Rename _client_response_hook to _grpc_client_response_hook - Preserve generic _extract_endpoint_attributes for shared transport usage
…ntion - Rename test_extract_t4_attributes to test_extract_grpc_request_attributes - Rename test_client_request_hook to test_grpc_client_request_hook - Rename test_client_response_hook to test_grpc_client_response_hook - Update interceptor hook references to _grpc_client_* hooks
- Add url.domain extraction from universe_domain or default to googleapis.com - Add _extract_error_attributes helper to extract gcp.errors.domain and gcp.errors.metadata.<key> - Omit server.port when port matches scheme defaults (443 for https/grpc, 80 for http) - Remove redundant _grpc_client_response_hook and _STATUS_CODE_NAMES - Deduplicate name and parent resource lookup for gcp.resource.destination.id - Add comprehensive parametrized unit tests and update interceptor test suites
…tem attribute - Strip leading slash from gRPC attempt span names via span.update_name - Set rpc.method to the fully qualified method name per PRD specification - Retain rpc.system.name: 'grpc' and remove legacy rpc.system attribute to avoid duplication - Update unit tests to verify span name normalization and attribute deduplication
- Remove gcp.resource.destination.id extraction from _extract_grpc_request_attributes - Update unit tests to reflect attribute removal per July Strategy Update
…ments without grpc
…parsing, and attribute handling
…nv version in response hook
0fb354a to
c0fadc4
Compare
There was an error while loading. Please reload this page.
🤖 I have created a release *beep* *boop* --- <details><summary>google-ads-admanager: 0.10.5</summary> ## [0.10.5](google-ads-admanager-v0.10.4...google-ads-admanager-v0.10.5) (2026-09-17) ### Features * update API sources and regenerate ([#18396](#18396)) ([e9f8e59](e9f8e59)) * update API sources and regenerate. ([e9f8e59](e9f8e59)) </details> <details><summary>google-ads-datamanager: 0.9.3</summary> ## [0.9.3](google-ads-datamanager-v0.9.2...google-ads-datamanager-v0.9.3) (2026-09-17) ### Features * update API sources and regenerate ([#18396](#18396)) ([e9f8e59](e9f8e59)) * update API sources and regenerate. ([e9f8e59](e9f8e59)) </details> <details><summary>google-analytics-data: 0.23.1</summary> ## [0.23.1](google-analytics-data-v0.23.0...google-analytics-data-v0.23.1) (2026-09-17) ### Features * update API sources and regenerate ([#18396](#18396)) ([e9f8e59](e9f8e59)) * update API sources and regenerate. ([e9f8e59](e9f8e59)) </details> <details><summary>google-api-core: 2.38.0</summary> ## [2.38.0](google-api-core-v2.37.0...google-api-core-v2.38.0) (2026-09-17) ### Features * **core:** add request hook to enrich T4 network spans with GCP resource attributes (E) ([#18272](#18272)) ([1ca95e9](1ca95e9)) </details> <details><summary>google-apps-meet: 0.5.1</summary> ## [0.5.1](google-apps-meet-v0.5.0...google-apps-meet-v0.5.1) (2026-09-17) ### Features * update API sources and regenerate ([#18396](#18396)) ([e9f8e59](e9f8e59)) * update API sources and regenerate. ([e9f8e59](e9f8e59)) </details> <details><summary>google-cloud-api-gateway: 1.17.0</summary> ## [1.17.0](google-cloud-api-gateway-v1.16.0...google-cloud-api-gateway-v1.17.0) (2026-09-17) ### Features * update API sources and regenerate ([#18396](#18396)) ([e9f8e59](e9f8e59)) * update API sources and regenerate. ([e9f8e59](e9f8e59)) </details> <details><summary>google-cloud-auditmanager: 0.3.2</summary> ## [0.3.2](google-cloud-auditmanager-v0.3.1...google-cloud-auditmanager-v0.3.2) (2026-09-17) ### Features * update API sources and regenerate ([#18396](#18396)) ([e9f8e59](e9f8e59)) * update API sources and regenerate. ([e9f8e59](e9f8e59)) </details> <details><summary>google-cloud-backupdr: 0.10.2</summary> ## [0.10.2](google-cloud-backupdr-v0.10.1...google-cloud-backupdr-v0.10.2) (2026-09-17) ### Features * **google/cloud/backupdr/v1beta:** add google-cloud-backupdr ([#18399](#18399)) ([91b7ae7](91b7ae7)) </details> <details><summary>google-cloud-bigquery: 3.45.2</summary> ## [3.45.2](google-cloud-bigquery-v3.45.1...google-cloud-bigquery-v3.45.2) (2026-09-17) ### Bug Fixes * disambiguate google-cloud-bigquery `to_dataframe` usage from `pandas-gbq` in ua. ([#18369](#18369)) ([0d7d59c](0d7d59c)) </details> <details><summary>google-cloud-bigtable: 2.46.0</summary> ## [2.46.0](google-cloud-bigtable-v2.45.0...google-cloud-bigtable-v2.46.0) (2026-09-17) ### Features * **bigtable:** Rerouted RowSet and RowRange to use ReadRows from data client ([#18196](#18196)) ([1857302](1857302)) * Rerouted ReadRows to data client ([#18198](#18198)) ([934cd2d](934cd2d)) * update API sources and regenerate ([#18396](#18396)) ([e9f8e59](e9f8e59)) * update API sources and regenerate. ([e9f8e59](e9f8e59)) ### Bug Fixes * **bigtable:** Added rst_stream exception handling for ReadRows. ([#18197](#18197)) ([f30df60](f30df60)) </details> <details><summary>google-cloud-compute: 1.54.0</summary> ## [1.54.0](google-cloud-compute-v1.53.0...google-cloud-compute-v1.54.0) (2026-09-17) ### Features * update API sources and regenerate ([#18396](#18396)) ([e9f8e59](e9f8e59)) * update API sources and regenerate. ([e9f8e59](e9f8e59)) </details> <details><summary>google-cloud-compute-v1beta: 0.12.6</summary> ## [0.12.6](google-cloud-compute-v1beta-v0.12.5...google-cloud-compute-v1beta-v0.12.6) (2026-09-17) ### Features * update API sources and regenerate ([#18396](#18396)) ([e9f8e59](e9f8e59)) * update API sources and regenerate. ([e9f8e59](e9f8e59)) </details> <details><summary>google-cloud-devicestreaming: 0.5.1</summary> ## [0.5.1](google-cloud-devicestreaming-v0.5.0...google-cloud-devicestreaming-v0.5.1) (2026-09-17) ### Features * update API sources and regenerate ([#18396](#18396)) ([e9f8e59](e9f8e59)) * update API sources and regenerate. ([e9f8e59](e9f8e59)) </details> <details><summary>google-cloud-discoveryengine: 0.20.4</summary> ## [0.20.4](google-cloud-discoveryengine-v0.20.3...google-cloud-discoveryengine-v0.20.4) (2026-09-17) ### Features * update API sources and regenerate ([#18396](#18396)) ([e9f8e59](e9f8e59)) * update API sources and regenerate. ([e9f8e59](e9f8e59)) </details> <details><summary>google-cloud-firestore: 2.31.0</summary> ## [2.31.0](google-cloud-firestore-v2.30.0...google-cloud-firestore-v2.31.0) (2026-09-17) ### Features * **firestore:** add BSONInt32 support ([#18388](#18388)) ([136d4b9](136d4b9)) * **firestore:** add BSONMinKey and BSONMaxKey support ([#18385](#18385)) ([9a1fb24](9a1fb24)) </details> <details><summary>google-cloud-kms: 3.17.0</summary> ## [3.17.0](google-cloud-kms-v3.16.0...google-cloud-kms-v3.17.0) (2026-09-17) ### Features * update API sources and regenerate ([#18396](#18396)) ([e9f8e59](e9f8e59)) * update API sources and regenerate. ([e9f8e59](e9f8e59)) </details> <details><summary>google-cloud-network-services: 0.10.3</summary> ## [0.10.3](google-cloud-network-services-v0.10.2...google-cloud-network-services-v0.10.3) (2026-09-17) ### Features * **google/cloud/networkservices/v1beta1:** add google-cloud-network-services ([#18398](#18398)) ([8df34ce](8df34ce)) ### Bug Fixes * empty commit to bump v1beta version ([#18411](#18411)) ([3b3cc6f](3b3cc6f)) </details> <details><summary>google-cloud-pubsub: 2.41.0</summary> ## [2.41.0](google-cloud-pubsub-v2.40.0...google-cloud-pubsub-v2.41.0) (2026-09-17) ### Features * update API sources and regenerate ([#18396](#18396)) ([e9f8e59](e9f8e59)) * update API sources and regenerate. ([e9f8e59](e9f8e59)) </details> <details><summary>google-cloud-securesourcemanager: 0.6.2</summary> ## [0.6.2](google-cloud-securesourcemanager-v0.6.1...google-cloud-securesourcemanager-v0.6.2) (2026-09-17) ### Features * update API sources and regenerate ([#18396](#18396)) ([e9f8e59](e9f8e59)) * update API sources and regenerate. ([e9f8e59](e9f8e59)) </details> <details><summary>google-maps-solar: 0.6.1</summary> ## [0.6.1](google-maps-solar-v0.6.0...google-maps-solar-v0.6.1) (2026-09-17) ### Features * update API sources and regenerate ([#18396](#18396)) ([e9f8e59](e9f8e59)) * update API sources and regenerate. ([e9f8e59](e9f8e59)) </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.