Skip to content

fix(google-api-core): align HTTP T3 and T4 OpenTelemetry span status and attributes - #18868

Merged
chalmerlowe merged 1 commit into
mainfrom
fix/otel-http-t3-t4-attributes
Oct 29, 2026
Merged

chalmerlowe merged 1 commit into
mainfrom
fix/otel-http-t3-t4-attributes

Conversation

@chalmerlowe

@chalmerlowe chalmerlowe commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Aligns HTTP Tier 3 (GAPIC client) and Tier 4 (wire attempt) OpenTelemetry span statuses and semantic attributes in google-api-core with the OpenTelemetry HTTP semantic conventions and the Cloud SDK Observability specification.

HTTP Tier 4 (Wire Attempt) Spans (_observability.py)

  • Set rpc.system.name = "http": Previously omitted on Tier 4 HTTP spans; _TraceContext._build_http_span_attributes now sets "rpc.system.name": "http" so HTTP attempt spans consistently identify the transport system alongside Tier 3 spans.
  • Keep 2xx Span Status UNSET: Previously, _TraceContext.record_response explicitly set StatusCode.OK on < 400 responses. It now leaves < 400 client spans UNSET per OpenTelemetry semantic conventions (matching gRPC Tier 4 and Tier 3 spans).
  • Populate error.type and status.message on 4xx/5xx Responses: Previously, Tier 4 HTTP error attributes were only recorded in record_error when an exception escaped _TraceContext.__exit__, leaving retried >= 400 responses without error.type or status.message. _TraceContext.record_response now sets error.type to the HTTP status code string (e.g., "400", "503") and extracts status.message from the error response payload on >= 400 responses.

HTTP Tier 3 (GAPIC Client) Spans (_observability.py, gapic_v1/method.py)

  • Propagate url.template and http.response.status_code to Parent Tier 3 Spans: Previously, Tier 3 HTTP spans had no visibility into wire-level URL templates or HTTP status codes. _TraceContext.__enter__ and record_response now propagate url.template (from the first HTTP attempt) and http.response.status_code (from the latest HTTP response) to the recording parent Tier 3 span.
  • Extract HTTP Status Codes, Dict ErrorInfo, and Clean Error Messages on Failed Tier 3 Spans: Previously, _extract_error_attributes in gapic_v1/method.py only inspected attribute-based ErrorInfo objects and fell back to canonical gRPC status names (e.g., "UNAVAILABLE") for error.type and target_exc.message (which in from_http_response prepends "POST http://...: ") for status.message. When an exception wraps an HTTP response or carries a dict error_info (from JSON format_http_response_error), _extract_error_attributes now:
    • Extracts domain, reason, and metadata from dict error_info payloads as well as protobuf ErrorInfo objects.
    • Records the HTTP status code string (e.g., "400", "503") as error.type when no ErrorInfo.reason is present.
    • Extracts the clean error message from the HTTP response body for status.message before falling back to target_exc.message.

Compliance Verification (gapic-generator)

  • Updated test_span_compliance.py and telemetry_requirements_matrix.csv to enforce exact status.message equality (replacing substring matching) and validate cross-tier attribute inheritance between Tier 4 and Tier 3 HTTP spans (_assert_t3_t4_inheritance).

@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 enhances HTTP telemetry tracking by adding rpc.system.name to HTTP spans, extracting detailed error messages from HTTP responses, and propagating status codes and URL templates to parent spans. Unit tests and system requirements matrices have been updated accordingly. The review feedback suggests wrapping the extraction of response attributes (text and reason) and the access of parent span attributes in try-except blocks with warning logging to prevent potential runtime exceptions from crashing the main application flow.

Comment thread packages/google-api-core/google/api_core/_observability.py Outdated
Comment thread packages/google-api-core/google/api_core/_observability.py Outdated
@chalmerlowe
chalmerlowe force-pushed the fix/otel-http-t3-t4-attributes branch from f636b0e to a8fbedc Compare October 27, 2026 20:37
@chalmerlowe
chalmerlowe force-pushed the test/showcase-client-timeout-compliance branch 2 times, most recently from 1e109a0 to 08d3f68 Compare October 27, 2026 23:03
@chalmerlowe
chalmerlowe force-pushed the fix/otel-http-t3-t4-attributes branch 2 times, most recently from fd9c5ba to 6855304 Compare October 28, 2026 09:27
@chalmerlowe
chalmerlowe force-pushed the test/showcase-client-timeout-compliance branch 2 times, most recently from 2f1ae8f to 7d82d40 Compare October 28, 2026 09:39
@chalmerlowe
chalmerlowe force-pushed the fix/otel-http-t3-t4-attributes branch from 6855304 to 64d36b7 Compare October 28, 2026 09:39
@chalmerlowe
chalmerlowe force-pushed the test/showcase-client-timeout-compliance branch from 7d82d40 to a0e4ee6 Compare October 28, 2026 21:03
@chalmerlowe
chalmerlowe force-pushed the fix/otel-http-t3-t4-attributes branch from 64d36b7 to 3cac2f0 Compare October 28, 2026 21:03
@chalmerlowe
chalmerlowe force-pushed the fix/otel-http-t3-t4-attributes branch from 3cac2f0 to 7ecc47d Compare October 29, 2026 10:13
@chalmerlowe
chalmerlowe force-pushed the test/showcase-client-timeout-compliance branch from a0e4ee6 to 0f9316b Compare October 29, 2026 10:13
@chalmerlowe
chalmerlowe force-pushed the fix/otel-http-t3-t4-attributes branch from 7ecc47d to e5c1686 Compare October 29, 2026 11:29
@chalmerlowe
chalmerlowe force-pushed the test/showcase-client-timeout-compliance branch from 0f9316b to f5cc3c3 Compare October 29, 2026 11:29
@chalmerlowe
chalmerlowe force-pushed the fix/otel-http-t3-t4-attributes branch from e5c1686 to a0113ae Compare October 29, 2026 13:37
Base automatically changed from test/showcase-client-timeout-compliance to main October 29, 2026 13:55
@chalmerlowe
chalmerlowe force-pushed the fix/otel-http-t3-t4-attributes branch from a0113ae to 7edc460 Compare October 29, 2026 14:01
@chalmerlowe
chalmerlowe force-pushed the fix/otel-http-t3-t4-attributes branch from 7edc460 to dde7880 Compare October 29, 2026 14:19
@chalmerlowe
chalmerlowe marked this pull request as ready for review October 29, 2026 14:49
@chalmerlowe
chalmerlowe requested a review from a team as a code owner October 29, 2026 14:49
@chalmerlowe
chalmerlowe merged commit deb2194 into main Oct 29, 2026
190 checks passed
@chalmerlowe
chalmerlowe deleted the fix/otel-http-t3-t4-attributes branch October 29, 2026 14:49
@release-please release-please Bot mentioned this pull request Oct 29, 2026
sofisl pushed a commit that referenced this pull request Oct 29, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>gapic-generator: 1.44.1</summary>

##
[1.44.1](gapic-generator-v1.44.0...gapic-generator-v1.44.1)
(2026-10-29)


### Bug Fixes

* **google-api-core:** align HTTP T3 and T4 OpenTelemetry span status
and attributes
([#18868](#18868))
([deb2194](deb2194))
* **google-api-core:** align OpenTelemetry span names, kinds, and T3
endpoint attributes with spec
([#18866](#18866))
([2a10196](2a10196))
</details>

<details><summary>google-api-core: 2.43.2</summary>

##
[2.43.2](google-api-core-v2.43.1...google-api-core-v2.43.2)
(2026-10-29)


### Bug Fixes

* **google-api-core:** align HTTP T3 and T4 OpenTelemetry span status
and attributes
([#18868](#18868))
([deb2194](deb2194))
* **google-api-core:** align OpenTelemetry span names, kinds, and T3
endpoint attributes with spec
([#18866](#18866))
([2a10196](2a10196))
</details>

<details><summary>google-apps-chat: 0.10.8</summary>

##
[0.10.8](google-apps-chat-v0.10.7...google-apps-chat-v0.10.8)
(2026-10-29)


### Features

* update API sources and regenerate
([#18889](#18889))
([8705243](8705243))
</details>

<details><summary>google-cloud-documentai: 3.17.0</summary>

##
[3.17.0](google-cloud-documentai-v3.16.0...google-cloud-documentai-v3.17.0)
(2026-10-29)


### Features

* update API sources and regenerate
([#18889](#18889))
([8705243](8705243))
</details>

<details><summary>google-cloud-geminidataanalytics: 0.13.6</summary>

##
[0.13.6](google-cloud-geminidataanalytics-v0.13.5...google-cloud-geminidataanalytics-v0.13.6)
(2026-10-29)


### Features

* update API sources and regenerate
([#18889](#18889))
([8705243](8705243))
</details>

<details><summary>google-cloud-memorystore: 0.5.7</summary>

##
[0.5.7](google-cloud-memorystore-v0.5.6...google-cloud-memorystore-v0.5.7)
(2026-10-29)


### Features

* update API sources and regenerate
([#18889](#18889))
([8705243](8705243))
</details>

<details><summary>google-cloud-modelarmor: 0.7.4</summary>

##
[0.7.4](google-cloud-modelarmor-v0.7.3...google-cloud-modelarmor-v0.7.4)
(2026-10-29)


### Features

* update API sources and regenerate
([#18889](#18889))
([8705243](8705243))
</details>

<details><summary>google-cloud-oracledatabase: 0.6.4</summary>

##
[0.6.4](google-cloud-oracledatabase-v0.6.3...google-cloud-oracledatabase-v0.6.4)
(2026-10-29)


### Features

* update API sources and regenerate
([#18889](#18889))
([8705243](8705243))
</details>

<details><summary>google-cloud-redis-cluster: 0.5.7</summary>

##
[0.5.7](google-cloud-redis-cluster-v0.5.6...google-cloud-redis-cluster-v0.5.7)
(2026-10-29)


### Features

* update API sources and regenerate
([#18889](#18889))
([8705243](8705243))
</details>

<details><summary>google-cloud-sql: 0.1.3</summary>

##
[0.1.3](google-cloud-sql-v0.1.2...google-cloud-sql-v0.1.3)
(2026-10-29)


### Features

* update API sources and regenerate
([#18889](#18889))
([8705243](8705243))
</details>

<details><summary>google-cloud-video-transcoder: 1.23.0</summary>

##
[1.23.0](google-cloud-video-transcoder-v1.22.0...google-cloud-video-transcoder-v1.23.0)
(2026-10-29)


### Features

* update API sources and regenerate
([#18889](#18889))
([8705243](8705243))
</details>

<details><summary>google-shopping-merchant-quota: 1.7.0</summary>

##
[1.7.0](google-shopping-merchant-quota-v1.6.0...google-shopping-merchant-quota-v1.7.0)
(2026-10-29)


### Features

* update API sources and regenerate
([#18889](#18889))
([8705243](8705243))
</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>
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.

2 participants