Skip to content

impl(o11y): introduce http.response.status_code#4161

Closed
diegomarquezp wants to merge 11 commits intomainfrom
observability/tracing-attr/status-code
Closed

impl(o11y): introduce http.response.status_code#4161
diegomarquezp wants to merge 11 commits intomainfrom
observability/tracing-attr/status-code

Conversation

@diegomarquezp
Copy link
Copy Markdown
Contributor

No description provided.

@product-auto-label product-auto-label bot added the size: l Pull request size is large. label Mar 20, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the observability features by introducing detailed request status attributes for both HTTP and gRPC calls. It provides a mechanism to capture and attach specific status codes (like HTTP 200/404 or gRPC OK/NOT_FOUND) to tracing spans, offering a clearer picture of API call outcomes. This improvement will aid in more precise debugging and monitoring of service interactions by making status information readily available within the tracing data.

Highlights

  • New Observability Attributes: Introduced new constants for HTTP_RESPONSE_STATUS_ATTRIBUTE and RPC_GRPC_STATUS_ATTRIBUTE to capture request status codes.
  • Status Attribute Population Logic: Added a new utility method populateStatusAttributes in ObservabilityUtils to dynamically determine and add appropriate HTTP or gRPC status codes to a map of attributes based on the request's outcome (success, ApiException, or CancellationException) and transport type.
  • Span Attribute Addition: The TraceManager.Span interface and its OpenTelemetry implementation (OpenTelemetryTraceManager.OtelSpan) were updated to include an addAttributes method, allowing attributes to be added to a span after its creation.
  • Enhanced Span Completion: Modified the SpanTracer.endAttempt method to accept a Throwable and utilize the new populateStatusAttributes method to enrich the span with status code attributes before it is ended. This ensures that all attempt outcomes (success, cancellation, various failures) are properly recorded with their respective status codes.
  • Comprehensive Testing: Added extensive unit tests for ObservabilityUtils and SpanTracer to verify the correct population of status attributes for both gRPC and HTTP transports across successful, API exception, and cancellation scenarios.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 observability attributes for request status, which is a valuable addition for monitoring. The changes involve adding new attribute constants, extending the TraceManager to allow adding attributes to existing spans, and implementing the logic to populate these status attributes at the end of a request attempt.

The implementation correctly handles different transports (gRPC and HTTP) and various outcomes (success, cancellation, different exceptions). Tests have been added to cover the new functionality.

However, I've found a critical issue where the new long status attributes would be dropped due to a missing type handler in toOtelAttributes, which violates the rule for conforming to OpenTelemetry Semantic Conventions for data types. I've also suggested a refactoring to improve the clarity and maintainability of the new populateStatusAttributes method, aligning with the preference for explicit null checks for readability in simple cases.

@sonarqubecloud
Copy link
Copy Markdown

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed for 'java_showcase_integration_tests'

Failed conditions
34.7% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

…into observability/tracing-attr/status-code

# Conflicts:
#	gax-java/gax/src/main/java/com/google/api/gax/tracing/OpenTelemetryTraceManager.java
#	gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java
#	gax-java/gax/src/main/java/com/google/api/gax/tracing/TraceManager.java
@diegomarquezp diegomarquezp changed the title impl(o11y): introduce request status attributes impl(o11y): introduce http.response.status_code Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants