google_cloud_trace_v2/
builder.rs1pub mod trace_service {
18 use crate::Result;
19
20 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 #[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 #[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 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 pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
107 self.0.options = v.into();
108 self
109 }
110
111 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 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 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 #[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 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 pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
182 self.0.options = v.into();
183 self
184 }
185
186 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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}