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