feat(bigquery): add gcp.resource.destination.id for span tracing#12134
feat(bigquery): add gcp.resource.destination.id for span tracing#12134
Conversation
Summary of ChangesHello, 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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
...ry/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java
Show resolved
Hide resolved
| .getRequestHeaders() | ||
| .set("x-goog-otel-enabled", this.options.isOpenTelemetryTracingEnabled()); | ||
|
|
||
| String destinationId = RESOURCE_PROJECT_PREFIX + dataset.getDatasetReference().getProjectId() + "/datasets/" + dataset.getDatasetReference().getDatasetId(); |
There was a problem hiding this comment.
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).
| 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(); |
There was a problem hiding this comment.
i feel like this is excessive and adds code bloat, but happy to change if others think we should
| String destinationId = | ||
| RESOURCE_PROJECT_PREFIX | ||
| + reference.getProjectId() | ||
| + "/datasets/" | ||
| + reference.getDatasetId() | ||
| + "/tables/" | ||
| + reference.getTableId(); |
There was a problem hiding this comment.
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();There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I prefer StringBuilder because it is still more performant than String concat.
| .getRequestHeaders() | ||
| .set("x-goog-otel-enabled", this.options.isOpenTelemetryTracingEnabled()); | ||
|
|
||
| String destinationId = |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I renamed all usages to gcpResourceDestinationId and constant GCP_DESTINATION_ID to GCP_RESOURCE_DESTINATION_ID
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