Skip to main content

google_cloud_trace_v2/
builder.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
17pub mod trace_service {
18    use crate::Result;
19
20    /// A builder for [TraceService][crate::client::TraceService].
21    ///
22    /// ```
23    /// # async fn sample() -> gax::client_builder::Result<()> {
24    /// # use google_cloud_trace_v2::*;
25    /// # use builder::trace_service::ClientBuilder;
26    /// # use client::TraceService;
27    /// let builder : ClientBuilder = TraceService::builder();
28    /// let client = builder
29    ///     .with_endpoint("https://cloudtrace.googleapis.com")
30    ///     .build().await?;
31    /// # Ok(()) }
32    /// ```
33    pub type ClientBuilder =
34        gax::client_builder::ClientBuilder<client::Factory, gaxi::options::Credentials>;
35
36    pub(crate) mod client {
37        use super::super::super::client::TraceService;
38        pub struct Factory;
39        impl gax::client_builder::internal::ClientFactory for Factory {
40            type Client = TraceService;
41            type Credentials = gaxi::options::Credentials;
42            async fn build(
43                self,
44                config: gaxi::options::ClientConfig,
45            ) -> gax::client_builder::Result<Self::Client> {
46                Self::Client::new(config).await
47            }
48        }
49    }
50
51    /// Common implementation for [crate::client::TraceService] request builders.
52    #[derive(Clone, Debug)]
53    pub(crate) struct RequestBuilder<R: std::default::Default> {
54        stub: std::sync::Arc<dyn super::super::stub::dynamic::TraceService>,
55        request: R,
56        options: gax::options::RequestOptions,
57    }
58
59    impl<R> RequestBuilder<R>
60    where
61        R: std::default::Default,
62    {
63        pub(crate) fn new(
64            stub: std::sync::Arc<dyn super::super::stub::dynamic::TraceService>,
65        ) -> Self {
66            Self {
67                stub,
68                request: R::default(),
69                options: gax::options::RequestOptions::default(),
70            }
71        }
72    }
73
74    /// The request builder for [TraceService::batch_write_spans][crate::client::TraceService::batch_write_spans] calls.
75    ///
76    /// # Example
77    /// ```
78    /// # use google_cloud_trace_v2::builder::trace_service::BatchWriteSpans;
79    /// # async fn sample() -> gax::Result<()> {
80    ///
81    /// let builder = prepare_request_builder();
82    /// let response = builder.send().await?;
83    /// # Ok(()) }
84    ///
85    /// fn prepare_request_builder() -> BatchWriteSpans {
86    ///   # panic!();
87    ///   // ... details omitted ...
88    /// }
89    /// ```
90    #[derive(Clone, Debug)]
91    pub struct BatchWriteSpans(RequestBuilder<crate::model::BatchWriteSpansRequest>);
92
93    impl BatchWriteSpans {
94        pub(crate) fn new(
95            stub: std::sync::Arc<dyn super::super::stub::dynamic::TraceService>,
96        ) -> Self {
97            Self(RequestBuilder::new(stub))
98        }
99
100        /// Sets the full request, replacing any prior values.
101        pub fn with_request<V: Into<crate::model::BatchWriteSpansRequest>>(mut self, v: V) -> Self {
102            self.0.request = v.into();
103            self
104        }
105
106        /// Sets all the options, replacing any prior values.
107        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
108            self.0.options = v.into();
109            self
110        }
111
112        /// Sends the request.
113        pub async fn send(self) -> Result<()> {
114            (*self.0.stub)
115                .batch_write_spans(self.0.request, self.0.options)
116                .await
117                .map(gax::response::Response::into_body)
118        }
119
120        /// Sets the value of [name][crate::model::BatchWriteSpansRequest::name].
121        ///
122        /// This is a **required** field for requests.
123        pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
124            self.0.request.name = v.into();
125            self
126        }
127
128        /// Sets the value of [spans][crate::model::BatchWriteSpansRequest::spans].
129        ///
130        /// This is a **required** field for requests.
131        pub fn set_spans<T, V>(mut self, v: T) -> Self
132        where
133            T: std::iter::IntoIterator<Item = V>,
134            V: std::convert::Into<crate::model::Span>,
135        {
136            use std::iter::Iterator;
137            self.0.request.spans = v.into_iter().map(|i| i.into()).collect();
138            self
139        }
140    }
141
142    #[doc(hidden)]
143    impl gax::options::internal::RequestBuilder for BatchWriteSpans {
144        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
145            &mut self.0.options
146        }
147    }
148
149    /// The request builder for [TraceService::create_span][crate::client::TraceService::create_span] calls.
150    ///
151    /// # Example
152    /// ```
153    /// # use google_cloud_trace_v2::builder::trace_service::CreateSpan;
154    /// # async fn sample() -> gax::Result<()> {
155    ///
156    /// let builder = prepare_request_builder();
157    /// let response = builder.send().await?;
158    /// # Ok(()) }
159    ///
160    /// fn prepare_request_builder() -> CreateSpan {
161    ///   # panic!();
162    ///   // ... details omitted ...
163    /// }
164    /// ```
165    #[derive(Clone, Debug)]
166    pub struct CreateSpan(RequestBuilder<crate::model::Span>);
167
168    impl CreateSpan {
169        pub(crate) fn new(
170            stub: std::sync::Arc<dyn super::super::stub::dynamic::TraceService>,
171        ) -> Self {
172            Self(RequestBuilder::new(stub))
173        }
174
175        /// Sets the full request, replacing any prior values.
176        pub fn with_request<V: Into<crate::model::Span>>(mut self, v: V) -> Self {
177            self.0.request = v.into();
178            self
179        }
180
181        /// Sets all the options, replacing any prior values.
182        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
183            self.0.options = v.into();
184            self
185        }
186
187        /// Sends the request.
188        pub async fn send(self) -> Result<crate::model::Span> {
189            (*self.0.stub)
190                .create_span(self.0.request, self.0.options)
191                .await
192                .map(gax::response::Response::into_body)
193        }
194
195        /// Sets the value of [name][crate::model::Span::name].
196        ///
197        /// This is a **required** field for requests.
198        pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
199            self.0.request.name = v.into();
200            self
201        }
202
203        /// Sets the value of [span_id][crate::model::Span::span_id].
204        ///
205        /// This is a **required** field for requests.
206        pub fn set_span_id<T: Into<std::string::String>>(mut self, v: T) -> Self {
207            self.0.request.span_id = v.into();
208            self
209        }
210
211        /// Sets the value of [parent_span_id][crate::model::Span::parent_span_id].
212        pub fn set_parent_span_id<T: Into<std::string::String>>(mut self, v: T) -> Self {
213            self.0.request.parent_span_id = v.into();
214            self
215        }
216
217        /// Sets the value of [display_name][crate::model::Span::display_name].
218        ///
219        /// This is a **required** field for requests.
220        pub fn set_display_name<T>(mut self, v: T) -> Self
221        where
222            T: std::convert::Into<crate::model::TruncatableString>,
223        {
224            self.0.request.display_name = std::option::Option::Some(v.into());
225            self
226        }
227
228        /// Sets or clears the value of [display_name][crate::model::Span::display_name].
229        ///
230        /// This is a **required** field for requests.
231        pub fn set_or_clear_display_name<T>(mut self, v: std::option::Option<T>) -> Self
232        where
233            T: std::convert::Into<crate::model::TruncatableString>,
234        {
235            self.0.request.display_name = v.map(|x| x.into());
236            self
237        }
238
239        /// Sets the value of [start_time][crate::model::Span::start_time].
240        ///
241        /// This is a **required** field for requests.
242        pub fn set_start_time<T>(mut self, v: T) -> Self
243        where
244            T: std::convert::Into<wkt::Timestamp>,
245        {
246            self.0.request.start_time = std::option::Option::Some(v.into());
247            self
248        }
249
250        /// Sets or clears the value of [start_time][crate::model::Span::start_time].
251        ///
252        /// This is a **required** field for requests.
253        pub fn set_or_clear_start_time<T>(mut self, v: std::option::Option<T>) -> Self
254        where
255            T: std::convert::Into<wkt::Timestamp>,
256        {
257            self.0.request.start_time = v.map(|x| x.into());
258            self
259        }
260
261        /// Sets the value of [end_time][crate::model::Span::end_time].
262        ///
263        /// This is a **required** field for requests.
264        pub fn set_end_time<T>(mut self, v: T) -> Self
265        where
266            T: std::convert::Into<wkt::Timestamp>,
267        {
268            self.0.request.end_time = std::option::Option::Some(v.into());
269            self
270        }
271
272        /// Sets or clears the value of [end_time][crate::model::Span::end_time].
273        ///
274        /// This is a **required** field for requests.
275        pub fn set_or_clear_end_time<T>(mut self, v: std::option::Option<T>) -> Self
276        where
277            T: std::convert::Into<wkt::Timestamp>,
278        {
279            self.0.request.end_time = v.map(|x| x.into());
280            self
281        }
282
283        /// Sets the value of [attributes][crate::model::Span::attributes].
284        pub fn set_attributes<T>(mut self, v: T) -> Self
285        where
286            T: std::convert::Into<crate::model::span::Attributes>,
287        {
288            self.0.request.attributes = std::option::Option::Some(v.into());
289            self
290        }
291
292        /// Sets or clears the value of [attributes][crate::model::Span::attributes].
293        pub fn set_or_clear_attributes<T>(mut self, v: std::option::Option<T>) -> Self
294        where
295            T: std::convert::Into<crate::model::span::Attributes>,
296        {
297            self.0.request.attributes = v.map(|x| x.into());
298            self
299        }
300
301        /// Sets the value of [stack_trace][crate::model::Span::stack_trace].
302        pub fn set_stack_trace<T>(mut self, v: T) -> Self
303        where
304            T: std::convert::Into<crate::model::StackTrace>,
305        {
306            self.0.request.stack_trace = std::option::Option::Some(v.into());
307            self
308        }
309
310        /// Sets or clears the value of [stack_trace][crate::model::Span::stack_trace].
311        pub fn set_or_clear_stack_trace<T>(mut self, v: std::option::Option<T>) -> Self
312        where
313            T: std::convert::Into<crate::model::StackTrace>,
314        {
315            self.0.request.stack_trace = v.map(|x| x.into());
316            self
317        }
318
319        /// Sets the value of [time_events][crate::model::Span::time_events].
320        pub fn set_time_events<T>(mut self, v: T) -> Self
321        where
322            T: std::convert::Into<crate::model::span::TimeEvents>,
323        {
324            self.0.request.time_events = std::option::Option::Some(v.into());
325            self
326        }
327
328        /// Sets or clears the value of [time_events][crate::model::Span::time_events].
329        pub fn set_or_clear_time_events<T>(mut self, v: std::option::Option<T>) -> Self
330        where
331            T: std::convert::Into<crate::model::span::TimeEvents>,
332        {
333            self.0.request.time_events = v.map(|x| x.into());
334            self
335        }
336
337        /// Sets the value of [links][crate::model::Span::links].
338        pub fn set_links<T>(mut self, v: T) -> Self
339        where
340            T: std::convert::Into<crate::model::span::Links>,
341        {
342            self.0.request.links = std::option::Option::Some(v.into());
343            self
344        }
345
346        /// Sets or clears the value of [links][crate::model::Span::links].
347        pub fn set_or_clear_links<T>(mut self, v: std::option::Option<T>) -> Self
348        where
349            T: std::convert::Into<crate::model::span::Links>,
350        {
351            self.0.request.links = v.map(|x| x.into());
352            self
353        }
354
355        /// Sets the value of [status][crate::model::Span::status].
356        pub fn set_status<T>(mut self, v: T) -> Self
357        where
358            T: std::convert::Into<rpc::model::Status>,
359        {
360            self.0.request.status = std::option::Option::Some(v.into());
361            self
362        }
363
364        /// Sets or clears the value of [status][crate::model::Span::status].
365        pub fn set_or_clear_status<T>(mut self, v: std::option::Option<T>) -> Self
366        where
367            T: std::convert::Into<rpc::model::Status>,
368        {
369            self.0.request.status = v.map(|x| x.into());
370            self
371        }
372
373        /// Sets the value of [same_process_as_parent_span][crate::model::Span::same_process_as_parent_span].
374        pub fn set_same_process_as_parent_span<T>(mut self, v: T) -> Self
375        where
376            T: std::convert::Into<wkt::BoolValue>,
377        {
378            self.0.request.same_process_as_parent_span = std::option::Option::Some(v.into());
379            self
380        }
381
382        /// Sets or clears the value of [same_process_as_parent_span][crate::model::Span::same_process_as_parent_span].
383        pub fn set_or_clear_same_process_as_parent_span<T>(
384            mut self,
385            v: std::option::Option<T>,
386        ) -> Self
387        where
388            T: std::convert::Into<wkt::BoolValue>,
389        {
390            self.0.request.same_process_as_parent_span = v.map(|x| x.into());
391            self
392        }
393
394        /// Sets the value of [child_span_count][crate::model::Span::child_span_count].
395        pub fn set_child_span_count<T>(mut self, v: T) -> Self
396        where
397            T: std::convert::Into<wkt::Int32Value>,
398        {
399            self.0.request.child_span_count = std::option::Option::Some(v.into());
400            self
401        }
402
403        /// Sets or clears the value of [child_span_count][crate::model::Span::child_span_count].
404        pub fn set_or_clear_child_span_count<T>(mut self, v: std::option::Option<T>) -> Self
405        where
406            T: std::convert::Into<wkt::Int32Value>,
407        {
408            self.0.request.child_span_count = v.map(|x| x.into());
409            self
410        }
411
412        /// Sets the value of [span_kind][crate::model::Span::span_kind].
413        pub fn set_span_kind<T: Into<crate::model::span::SpanKind>>(mut self, v: T) -> Self {
414            self.0.request.span_kind = v.into();
415            self
416        }
417    }
418
419    #[doc(hidden)]
420    impl gax::options::internal::RequestBuilder for CreateSpan {
421        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
422            &mut self.0.options
423        }
424    }
425}