google_cloud_trace_v1/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::bare_urls)]
17#![allow(rustdoc::broken_intra_doc_links)]
18#![allow(rustdoc::invalid_html_tags)]
19#![allow(rustdoc::redundant_explicit_links)]
20
21/// Implements a client for the Cloud Trace API.
22///
23/// # Example
24/// ```
25/// # use google_cloud_trace_v1::client::TraceService;
26/// use google_cloud_gax::paginator::ItemPaginator as _;
27/// async fn sample(
28/// ) -> anyhow::Result<()> {
29/// let client = TraceService::builder().build().await?;
30/// let mut list = client.list_traces()
31/// /* set fields */
32/// .by_item();
33/// while let Some(item) = list.next().await.transpose()? {
34/// println!("{:?}", item);
35/// }
36/// Ok(())
37/// }
38/// ```
39///
40/// # Service Description
41///
42/// This file describes an API for collecting and viewing traces and spans
43/// within a trace. A Trace is a collection of spans corresponding to a single
44/// operation or set of operations for an application. A span is an individual
45/// timed event which forms a node of the trace tree. Spans for a single trace
46/// may span multiple services.
47///
48/// # Configuration
49///
50/// To configure `TraceService` use the `with_*` methods in the type returned
51/// by [builder()][TraceService::builder]. The default configuration should
52/// work for most applications. Common configuration changes include
53///
54/// * [with_endpoint()]: by default this client uses the global default endpoint
55/// (`https://cloudtrace.googleapis.com`). Applications using regional
56/// endpoints or running in restricted networks (e.g. a network configured
57/// with [Private Google Access with VPC Service Controls]) may want to
58/// override this default.
59/// * [with_credentials()]: by default this client uses
60/// [Application Default Credentials]. Applications using custom
61/// authentication may need to override this default.
62///
63/// [with_endpoint()]: super::builder::trace_service::ClientBuilder::with_endpoint
64/// [with_credentials()]: super::builder::trace_service::ClientBuilder::with_credentials
65/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
66/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
67///
68/// # Pooling and Cloning
69///
70/// `TraceService` holds a connection pool internally, it is advised to
71/// create one and reuse it. You do not need to wrap `TraceService` in
72/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
73/// already uses an `Arc` internally.
74#[derive(Clone, Debug)]
75pub struct TraceService {
76 inner: std::sync::Arc<dyn super::stub::dynamic::TraceService>,
77}
78
79impl TraceService {
80 /// Returns a builder for [TraceService].
81 ///
82 /// ```
83 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
84 /// # use google_cloud_trace_v1::client::TraceService;
85 /// let client = TraceService::builder().build().await?;
86 /// # Ok(()) }
87 /// ```
88 pub fn builder() -> super::builder::trace_service::ClientBuilder {
89 crate::new_client_builder(super::builder::trace_service::client::Factory)
90 }
91
92 /// Creates a new client from the provided stub.
93 ///
94 /// The most common case for calling this function is in tests mocking the
95 /// client's behavior.
96 pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
97 where
98 T: super::stub::TraceService + 'static,
99 {
100 Self { inner: stub.into() }
101 }
102
103 pub(crate) async fn new(
104 config: gaxi::options::ClientConfig,
105 ) -> crate::ClientBuilderResult<Self> {
106 let inner = Self::build_inner(config).await?;
107 Ok(Self { inner })
108 }
109
110 async fn build_inner(
111 conf: gaxi::options::ClientConfig,
112 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::TraceService>> {
113 if gaxi::options::tracing_enabled(&conf) {
114 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
115 }
116 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
117 }
118
119 async fn build_transport(
120 conf: gaxi::options::ClientConfig,
121 ) -> crate::ClientBuilderResult<impl super::stub::TraceService> {
122 super::transport::TraceService::new(conf).await
123 }
124
125 async fn build_with_tracing(
126 conf: gaxi::options::ClientConfig,
127 ) -> crate::ClientBuilderResult<impl super::stub::TraceService> {
128 Self::build_transport(conf)
129 .await
130 .map(super::tracing::TraceService::new)
131 }
132
133 /// Returns of a list of traces that match the specified filter conditions.
134 ///
135 /// # Example
136 /// ```
137 /// # use google_cloud_trace_v1::client::TraceService;
138 /// use google_cloud_gax::paginator::ItemPaginator as _;
139 /// use google_cloud_trace_v1::Result;
140 /// async fn sample(
141 /// client: &TraceService
142 /// ) -> Result<()> {
143 /// let mut list = client.list_traces()
144 /// /* set fields */
145 /// .by_item();
146 /// while let Some(item) = list.next().await.transpose()? {
147 /// println!("{:?}", item);
148 /// }
149 /// Ok(())
150 /// }
151 /// ```
152 pub fn list_traces(&self) -> super::builder::trace_service::ListTraces {
153 super::builder::trace_service::ListTraces::new(self.inner.clone())
154 }
155
156 /// Gets a single trace by its ID.
157 ///
158 /// # Example
159 /// ```
160 /// # use google_cloud_trace_v1::client::TraceService;
161 /// use google_cloud_trace_v1::Result;
162 /// async fn sample(
163 /// client: &TraceService
164 /// ) -> Result<()> {
165 /// let response = client.get_trace()
166 /// /* set fields */
167 /// .send().await?;
168 /// println!("response {:?}", response);
169 /// Ok(())
170 /// }
171 /// ```
172 pub fn get_trace(&self) -> super::builder::trace_service::GetTrace {
173 super::builder::trace_service::GetTrace::new(self.inner.clone())
174 }
175
176 /// Sends new traces to Stackdriver Trace or updates existing traces. If the ID
177 /// of a trace that you send matches that of an existing trace, any fields
178 /// in the existing trace and its spans are overwritten by the provided values,
179 /// and any new fields provided are merged with the existing trace data. If the
180 /// ID does not match, a new trace is created.
181 ///
182 /// # Example
183 /// ```
184 /// # use google_cloud_trace_v1::client::TraceService;
185 /// use google_cloud_trace_v1::Result;
186 /// async fn sample(
187 /// client: &TraceService
188 /// ) -> Result<()> {
189 /// client.patch_traces()
190 /// /* set fields */
191 /// .send().await?;
192 /// Ok(())
193 /// }
194 /// ```
195 pub fn patch_traces(&self) -> super::builder::trace_service::PatchTraces {
196 super::builder::trace_service::PatchTraces::new(self.inner.clone())
197 }
198}