google_cloud_trace_v2/client.rs
1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16#![allow(rustdoc::redundant_explicit_links)]
17#![allow(rustdoc::broken_intra_doc_links)]
18
19/// Implements a client for the Cloud Trace API.
20///
21/// # Example
22/// ```
23/// # tokio_test::block_on(async {
24/// # use google_cloud_trace_v2::client::TraceService;
25/// let client = TraceService::builder().build().await?;
26/// // use `client` to make requests to the Cloud Trace API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// Service for collecting and viewing traces and spans within a trace.
33///
34/// A trace is a collection of spans corresponding to a single
35/// operation or a set of operations in an application.
36///
37/// A span is an individual timed event which forms a node of the trace tree.
38/// A single trace can contain spans from multiple services.
39///
40/// # Configuration
41///
42/// To configure `TraceService` use the `with_*` methods in the type returned
43/// by [builder()][TraceService::builder]. The default configuration should
44/// work for most applications. Common configuration changes include
45///
46/// * [with_endpoint()]: by default this client uses the global default endpoint
47/// (`https://cloudtrace.googleapis.com`). Applications using regional
48/// endpoints or running in restricted networks (e.g. a network configured
49// with [Private Google Access with VPC Service Controls]) may want to
50/// override this default.
51/// * [with_credentials()]: by default this client uses
52/// [Application Default Credentials]. Applications using custom
53/// authentication may need to override this default.
54///
55/// [with_endpoint()]: super::builder::trace_service::ClientBuilder::with_endpoint
56/// [with_credentials()]: super::builder::trace_service::ClientBuilder::credentials
57/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
58/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
59///
60/// # Pooling and Cloning
61///
62/// `TraceService` holds a connection pool internally, it is advised to
63/// create one and the reuse it. You do not need to wrap `TraceService` in
64/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
65/// already uses an `Arc` internally.
66#[derive(Clone, Debug)]
67pub struct TraceService {
68 inner: std::sync::Arc<dyn super::stub::dynamic::TraceService>,
69}
70
71impl TraceService {
72 /// Returns a builder for [TraceService].
73 ///
74 /// ```
75 /// # tokio_test::block_on(async {
76 /// # use google_cloud_trace_v2::client::TraceService;
77 /// let client = TraceService::builder().build().await?;
78 /// # gax::client_builder::Result::<()>::Ok(()) });
79 /// ```
80 pub fn builder() -> super::builder::trace_service::ClientBuilder {
81 gax::client_builder::internal::new_builder(super::builder::trace_service::client::Factory)
82 }
83
84 /// Creates a new client from the provided stub.
85 ///
86 /// The most common case for calling this function is in tests mocking the
87 /// client's behavior.
88 pub fn from_stub<T>(stub: T) -> Self
89 where
90 T: super::stub::TraceService + 'static,
91 {
92 Self {
93 inner: std::sync::Arc::new(stub),
94 }
95 }
96
97 pub(crate) async fn new(
98 config: gaxi::options::ClientConfig,
99 ) -> gax::client_builder::Result<Self> {
100 let inner = Self::build_inner(config).await?;
101 Ok(Self { inner })
102 }
103
104 async fn build_inner(
105 conf: gaxi::options::ClientConfig,
106 ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::TraceService>> {
107 if gaxi::options::tracing_enabled(&conf) {
108 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
109 }
110 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
111 }
112
113 async fn build_transport(
114 conf: gaxi::options::ClientConfig,
115 ) -> gax::client_builder::Result<impl super::stub::TraceService> {
116 super::transport::TraceService::new(conf).await
117 }
118
119 async fn build_with_tracing(
120 conf: gaxi::options::ClientConfig,
121 ) -> gax::client_builder::Result<impl super::stub::TraceService> {
122 Self::build_transport(conf)
123 .await
124 .map(super::tracing::TraceService::new)
125 }
126
127 /// Batch writes new spans to new or existing traces. You cannot update
128 /// existing spans.
129 pub fn batch_write_spans(&self) -> super::builder::trace_service::BatchWriteSpans {
130 super::builder::trace_service::BatchWriteSpans::new(self.inner.clone())
131 }
132
133 /// Creates a new span.
134 pub fn create_span(&self) -> super::builder::trace_service::CreateSpan {
135 super::builder::trace_service::CreateSpan::new(self.inner.clone())
136 }
137}