pub struct TelemetryConfig {
pub logging_enabled: bool,
pub log_filter: String,
pub json_logs: bool,
pub metrics_enabled: bool,
pub metrics_addr: Option<String>,
pub otel_traces: bool,
pub otel_metrics: bool,
pub otel_service_name: String,
pub otel_endpoint: Option<String>,
pub otel_gcp_project: Option<String>,
}Expand description
Telemetry configuration.
Fields§
§logging_enabled: boolEnable structured logging. Installing the subscriber requires the
tracing-subscriber crate feature; without it this flag is inert.
log_filter: StringLog level filter (e.g., “info”, “debug”, “gemini_genai_rs=debug”).
json_logs: boolUse JSON format for logs (production). If false, uses pretty format (development).
metrics_enabled: boolEnable Prometheus metrics endpoint.
metrics_addr: Option<String>Prometheus listen address (e.g., “0.0.0.0:9090”).
otel_traces: boolEnable OTel trace export (requires otel-otlp or otel-gcp feature).
otel_metrics: boolEnable OTel metrics export (requires otel-otlp or otel-gcp feature).
otel_service_name: StringOTel service name for resource identification.
otel_endpoint: Option<String>OTLP collector endpoint (e.g. http://localhost:4317). None lets the
exporter fall back to the standard OTEL_EXPORTER_OTLP_ENDPOINT env var
and its default. Passed to the exporter builder directly; nothing here
mutates the process environment.
otel_gcp_project: Option<String>Google Cloud project ID for GCP-native OTel export. If None, auto-detects from ADC or environment.
Implementations§
Source§impl TelemetryConfig
impl TelemetryConfig
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
A config from the standard environment variables:
OTEL_EXPORTER_OTLP_ENDPOINT: turns on OTLP trace and metric export to that collector (otel-otlp).ADK_TELEMETRY=gcp: turns on Cloud Trace and Cloud Monitoring export (otel-gcp, usebuild_gcp), withGOOGLE_CLOUD_PROJECTas the project when set.OTEL_SERVICE_NAME: the service name (defaultgemini-live).ADK_METRICS_ADDR: serve Prometheus metrics at this address, e.g.0.0.0.0:9464(metrics).RUST_LOG: the log filter (defaultinfo).
Sourcepub fn wants_gcp(&self) -> bool
pub fn wants_gcp(&self) -> bool
Whether this config asks for Cloud Trace and Cloud Monitoring rather
than OTLP (set by from_env for ADK_TELEMETRY=gcp).
Sourcepub fn install_metrics(&self) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn install_metrics(&self) -> Result<(), Box<dyn Error + Send + Sync>>
Serve the SDK’s metrics (Live sessions, reconnections, bytes, tool
calls, tokens by modality, HTTP requests) in Prometheus format at
metrics_addr. Does nothing when metrics are
off or no address is set.
Sourcepub fn prometheus_recorder() -> Result<PrometheusHandle, Box<dyn Error + Send + Sync>>
pub fn prometheus_recorder() -> Result<PrometheusHandle, Box<dyn Error + Send + Sync>>
Record the SDK’s metrics in process and return a handle that renders
them as Prometheus text, for a server that serves its own
/metrics. Installs the global metrics recorder, so call it once.
Sourcepub fn build_otlp(&self) -> Result<Exporters, Box<dyn Error + Send + Sync>>
pub fn build_otlp(&self) -> Result<Exporters, Box<dyn Error + Send + Sync>>
Build the OTLP exporters this config asks for, without installing a subscriber. The meter provider, when metrics are on, is installed globally.
Sourcepub fn init(&self) -> Result<TelemetryGuard, Box<dyn Error>>
pub fn init(&self) -> Result<TelemetryGuard, Box<dyn Error>>
Initialize telemetry subsystems based on configuration: the OTLP
exporters (build_otlp, feature otel-otlp),
the Prometheus endpoint (install_metrics,
feature metrics) and a logging subscriber carrying the trace
exporter (feature tracing-subscriber).
With otel-gcp, use init_gcp instead. To add
layers of your own, use build_otlp and Exporters::layer.
The returned TelemetryGuard must be held alive for the duration of the
application. Dropping it triggers a flush and shutdown of all exporters.
Sourcepub async fn init_gcp(
&self,
) -> Result<TelemetryGuard, Box<dyn Error + Send + Sync>>
pub async fn init_gcp( &self, ) -> Result<TelemetryGuard, Box<dyn Error + Send + Sync>>
Initialize telemetry with Google Cloud-native exporters (Cloud Trace + Cloud Monitoring).
This is the GCP counterpart to init(). It uses opentelemetry-gcloud-trace for
span export and opentelemetry_gcloud_monitoring_exporter for metrics.
If otel_gcp_project is set, it is used as the GCP project ID. Otherwise the
project ID is auto-detected from ADC or the environment.
The returned TelemetryGuard must be held alive for the duration of the
application. Dropping it triggers a flush and shutdown of all exporters.
Trait Implementations§
Source§impl Clone for TelemetryConfig
impl Clone for TelemetryConfig
Source§fn clone(&self) -> TelemetryConfig
fn clone(&self) -> TelemetryConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TelemetryConfig
impl Debug for TelemetryConfig
Auto Trait Implementations§
impl Freeze for TelemetryConfig
impl RefUnwindSafe for TelemetryConfig
impl Send for TelemetryConfig
impl Sync for TelemetryConfig
impl Unpin for TelemetryConfig
impl UnwindSafe for TelemetryConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].