Commit 3cc63b2
authored
feat(sidekick): Add conditional instrumentation to gRPC clients (#2594)
This PR introduces feature-gated instrumentation support for gRPC
clients generated by Librarian, specifically targeting gRPC-only clients
using the `grpc-client` template set.
For googleapis/google-cloud-rust#3418
**Changes:**
1.
**`internal/sidekick/internal/rust/templates/grpc-client/transport.rs.mustache`:**
* Added a `lazy_static` definition for `INSTRUMENTATION_CLIENT_INFO`
within the existing `info` module. This static is conditionally compiled
based on the `google_cloud_unstable_tracing` cfg flag and the
`Codec.DetailedTracingAttributes` Sidekick option.
* Modified the `StorageControl::new` function to call
`.with_instrumentation()` on the `gaxi::grpc::Client` instance
(`inner`). This call is conditional based on
`gaxi::options::tracing_enabled(&config)` at runtime, and the entire
block is guarded by `{{#Codec.DetailedTracingAttributes}}` and
`#[cfg(google_cloud_unstable_tracing)]`.
2.
**`internal/sidekick/internal/rust/templates/common/Cargo.toml.mustache`:**
* Added `[lints] workspace = true` to ensure generated crates inherit
workspace lint configurations, including the `unexpected_cfgs` allowance
for `google_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-storage` crate's `StorageControl` client as a test
case, as it uses the `grpc-client` templates.
**Setup:**
* Librarian repo on branch `feat/t4-grpc-conditional-instr`.
* `google-cloud-rust` repo on branch `feat/t4-grpc-client-with-instr`
(which contains the `with_instrumentation` method on
`gaxi::grpc::Client`).
**Test Case 1: DetailedTracingAttributes ON**
1. **Configure:** Modify
`/usr/local/google/home/westarle/src/otel-rust/projects/t4-grpc-network-span/google-cloud-rust/src/storage/src/generated/gapic/.sidekick.toml`
to ensure `detailed-tracing-attributes = true`.
2. **Regenerate:** From the Librarian repo root:
```bash
go run ./cmd/sidekick refresh -project-root
/usr/local/google/home/westarle/src/otel-rust/projects/t4-grpc-network-span/google-cloud-rust
-output src/storage/src/generated/gapic
```
3. **Format:** In the `google-cloud-rust` repo:
```bash
cargo fmt -p google-cloud-storage
```
4. **Verify Diffs:** In the `google-cloud-rust` repo:
```bash
git diff src/storage/src/generated/gapic/transport.rs
```
Confirmed that the `INSTRUMENTATION_CLIENT_INFO` static and the call to
`inner.with_instrumentation(Some(&info::INSTRUMENTATION_CLIENT_INFO))`
were present and correctly guarded.
5. **Test with RUSTFLAGS:** In the `google-cloud-rust` repo:
```bash
RUSTFLAGS="--cfg google_cloud_unstable_tracing" cargo test -p
google-cloud-storage
RUSTFLAGS="--cfg google_cloud_unstable_tracing" cargo clippy -p
google-cloud-storage -- -D warnings
cargo semver-checks check-release -p google-cloud-storage
```
All checks passed.
6. **Test without RUSTFLAGS:** In the `google-cloud-rust` repo:
```bash
cargo test -p google-cloud-storage
cargo clippy -p google-cloud-storage -- -D warnings
cargo semver-checks check-release -p google-cloud-storage
```
All checks passed.
**Test Case 2: DetailedTracingAttributes OFF**
1. **Configure:** Modify
`/usr/local/google/home/westarle/src/otel-rust/projects/t4-grpc-network-span/google-cloud-rust/src/storage/src/generated/gapic/.sidekick.toml`
to set `detailed-tracing-attributes = false`.
2. **Regenerate:** Repeat step 3 from Test Case 1.
3. **Format:** Repeat step 4 from Test Case 1.
4. **Verify Diffs:** In the `google-cloud-rust` repo:
```bash
git diff src/storage/src/generated/gapic/transport.rs
```
Confirmed that the guarded blocks are now absent in
`src/storage/src/generated/gapic/transport.rs`.
5. **Test without RUSTFLAGS:** Repeat step 7 from Test Case 1.
```bash
cargo test -p google-cloud-storage
cargo clippy -p google-cloud-storage -- -D warnings
cargo semver-checks check-release -p google-cloud-storage
```
All checks passed.
**Cleanup:**
* Restored
`google-cloud-rust/src/storage/src/generated/gapic/.sidekick.toml` to
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.1 parent 7e6740f commit 3cc63b2
File tree
1 file changed
+26
-0
lines changed- internal/sidekick/internal/rust/templates/grpc-client
1 file changed
+26
-0
lines changedLines changed: 26 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
53 | 66 | | |
54 | 67 | | |
55 | 68 | | |
| |||
79 | 92 | | |
80 | 93 | | |
81 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
82 | 107 | | |
| 108 | + | |
83 | 109 | | |
84 | 110 | | |
85 | 111 | | |
| |||
0 commit comments