feat(sidekick): Add conditional instrumentation to gRPC clients#2594
Merged
westarle merged 1 commit intogoogleapis:mainfrom Oct 17, 2025
Merged
Conversation
Adds feature-gated instrumentation support for gRPC clients using google_cloud_unstable_tracing flag and DetailedTracingAttributes option. Tested with google-cloud-storage, toggling DTA and RUSTFLAGS, running tests, clippy, and semver-checks.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2594 +/- ##
==========================================
+ Coverage 85.51% 85.52% +0.01%
==========================================
Files 107 107
Lines 10798 10808 +10
==========================================
+ Hits 9234 9244 +10
Misses 1234 1234
Partials 330 330 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
coryan
approved these changes
Oct 16, 2025
ldetmer
pushed a commit
that referenced
this pull request
Oct 22, 2025
Librarian Version: v0.0.0-20251022154542-dd249212325d Language Image: us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/librarian-release-container:latest <details><summary>librarian: 0.5.0</summary> ## [0.5.0](v0.4.0...v0.5.0) (2025-10-22) ### Features * speed up finding changed files in commits (#2645) ([1060946](10609465)) * Can config dart `export` (#2641) ([97eacd2](97eacd29)) * minor whitespace and doc changes to the Dart templates (#2636) ([b3ac7b4](b3ac7b42)) * only generate libraries with changed APIs (#2618) ([82171be](82171bed)) * make extra modules public (#2622) ([2c94a53](2c94a53f)) * skip a GitHub release for a library (#2612) ([6258f4d](6258f4d1)) * allow skipping semver checks for rust-publish (#2584) ([739ce0d](739ce0d5)) * add ability to open pull request as a draft (#2604) ([c1f0285](c1f02859)) * capture discovery revision (#2605) ([14a1483](14a14830)) * Add conditional instrumentation to gRPC clients (#2594) ([3cc63b2](3cc63b22)) * add update-image CLI command (#2580) ([90e0f6e](90e0f6e5)) * Generate more samples for oneof main setters. (#2592) ([c55f3ce](c55f3ceb)) * Add documentation for generated service constructors (#2575) ([6a4aead](6a4aeade)) * disable some clippy warnings (#2567) ([9f51084](9f510842)) * Generate setter samples for oneof fields. (#2573) ([8c2416a](8c2416ab)) * add default Rust features option (#2562) ([892f42b](892f42b7)) * Include a correct URL for issues (#2570) ([10493ed](10493ed9)) * add ability to find the latest docker image SHA (#2539) ([62e80f1](62e80f19)) * add ability to checkout a repo at a certain commit (#2555) ([23b8ffe](23b8ffea)) * add onboarding PR body (#2552) ([e32719c](e32719cd)) ### Bug Fixes * associate bulk change to individual libraries (#2626) ([dd24921](dd249212)) * Allow `unnecessary_import`s (#2642) ([88c4379](88c43794)) * resolve issue where onboarded library can't be released (#2632) ([b300a4e](b300a4ea)) * resolve issue where commits cannot be fetched for new library (#2631) ([45652c0](45652c03)) * address a typo in the Message.ServicePlaceholder docs (#2616) ([82fda96](82fda96b)) * bad version bump edits (#2613) ([9902b1d](9902b1d5)) * use templates for update-image PR body (#2602) ([7309cad](7309cadd)) * populate configure command pr content (#2591) ([811eb8e](811eb8e2)) * shrink release PR size when there are bulk changes (#2585) ([bcb914a](bcb914ac)) * Fixes several issues with oneof main setter samples (#2589) ([e4958d0](e4958d00)) * resolve broken link in PR body (#2579) ([098c1d2](098c1d24)) * Remove double sample code blocks (#2582) ([6b10456](6b104567)) * change commit package (#2571) ([45ee48f](45ee48f0)) * show chores in release notes (#2544) ([88b62cc](88b62ccb)) * avoid work duplication when finding changes (#2558) ([0adeeac](0adeeac6)) * mangled method names and doc links (#2565) ([895dac9](895dac94)) ### Reverts * show chores in release notes (#2601) ([7e6740f](7e6740ff)) </details>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR introduces feature-gated instrumentation support for gRPC clients generated by Librarian, specifically targeting gRPC-only clients using the
grpc-clienttemplate set.For googleapis/google-cloud-rust#3418
Changes:
internal/sidekick/internal/rust/templates/grpc-client/transport.rs.mustache:lazy_staticdefinition forINSTRUMENTATION_CLIENT_INFOwithin the existinginfomodule. This static is conditionally compiled based on thegoogle_cloud_unstable_tracingcfg flag and theCodec.DetailedTracingAttributesSidekick option.StorageControl::newfunction to call.with_instrumentation()on thegaxi::grpc::Clientinstance (inner). This call is conditional based ongaxi::options::tracing_enabled(&config)at runtime, and the entire block is guarded by{{#Codec.DetailedTracingAttributes}}and#[cfg(google_cloud_unstable_tracing)].internal/sidekick/internal/rust/templates/common/Cargo.toml.mustache:[lints] workspace = trueto ensure generated crates inherit workspace lint configurations, including theunexpected_cfgsallowance forgoogle_cloud_unstable_tracing. This is also guarded by{{#Codec.DetailedTracingAttributes}}.Testing Steps:
Test PR: googleapis/google-cloud-rust#3546
The following steps were performed to test these template changes, using the
google-cloud-storagecrate'sStorageControlclient as a test case, as it uses thegrpc-clienttemplates.Setup:
feat/t4-grpc-conditional-instr.google-cloud-rustrepo on branchfeat/t4-grpc-client-with-instr(which contains thewith_instrumentationmethod ongaxi::grpc::Client).Test Case 1: DetailedTracingAttributes ON
Configure: Modify
/usr/local/google/home/westarle/src/otel-rust/projects/t4-grpc-network-span/google-cloud-rust/src/storage/src/generated/gapic/.sidekick.tomlto ensuredetailed-tracing-attributes = true.Regenerate: From the Librarian repo root:
Format: In the
google-cloud-rustrepo:Verify Diffs: In the
google-cloud-rustrepo:Confirmed that the
INSTRUMENTATION_CLIENT_INFOstatic and the call toinner.with_instrumentation(Some(&info::INSTRUMENTATION_CLIENT_INFO))were present and correctly guarded.Test with RUSTFLAGS: In the
google-cloud-rustrepo:All checks passed.
Test without RUSTFLAGS: In the
google-cloud-rustrepo:cargo test -p google-cloud-storage cargo clippy -p google-cloud-storage -- -D warnings cargo semver-checks check-release -p google-cloud-storageAll checks passed.
Test Case 2: DetailedTracingAttributes OFF
/usr/local/google/home/westarle/src/otel-rust/projects/t4-grpc-network-span/google-cloud-rust/src/storage/src/generated/gapic/.sidekick.tomlto setdetailed-tracing-attributes = false.google-cloud-rustrepo:src/storage/src/generated/gapic/transport.rs.cargo test -p google-cloud-storage cargo clippy -p google-cloud-storage -- -D warnings cargo semver-checks check-release -p google-cloud-storageCleanup:
google-cloud-rust/src/storage/src/generated/gapic/.sidekick.tomlto its original state.These tests confirm that the template changes correctly inject the instrumentation logic only when both the Sidekick option and the compile-time cfg flag are active, and do not affect the build when disabled.