Skip to content

feat(o11y): introduce http.request.method and span name for HTTP requests#4127

Draft
diegomarquezp wants to merge 4 commits intoobservability/tracing-attr/rpc.method-and-rpc.systemfrom
observability/tracing-attr/http-method-definition
Draft

feat(o11y): introduce http.request.method and span name for HTTP requests#4127
diegomarquezp wants to merge 4 commits intoobservability/tracing-attr/rpc.method-and-rpc.systemfrom
observability/tracing-attr/http-method-definition

Conversation

@diegomarquezp
Copy link
Contributor

  • feat(o11y): add http.request.method to span tracing
  • test: update tests

@gemini-code-assist
Copy link
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 of HTTP requests within the system by introducing detailed HTTP-specific attributes to tracing spans. It refactors the mechanism for generating span context, allowing for the inclusion of HTTP method and path template, which provides more granular and actionable insights into the performance and behavior of HTTP interactions.

Highlights

  • Enhanced HTTP Tracing: Introduced http.request.method and http.request.path_template attributes to HTTP request tracing spans for improved observability.
  • Dynamic HTTP Span Naming: Updated the naming convention for HTTP spans to dynamically include the HTTP method and path template, providing more descriptive span names.
  • Refactored Span Context: Migrated from SpanName to ApiTracerContext for generating span context, allowing for richer metadata and more flexible attribute management.
Changelog
  • gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallableFactory.java
    • Imported LibraryMetadata and ApiTracerContext.
    • Removed SpanName import.
    • Replaced getSpanName with getApiTracerContext which now builds a comprehensive ApiTracerContext including HTTP method, path template, and transport type.
  • gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallableFactoryTest.java
    • Updated imports to include Mockito and ApiTracerContext.
    • Refactored testGetSpanName to testGetApiTracerContext to test the new ApiTracerContext fields.
    • Added a new test testGetApiTracerContext_populatesHttpFields to specifically verify HTTP method and path template population.
  • gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracerContext.java
    • Added abstract methods httpMethod() and httpPathTemplate() to ApiTracerContext.
    • Modified getAttemptAttributes() to include http.request.method attribute if the transport is HTTP.
    • Updated the merge method in the Builder to handle the new httpMethod and httpPathTemplate fields.
    • Added setHttpMethod and setHttpPathTemplate to the Builder.
  • gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityAttributes.java
    • Added a new constant HTTP_METHOD_ATTRIBUTE for the http.request.method span attribute.
  • gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracerFactory.java
    • Modified the newTracer method to construct HTTP span names using the httpMethod and httpPathTemplate from ApiTracerContext instead of a generic client/method name.
  • gax-java/gax/src/test/java/com/google/api/gax/tracing/ApiTracerContextTest.java
    • Added testGetAttemptAttributes_httpMethod to verify the inclusion of the HTTP method attribute.
    • Added testGetAttemptAttributes_httpMethod_notHttpTransport to ensure the HTTP method attribute is only added for HTTP transport.
    • Added testMerge_httpFields to verify correct merging of HTTP-related fields in ApiTracerContext.
  • java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelTracing.java
    • Updated the expected span name in testTracing_successfulEcho_httpjson to reflect the new HTTP method and path template format.
    • Added an assertion to verify the http.request.method attribute is present and correct in the HTTPJSON attempt span.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Mar 2, 2026
Copy link
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 improvements for HTTP requests by adding the http.request.method attribute to traces and defining a more informative span name format (<HTTP_METHOD> <HTTP_PATH_TEMPLATE>). The changes are well-structured and include corresponding updates to unit and integration tests. However, I've identified a bug in SpanTracerFactory where an incorrect context is used to generate the new span name, which could lead to errors. My review includes a specific comment with a suggested fix for this issue.

Comment on lines +87 to +89
attemptSpanName =
String.format(
"%s %s", apiTracerContext.httpMethod(), apiTracerContext.httpPathTemplate());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

There's a bug here where the span name for HTTP requests is constructed using the apiTracerContext parameter directly, instead of the merged context variable. The context variable correctly holds the merged properties from both the factory-level and call-level contexts. Using apiTracerContext bypasses any factory-level context, which could lead to incorrect span names or a NullPointerException if httpMethod or httpPathTemplate are not present in the call-level context but are in the factory-level one.

Please use the context variable to ensure the merged context is used.

      attemptSpanName =
          String.format("%s %s", context.httpMethod(), context.httpPathTemplate());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant