Skip to content

feat(bigquery): add gcp.resource.destination.id for span tracing#12134

Open
ldetmer wants to merge 11 commits intomainfrom
add-destination-trace
Open

feat(bigquery): add gcp.resource.destination.id for span tracing#12134
ldetmer wants to merge 11 commits intomainfrom
add-destination-trace

Conversation

@ldetmer
Copy link
Contributor

@ldetmer ldetmer commented Mar 23, 2026

Adds gcp.resource.destination.id attribute to span tracing. As discussed in this design we are hard coding the value at each API call to ensure the value is correct (vs trying to automatically build it from request).

Example trace

@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 enhances BigQuery's OpenTelemetry tracing capabilities by adding a gcp.resource.destination.id attribute to RPC spans. This change provides more specific context about the target resource for each API operation, which is crucial for detailed observability and debugging. The implementation ensures that this identifier is accurately generated and attached to spans for various BigQuery services, aligning with the specified design principles.

Highlights

  • Telemetry Tracing Enhancement: Introduced the gcp.resource.destination.id attribute to OpenTelemetry spans for BigQuery RPC calls, providing more granular tracing information.
  • Resource ID Generation: Implemented logic to construct and hardcode the gcp.resource.destination.id value at each API call, ensuring accuracy as per the design document.
  • API Coverage: Applied the new tracing attribute across a wide range of BigQuery RPC methods, including operations on datasets, tables, models, routines, jobs, and IAM policies.
  • Code Refactoring: Refactored the createRpcTracingSpan method to accept an optional destinationId parameter and renamed the corresponding attribute key in BigQueryTelemetryTracer.
  • Test Coverage: Updated existing unit tests to verify the correct population and presence of the gcp.resource.destination.id attribute in generated spans.
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
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 enhances OpenTelemetry tracing for BigQuery RPC calls by introducing a destinationId attribute to the generated spans. A new RESOURCE_PROJECT_PREFIX constant is added and used to construct the destination IDs for various BigQuery operations (datasets, tables, models, routines, jobs, IAM policies). The createRpcTracingSpan method is updated to accept this new destinationId parameter, and corresponding test cases are adjusted to verify its presence in the spans. Feedback suggests improving code readability and consistency by making the RESOURCE_PROJECT_PREFIX constant package-private, extracting DatasetReference into local variables, and using StringBuilder for multi-line string concatenations.

.getRequestHeaders()
.set("x-goog-otel-enabled", this.options.isOpenTelemetryTracingEnabled());

String destinationId = RESOURCE_PROJECT_PREFIX + dataset.getDatasetReference().getProjectId() + "/datasets/" + dataset.getDatasetReference().getDatasetId();
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For improved readability and to avoid multiple calls to getDatasetReference(), consider extracting the DatasetReference into a local variable. This pattern can be applied to other similar places in this file (e.g., patchSkipExceptionTranslation).

Suggested change
String destinationId = RESOURCE_PROJECT_PREFIX + dataset.getDatasetReference().getProjectId() + "/datasets/" + dataset.getDatasetReference().getDatasetId();
com.google.api.services.bigquery.model.DatasetReference datasetReference = dataset.getDatasetReference();
String destinationId = RESOURCE_PROJECT_PREFIX + datasetReference.getProjectId() + "/datasets/" + datasetReference.getDatasetId();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i feel like this is excessive and adds code bloat, but happy to change if others think we should

Comment on lines +324 to +330
String destinationId =
RESOURCE_PROJECT_PREFIX
+ reference.getProjectId()
+ "/datasets/"
+ reference.getDatasetId()
+ "/tables/"
+ reference.getTableId();
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This multi-line string concatenation using + is hard to read. Using a StringBuilder would make the intent clearer and is generally preferred for building strings from multiple parts, especially across multiple lines. This approach could be used for other long destinationId constructions in this file.

    String destinationId =
        new StringBuilder()
            .append(RESOURCE_PROJECT_PREFIX)
            .append(reference.getProjectId())
            .append("/datasets/")
            .append(reference.getDatasetId())
            .append("/tables/")
            .append(reference.getTableId())
            .toString();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

made this change as it's a preferred style, but I also thinks this adds code bloat, so happy to revert if others feel similar.

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer StringBuilder because it is still more performant than String concat.

@ldetmer ldetmer marked this pull request as ready for review March 23, 2026 18:58
@ldetmer ldetmer requested review from a team as code owners March 23, 2026 18:58
@ldetmer ldetmer requested review from jinseopkim0 and lqiu96 March 23, 2026 20:20
.getRequestHeaders()
.set("x-goog-otel-enabled", this.options.isOpenTelemetryTracingEnabled());

String destinationId =
Copy link
Member

Choose a reason for hiding this comment

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

FYI for the other reviewers: BigQuery has a concept of Destination Table (https://docs.cloud.google.com/bigquery/docs/samples/bigquery-query-natality-tutorial)

I think the name makes sense given the context and how it's used. If other may find it confusing, then maybe a more explicit variable name like gcpResourceDestinationId can be used or something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed all usages to gcpResourceDestinationId and constant GCP_DESTINATION_ID to GCP_RESOURCE_DESTINATION_ID

@ldetmer ldetmer enabled auto-merge (squash) March 23, 2026 22:36
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.

3 participants