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