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