feat(gcp-auth-extension): Support custom credentials via configuration properties#2767
feat(gcp-auth-extension): Support custom credentials via configuration properties#2767keshavdandeva wants to merge 3 commits intoopen-telemetry:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for supplying Google Cloud credentials via configuration (file path or inline JSON) for the GCP auth extension, with tests covering the new resolution behavior.
Changes:
- Add new configuration options for credentials file path and inline JSON.
- Resolve credentials from config properties before falling back to Application Default Credentials.
- Add unit tests validating credential loading and fallback behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| gcp-auth-extension/src/main/java/io/opentelemetry/contrib/gcp/auth/GcpAuthAutoConfigurationCustomizerProvider.java | Adds credential resolution from config properties (file/JSON) with ADC fallback. |
| gcp-auth-extension/src/main/java/io/opentelemetry/contrib/gcp/auth/ConfigurableOption.java | Introduces new configurable options for credentials path and JSON. |
| gcp-auth-extension/src/test/java/io/opentelemetry/contrib/gcp/auth/GcpAuthAutoConfigurationCustomizerProviderTest.java | Adds tests for credentials loading from file path/JSON and ADC fallback. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds configuration-driven credential loading to gcp-auth-extension, allowing users to supply Google Cloud credentials via file path or raw JSON while preserving ADC fallback behavior.
Changes:
- Added new configuration options for credentials path and credentials JSON.
- Implemented lazy, prioritized credential resolution (path → JSON → ADC) with caching.
- Added unit tests covering custom credential sources and fallback behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| gcp-auth-extension/src/main/java/io/opentelemetry/contrib/gcp/auth/ConfigurableOption.java | Adds new configuration enum entries for credentials path/JSON. |
| gcp-auth-extension/src/main/java/io/opentelemetry/contrib/gcp/auth/GcpAuthAutoConfigurationCustomizerProvider.java | Adds lazy credential resolution with a small cache and a defined precedence chain. |
| gcp-auth-extension/src/test/java/io/opentelemetry/contrib/gcp/auth/GcpAuthAutoConfigurationCustomizerProviderTest.java | Adds tests for credentials loading from path/JSON and ADC fallback. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@keshavdandeva are you able to sign the CLA? |
Yes, done |
feat(gcp-auth-extension): Support custom credentials via configuration properties
Description
Currently, the
gcp-auth-extensionis hardcoded to use Google Application Default Credentials (ADC) viaGoogleCredentials.getApplicationDefault(). While this works well for standard environments (like GCE or environments withGOOGLE_APPLICATION_CREDENTIALSset), it poses limitations in scenarios where credentials need to be provided explicitly at runtime. For example, a JDBC driver integrating OpenTelemetry often receives credentials explicitly from the user (e.g., a path to a specific Service Account JSON file or a raw JSON string passed in the JDBC connection properties) and cannot easily rely on ambient environment variables.This PR adds support for specifying custom credentials via configuration properties, allowing users to provide a service account JSON file path or the raw JSON content directly, while maintaining backward compatibility by falling back to ADC.
Proposed Changes
gcp-auth-extensionConfigurableOption.java
GOOGLE_CLOUD_CREDENTIALS_PATH(System property:google.cloud.credentials.path, Env var:GOOGLE_CLOUD_CREDENTIALS_PATH)GOOGLE_CLOUD_CREDENTIALS_JSON(System property:google.cloud.credentials.json, Env var:GOOGLE_CLOUD_CREDENTIALS_JSON)GcpAuthAutoConfigurationCustomizerProvider.java
customizemethod to a lazyresolveCredentialsmethod called within the customizer lambdas. This was necessary becausecustomizeonly receivesAutoConfigurationCustomizerand does not have access toConfigPropertiesto read user-specified options.resolveCredentials:google.cloud.credentials.path.google.cloud.credentials.json.GoogleCredentials.getApplicationDefault().setHeaders(() -> ...)), ensuring that credentials loaded from custom sources still benefit from automatic token refreshing provided by thegoogle-authlibrary.GcpAuthAutoConfigurationCustomizerProviderTest.java
-Werror.Verification Results
Automated Tests
./gradlew :gcp-auth-extension:test