fix(telemetry): resolve GCP project ID from gcloud for trace exporter#23942
fix(telemetry): resolve GCP project ID from gcloud for trace exporter#23942Gitanaskhan26 wants to merge 6 commits intogoogle-gemini:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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 addresses a critical issue in GCP telemetry exporting where trace data was being sent to an incorrect project when using CLI authentication. By introducing a robust project ID resolution mechanism that leverages environment variables and the 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 introduces the resolveGcpProjectId function to the telemetry SDK to ensure consistent GCP project ID resolution. The function prioritizes environment variables (OTLP_GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_PROJECT) and falls back to querying the gcloud CLI configuration if they are unset. Corresponding updates were made to initializeTelemetry to use this logic, and new unit tests were added to cover various resolution scenarios. I have no feedback to provide.
8fab13c to
e50cbac
Compare
When useCliAuth is enabled, the TraceExporter's internal GoogleAuth resolves the project ID incorrectly for authorized_user credentials, causing traces to target the wrong GCP project while logs and metrics work correctly. Add resolveGcpProjectId() that falls back to 'gcloud config get-value project' when OTLP_GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_PROJECT env vars are not set, ensuring all three exporters receive the correct project ID explicitly. Fixes google-gemini#21969
e9d46fd to
e7956cc
Compare
Summary
Fixes trace exporting failure when
useCliAuthis enabled. TheTraceExporter's internalGoogleAuthincorrectly resolves the GCP project ID forauthorized_usercredentials, causing traces to target the wrong project (e.g., the OAuth client's project681255809395) while logs and metrics export correctly.Details
When
useCliAuthis enabled and no explicitGOOGLE_CLOUD_PROJECT/OTLP_GOOGLE_CLOUD_PROJECTenv var is set, the GCP project ID passed to all three exporters isundefined. Each exporter then resolves the project internally:@google-cloud/logging): Usesgoogle-gaxwhich adds extra fallback logic for project resolution.googleapis): Uses REST clients with broader auth handling.@google-cloud/opentelemetry-cloud-trace-exporter): Creates a rawGoogleAuthwithauthorized_usercredentials. SinceUserRefreshClienthas noprojectId,GoogleAuth.getProjectId()falls through togcloud config config-helperor the metadata server and may resolve to the wrong project.This PR adds a
resolveGcpProjectId()helper insdk.tsthat resolves the project ID with a fallback togcloud config get-value project, ensuring all three exporters always receive the correct project ID explicitly.Related Issues
Fixes #21969
How to Validate
useCliAuth: trueandtarget: gcpin settings.gcloud config get-value projectreturns your GCP project ID.GOOGLE_CLOUD_PROJECTorOTLP_GOOGLE_CLOUD_PROJECTenv vars.OTLP_GOOGLE_CLOUD_PROJECTstill takes priority over the gcloud fallback.Pre-Merge Checklist