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