GeezerVison is showing github.com — feat(o11y): introduce `gcp.client.repo` and `gcp.client.artifact` attributes by diegomarquezp · Pull Request #4120 · googleapis/sdk-platform-java
This repository was archived by the owner on Oct 29, 2026. It is now read-only.
Conversation
This PR introduces the ability to include repository and artifact name metadata in generated GAPIC libraries.
Changes
GAX (Google API Extensions)
LibraryMetadata: Introduced a new internal class to hold repository and artifactName.
StubSettings & ClientContext: Added LibraryMetadata to these classes to carry the metadata through the client lifecycle.
- Observability/Tracing: Updated
ApiTracerContext and ObservabilityAttributes to support these new attributes, enabling them to be included in exported traces.
GAPIC Generator
- Support for
repo and artifact flags, passed down to generate a method in [Service]StubSettings that builds an instance of LibraryMetadata.
Hermetic Build
- Support for
repo and artifact to be passed down to generate_library.sh. The flags reuse the existing logic that determines the values.
Verification Results
Note on java-bigtable downstream check
Since SkipTrailersTest mocks the tracer factory, the EndpointContext call to apiTracerFactory.withContext() returns a null factory, causing a null pointer exception when building the client context.
We expect the test to be adjusted with this change with the next release.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
- Rename SpanHandle to GaxSpan
- Simplify adding op and attempt attributes
- Use HashMap instead of ConcurrentHashMap
- Remove error handling (for now)
…icTracer.java
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Summary of Changes
Hello @diegomarquezp, 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 introduces new gcp.client.repo and gcp.client.artifact attributes to enhance observability within client libraries. It modifies the GAPIC generator to accept and propagate these attributes, ensuring that generated client settings classes include this metadata. This change provides better insights into the client library's origin and identity during tracing, which is crucial for monitoring and debugging.
Highlights
- Observability Attributes: Introduced new
gcp.client.repo and gcp.client.artifact attributes to enhance observability within client libraries, providing more context about the client's origin and identity.
- GAPIC Generator Updates: Modified the GAPIC generator to accept and propagate these new
repo and artifact parameters, ensuring that generated client settings classes include this metadata.
- Core Library Integration: Integrated
LibraryMetadata into gax-java's ClientContext and ApiTracerContext to automatically include repository and artifact information in tracing spans.
- Build Process Enhancements: Updated the library generation build scripts and Dockerfile to support passing and processing the new
repo and artifact arguments during code generation.
Changelog
- .cloudbuild/library_generation/library_generation.Dockerfile
- Updated Maven install command with additional flags to skip enforcer and format checks.
- gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java
- Imported
LibraryMetadata for use in generated settings.
- Modified
createClassMethods to accept GapicContext for metadata access.
- Added
createGetLibraryMetadataMethod to generate the getLibraryMetadata override in settings classes.
- gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/GapicContext.java
- Added abstract methods
repo() and artifact() to GapicContext.
- Included
setRepo and setArtifact methods in the GapicContext.Builder.
- gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java
- Added parsing for
repo and artifact from the code generator request.
- Set the parsed
repo and artifact values in the GapicContext builder.
- gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/PluginArgumentParser.java
- Defined new constant keys
KEY_REPO and KEY_ARTIFACT.
- Added static methods
parseRepo and parseArtifact to extract these arguments.
- gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposerTest.java
- Added a new parameterized test to verify
ServiceStubSettings generation with repo and artifact metadata.
- gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/ApiVersionTestingStubSettings.golden
- Imported
LibraryMetadata.
- Overrode the
getLibraryMetadata method to return a default LibraryMetadata instance.
- gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/ApiVersionTestingStubSettingsMetadata.golden
- Added a new golden file reflecting the generated
ApiVersionTestingStubSettings with LibraryMetadata.
- gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/DeprecatedServiceStubSettings.golden
- Imported
LibraryMetadata.
- Overrode the
getLibraryMetadata method to return a default LibraryMetadata instance.
- gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/DeprecatedServiceStubSettingsMetadata.golden
- Added a new golden file reflecting the generated
DeprecatedServiceStubSettings with LibraryMetadata.
- gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoServiceSelectiveGapicStubSettings.golden
- Imported
LibraryMetadata.
- Overrode the
getLibraryMetadata method to return a default LibraryMetadata instance.
- gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoServiceSelectiveGapicStubSettingsMetadata.golden
- Added a new golden file reflecting the generated
EchoServiceSelectiveGapicStubSettings with LibraryMetadata.
- gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoStubSettings.golden
- Imported
LibraryMetadata.
- Overrode the
getLibraryMetadata method to include specific artifact and repository names.
- gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoStubSettingsMetadata.golden
- Added a new golden file reflecting the generated
EchoStubSettings with LibraryMetadata.
- gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/JobServiceStubSettings.golden
- Imported
LibraryMetadata.
- Overrode the
getLibraryMetadata method to return a default LibraryMetadata instance.
- gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/JobServiceStubSettingsMetadata.golden
- Added a new golden file reflecting the generated
JobServiceStubSettings with LibraryMetadata.
- gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/LoggingServiceV2StubSettings.golden
- Imported
LibraryMetadata.
- Overrode the
getLibraryMetadata method to return a default LibraryMetadata instance.
- gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/LoggingServiceV2StubSettingsMetadata.golden
- Added a new golden file reflecting the generated
LoggingServiceV2StubSettings with LibraryMetadata.
- gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/PublisherStubSettings.golden
- Imported
LibraryMetadata.
- Overrode the
getLibraryMetadata method to return a default LibraryMetadata instance.
- gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/PublisherStubSettingsMetadata.golden
- Added a new golden file reflecting the generated
PublisherStubSettings with LibraryMetadata.
- gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/EchoStubSettings.golden
- Imported
LibraryMetadata.
- Overrode the
getLibraryMetadata method to include specific artifact and repository names.
- gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/WickedStubSettings.golden
- Imported
LibraryMetadata.
- Overrode the
getLibraryMetadata method to include specific artifact and repository names.
- gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/goldens/ComplianceStubSettings.golden
- Imported
LibraryMetadata.
- Overrode the
getLibraryMetadata method to return a default LibraryMetadata instance.
- gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/goldens/HttpJsonApiVersionTestingStubSettings.golden
- Imported
LibraryMetadata.
- Overrode the
getLibraryMetadata method to return a default LibraryMetadata instance.
- gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/PluginArgumentParserTest.java
- Added new unit tests
parseRepo and parseArtifact to verify correct parsing of new plugin arguments.
- gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/GrpcRestTestProtoLoader.java
- Added constants
ECHO_SERVICE_REPOSITORY and ECHO_SERVICE_ARTIFACT.
- Updated
parseShowcaseEcho and parseShowcaseWicked to set these new attributes in the GapicContext.
- gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/TestProtoLoader.java
- Added constants
ECHO_SERVICE_REPOSITORY and ECHO_SERVICE_ARTIFACT.
- Updated
parseShowcaseEcho to set these new attributes in the GapicContext.
- gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java
- Modified the
create method to include LibraryMetadata in the ApiTracerContext.
- gax-java/gax/src/main/java/com/google/api/gax/rpc/LibraryMetadata.java
- Added a new
LibraryMetadata class with repository and artifactName fields, using AutoValue for immutability.
- gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java
- Added a protected
getLibraryMetadata method to StubSettings to provide library-specific metadata.
- gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracerContext.java
- Modified
ApiTracerContext to include LibraryMetadata.
- Updated
getAttemptAttributes to add REPO_ATTRIBUTE and ARTIFACT_ATTRIBUTE from LibraryMetadata to tracing spans.
- gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityAttributes.java
- Added new constants
REPO_ATTRIBUTE and ARTIFACT_ATTRIBUTE for observability tracing.
- gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracerFactory.java
- Updated the constructor to use
ApiTracerContext.empty() for initialization.
- gax-java/gax/src/test/java/com/google/api/gax/tracing/ApiTracerContextTest.java
- Added a new test file for
ApiTracerContext to verify the inclusion of LibraryMetadata attributes in tracing.
- gax-java/gax/src/test/java/com/google/api/gax/tracing/SpanTracerFactoryTest.java
- Updated test cases to use
ApiTracerContext.empty() for consistency.
- gax-java/gax/src/test/java/com/google/api/gax/tracing/SpanTracerTest.java
- Updated test cases to use
ApiTracerContext.empty() for consistency.
- hermetic_build/library_generation/generate_composed_library.py
- Renamed
__construct_effective_arg to _construct_effective_arg.
- Updated
_construct_effective_arg to accept generation_config and library parameters.
- Added
--repo and --artifact arguments to the effective arguments passed to the GAPIC generator.
- hermetic_build/library_generation/generate_library.sh
- Added
--repo and --artifact options for the script.
- Initialized
repo and artifact variables.
- Passed
repo and artifact to the get_gapic_opts function.
- hermetic_build/library_generation/tests/generate_library_unit_tests.py
- Imported necessary classes for testing
GapicConfig, GapicInputs, GenerationConfig, and LibraryConfig.
- Added a new unit test
test_construct_effective_arg_confirm_repo_and_artifact to verify the correct construction of arguments including repo and artifact.
- hermetic_build/library_generation/tests/generate_library_unit_tests.sh
- Updated calls to
get_gapic_opts in unit tests to include the new repo and artifact parameters.
- hermetic_build/library_generation/utils/utilities.py
- Added a new function
get_library_repository to determine the repository identifier based on library configuration.
- Refactored
generate_postprocessing_prerequisite_files to use get_library_repository.
- hermetic_build/library_generation/utils/utilities.sh
- Modified
get_gapic_opts function to accept repo and artifact as parameters and include them in the generated options string.
- java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/ComplianceStubSettings.java
- Imported
LibraryMetadata.
- Overrode the
getLibraryMetadata method to include specific artifact and repository names.
- java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/EchoStubSettings.java
- Imported
LibraryMetadata.
- Overrode the
getLibraryMetadata method to include specific artifact and repository names.
- java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/IdentityStubSettings.java
- Imported
LibraryMetadata.
- Overrode the
getLibraryMetadata method to include specific artifact and repository names.
- java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/MessagingStubSettings.java
- Imported
LibraryMetadata.
- Overrode the
getLibraryMetadata method to include specific artifact and repository names.
- java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/SequenceServiceStubSettings.java
- Imported
LibraryMetadata.
- Overrode the
getLibraryMetadata method to include specific artifact and repository names.
- java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/TestingStubSettings.java
- Imported
LibraryMetadata.
- Overrode the
getLibraryMetadata method to include specific artifact and repository names.
- java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelTracing.java
- Added constants
SHOWCASE_REPO and SHOWCASE_ARTIFACT for tracing tests.
- Updated tracing tests to assert the presence and correctness of
REPO_ATTRIBUTE and ARTIFACT_ATTRIBUTE.
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this 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 new observability attributes gcp.client.repo and gcp.client.artifact to tracing spans, which is a valuable addition for client library telemetry. The changes are well-integrated throughout the codebase, from the generator arguments and models to the GAX runtime and build scripts. The inclusion of tests at various levels, including new golden files and integration tests, ensures the correctness of this new feature. I've found one minor issue in a test file, which I've commented on.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm only passing repo and artifact to the showcase service protos. I believe it's fine to observe both when the arguments were passend and when they were not.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
|
@InternalApi
|
|
|
@AutoValue
|
|
|
public abstract class ApiTracerContext {
|
|
|
@Nullable
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these two attributes could be null?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
/** Creates a SpanTracerFactory */ |
|
public SpanTracerFactory(TraceManager traceManager) { |
|
this(traceManager, ApiTracerContext.empty()); |
|
} |
Users may provide a factory without an ApiTracerContext, so we need an empty one here with null values.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may change later with feature enablement but for now I believe it's necessary.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
|
:return: string representing the repository
|
|
|
"""
|
|
|
if config.contains_common_protos():
|
|
|
repo = SDK_PLATFORM_JAVA
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may have to change this hardcode value to google-cloud-java once sdk-platform-java is migrated to google-cloud-java.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
diegomarquezp reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Mar 23, 2026
Reviewers
2 more reviewers
blakeli0
blakeli0 approved these changes
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
size: l
Pull request size is large.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|