Skip to content

feat(core): add request hook to enrich spans with GCP resource attributes (E) - #18272

Draft
chalmerlowe wants to merge 1 commit into
feat/otel-tracing-t3-method-spansfrom
feat/otel-tracing-t4-resource-attributes
Draft

feat(core): add request hook to enrich spans with GCP resource attributes (E)#18272
chalmerlowe wants to merge 1 commit into
feat/otel-tracing-t3-method-spansfrom
feat/otel-tracing-t4-resource-attributes

Conversation

@chalmerlowe

Copy link
Copy Markdown
Contributor

Summary

This PR implements Option A for OpenTelemetry tracing in google-api-core:

  • Adds an OpenTelemetry client request_hook to otel_grpc.client_interceptor and otel_grpc.aio_client_interceptors.
  • Dynamically extracts semantic Google Cloud resource attributes from gRPC request objects:
    • gcp.resource.name
    • gcp.resource.parent
    • gcp.project_id (parsed from standard AIP-122 resource names and parents)
  • Injects these attributes directly into the active wire-level span.
  • Adds comprehensive unit tests validating extraction from requests and attachment to spans.

Why

Enriches raw gRPC transport spans with high-level Google Cloud resource context without requiring modifications to generated client methods or waiting for higher-level method decorators.

Verification

  • run_nox_docker.sh lint (Passed: ruff & flake8 clean)
  • run_nox_docker.sh mypy (Passed: 119 files checked)
  • run_nox_docker.sh unit-3.10 (Passed: 18 passed)
  • Live verification against projects/callovian with Secret Manager confirmed gcp.project_id and gcp.resource.parent are captured on emitted spans.

@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 introduces OpenTelemetry request hooks to extract and inject Google Cloud semantic and resource attributes (such as resource name, parent, and project ID) from gRPC request objects into OpenTelemetry spans. Specifically, it adds _extract_t4_attributes and _client_request_hook helper functions in _observability.py, registers the hook in the gRPC client interceptors, and includes comprehensive unit tests to verify this behavior. There are no review comments, so I have no feedback to provide.

@chalmerlowe
chalmerlowe force-pushed the feat/otel-tracing-t4-resource-attributes branch from a7be0e4 to 9efe757 Compare September 3, 2026 14:49
@chalmerlowe
chalmerlowe changed the base branch from feat/otel-tracing-transport-logic to feat/otel-tracing-t3-method-spans September 3, 2026 14:50
@chalmerlowe chalmerlowe added this to the [o11y] Tracing milestone Sep 3, 2026
@chalmerlowe chalmerlowe changed the title feat(core): add request hook to inject GCP resource and project attributes into OpenTelemetry spans feat(core): add OpenTelemetry T4 span wrapping (E) Sep 3, 2026
@chalmerlowe chalmerlowe self-assigned this Sep 3, 2026
@chalmerlowe chalmerlowe changed the title feat(core): add OpenTelemetry T4 span wrapping (E) feat(core): add request hook to enrich spans with GCP resource attributes (E) Sep 3, 2026
@chalmerlowe
chalmerlowe force-pushed the feat/otel-tracing-t4-resource-attributes branch from 9efe757 to 40071ff Compare September 3, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant