Skip to content

Commit 1358226

Browse files
authored
feat(sidekick): Inject InstrumentationClientInfo for tracing (#2252)
- Add static INSTRUMENTATION_CLIENT_INFO to lib.rs.mustache. - Use INSTRUMENTATION_CLIENT_INFO in transport.rs.mustache if tracing is enabled. For #2212 see also googleapis/google-cloud-rust#3347 and googleapis/google-cloud-rust#3376
1 parent 46428ca commit 1358226

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

internal/sidekick/internal/rust/templates/crate/src/lib.rs.mustache

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ pub(crate) mod info {
119119
ac.rest_header_value()
120120
};
121121
}
122+
{{#Codec.DetailedTracingAttributes}}
123+
pub(crate) static INSTRUMENTATION_CLIENT_INFO: gaxi::options::InstrumentationClientInfo = gaxi::options::InstrumentationClientInfo {
124+
service_name: "{{Name}}",
125+
client_version: VERSION,
126+
client_artifact: NAME,
127+
default_host: "{{Codec.DefaultHostShort}}",
128+
..Default::default()
129+
};
130+
{{/Codec.DetailedTracingAttributes}}
122131
}
123132

124133
{{/Codec.HasServices}}

internal/sidekick/internal/rust/templates/crate/src/transport.rs.mustache

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,20 @@ impl std::fmt::Debug for {{Codec.Name}} {
5353
{{/Codec.PerServiceFeatures}}
5454
impl {{Codec.Name}} {
5555
pub async fn new(config: gaxi::options::ClientConfig) -> gax::client_builder::Result<Self> {
56+
{{#Codec.DetailedTracingAttributes}}
57+
let tracing_is_enabled = gaxi::options::tracing_enabled(&config);
58+
let inner = gaxi::http::ReqwestClient::new(config, crate::DEFAULT_HOST).await?;
59+
let inner = if tracing_is_enabled {
60+
inner.with_instrumentation(Some(crate::info::INSTRUMENTATION_CLIENT_INFO))
61+
} else {
62+
inner
63+
};
64+
Ok(Self { inner })
65+
{{/Codec.DetailedTracingAttributes}}
66+
{{^Codec.DetailedTracingAttributes}}
5667
let inner = gaxi::http::ReqwestClient::new(config, crate::DEFAULT_HOST).await?;
5768
Ok(Self { inner })
69+
{{/Codec.DetailedTracingAttributes}}
5870
}
5971
}
6072

0 commit comments

Comments
 (0)