|
12 | 12 | // See the License for the specific language governing permissions and |
13 | 13 | // limitations under the License. |
14 | 14 |
|
15 | | -use crate::observability::attributes::RPC_SYSTEM_HTTP; |
| 15 | +use crate::observability::attributes::{GCP_CLIENT_REPO_GOOGLEAPIS, RPC_SYSTEM_HTTP}; |
16 | 16 | use crate::options::InstrumentationClientInfo; |
17 | 17 | #[cfg(feature = "_internal-http-client")] |
18 | 18 | use google_cloud_gax::error::Error; |
@@ -259,6 +259,34 @@ impl ClientSnapshot { |
259 | 259 | self.info.default_host |
260 | 260 | } |
261 | 261 |
|
| 262 | + /// Returns the service name (e.g. `storage`). |
| 263 | + /// |
| 264 | + /// Use with the "gcp.client.service" attribute. |
| 265 | + pub fn service_name(&self) -> &'static str { |
| 266 | + self.info.service_name |
| 267 | + } |
| 268 | + |
| 269 | + /// Returns the service version (e.g. `1.2.3`). |
| 270 | + /// |
| 271 | + /// Use with the "gcp.client.version" attribute. |
| 272 | + pub fn client_version(&self) -> &'static str { |
| 273 | + self.info.client_version |
| 274 | + } |
| 275 | + |
| 276 | + /// Returns the GitHub repository. |
| 277 | + /// |
| 278 | + /// Use with the "gcp.client.repo" attribute. |
| 279 | + pub fn client_repo(&self) -> &'static str { |
| 280 | + GCP_CLIENT_REPO_GOOGLEAPIS |
| 281 | + } |
| 282 | + |
| 283 | + /// Returns the Rust crate. |
| 284 | + /// |
| 285 | + /// Use as instrumentation name, and with the "gcp.client.artifact" attribute. |
| 286 | + pub fn client_artifact(&self) -> &'static str { |
| 287 | + self.info.client_artifact |
| 288 | + } |
| 289 | + |
262 | 290 | /// Returns the RPC system (HTTP or gRPC) used in the last low-level request. |
263 | 291 | /// |
264 | 292 | /// Use with the "rpc.system.name" attribute. |
@@ -313,6 +341,30 @@ impl ClientSnapshot { |
313 | 341 | .and_then(|s| s.http_status_code) |
314 | 342 | } |
315 | 343 |
|
| 344 | + /// Returns the HTTP method (e.g. POST) used in the last request. |
| 345 | + /// |
| 346 | + /// Note that this may not be populated for gRPC requests. |
| 347 | + /// |
| 348 | + /// Use with the "http.request.method" attribute. |
| 349 | + pub fn http_method(&self) -> Option<&str> { |
| 350 | + self.transport_snapshot |
| 351 | + .as_ref() |
| 352 | + .and_then(|s| s.http_method.as_ref().map(|m| m.as_str())) |
| 353 | + } |
| 354 | + |
| 355 | + /// Returns the "resend count" of the last request, if it was a retry. |
| 356 | + /// |
| 357 | + /// The resend count of the initial attempt is `None`, and starts at 1 for each retry attempt |
| 358 | + /// made. |
| 359 | + /// |
| 360 | + /// Use with the "http.request.resend_count" attribute. |
| 361 | + pub fn http_resend_count(&self) -> Option<u32> { |
| 362 | + if self.attempt_count <= 1 { |
| 363 | + return None; |
| 364 | + } |
| 365 | + Some(self.attempt_count - 1) |
| 366 | + } |
| 367 | + |
316 | 368 | /// Returns the full URL used in the last request. |
317 | 369 | /// |
318 | 370 | /// Note that this may not be populated for gRPC requests. |
|
0 commit comments