pub trait SpannerBuilderExt: SpannerBuilderExt {
// Required methods
fn with_channel_pool(
self,
pool_config: impl Into<ChannelPoolConfig>,
) -> Self;
fn with_instance_type(self, instance_type: InstanceType) -> Self;
fn with_omni_tls(self, tls_config: TlsConfig) -> Self;
fn with_meter_provider(
self,
provider: Arc<dyn MeterProvider + Send + Sync>,
) -> Self;
fn with_export_builtin_metrics_to_custom_provider(
self,
export: bool,
) -> Self;
fn with_export_builtin_metrics_to_cloud_monitoring(
self,
export: bool,
) -> Self;
}Expand description
Extension trait for ClientBuilder (also exported as SpannerBuilder) to configure Spanner-specific options.
This trait is sealed and cannot be implemented for types outside of this crate.
Required Methods§
Sourcefn with_channel_pool(self, pool_config: impl Into<ChannelPoolConfig>) -> Self
fn with_channel_pool(self, pool_config: impl Into<ChannelPoolConfig>) -> Self
Configures the gRPC channel pool for the Spanner client.
§Example
let client = Spanner::builder()
.with_channel_pool(DynamicChannelPoolConfig::new())
.build()
.await?;Accepts any configuration convertible into ChannelPoolConfig, such as
StaticChannelPoolConfig or DynamicChannelPoolConfig.
By default, the client uses a dynamic channel pool (DynamicChannelPoolConfig)
starting with 4 channels and scaling up to 256 channels based on RPC concurrency and error feedback.
When connecting to the Spanner emulator, the client defaults to a static pool with 1 channel.
Sourcefn with_instance_type(self, instance_type: InstanceType) -> Self
fn with_instance_type(self, instance_type: InstanceType) -> Self
Sets the target InstanceType (Cloud vs Omni) for the Spanner client.
§Example
let client = Spanner::builder()
.with_instance_type(InstanceType::Omni)
.build()
.await?;Sourcefn with_omni_tls(self, tls_config: TlsConfig) -> Self
fn with_omni_tls(self, tls_config: TlsConfig) -> Self
Configures custom TLS or mutual TLS (mTLS) settings for Spanner Omni.
§Example
let tls_config = TlsConfig::new()
.with_root_certificate_file("path/to/ca.pem")?;
let client = Spanner::builder()
.with_omni_tls(tls_config)
.build()
.await?;Calling this method automatically configures the client instance type as InstanceType::Omni.
Sourcefn with_meter_provider(
self,
provider: Arc<dyn MeterProvider + Send + Sync>,
) -> Self
Available on crate feature unstable-metrics only.
fn with_meter_provider( self, provider: Arc<dyn MeterProvider + Send + Sync>, ) -> Self
unstable-metrics only.Configures a custom OpenTelemetry MeterProvider for recording Client metrics.
§Example
let provider = Arc::new(SdkMeterProvider::builder().build());
let spanner = Spanner::builder()
.with_meter_provider(provider)
.build()
.await?;The caller owns the lifecycle of this provider; Spanner will not shut it down.
§Client Metrics
When configured, Client metrics (such as gRPC channel pool metrics) are recorded directly to this provider.
§Built-in Metrics Export (Secondary)
In addition to Client metrics, this provider can optionally receive Spanner built-in request and attempt latency metrics:
-
Cloud Spanner: Built-in metrics are exported directly to Google Cloud Monitoring free of charge and are not duplicated to this provider by default to protect users from unexpected third-party monitoring costs. To export built-in metrics to this provider as well, call
with_export_builtin_metrics_to_custom_provider(true). Note that this opt-in is required on Cloud Spanner even when thebuiltin-metricsCargo feature is compiled out. -
Spanner Omni: Because Cloud Monitoring is not active for Omni, built-in metrics are exported to this provider by default.
Sourcefn with_export_builtin_metrics_to_custom_provider(self, export: bool) -> Self
Available on crate feature unstable-metrics only.
fn with_export_builtin_metrics_to_custom_provider(self, export: bool) -> Self
unstable-metrics only.Configures whether built-in request and attempt latency metrics should be
exported to the custom MeterProvider configured via
with_meter_provider.
§Example
let provider = Arc::new(SdkMeterProvider::builder().build());
let client = Spanner::builder()
.with_meter_provider(provider)
.with_export_builtin_metrics_to_custom_provider(true)
.build()
.await?;§Background & Cost Considerations
Cloud Spanner collects curated client metrics (such as operation_latencies,
attempt_latencies, and attempt_count).
-
Cloud Spanner: Built-in metrics are exported directly to Google Cloud Monitoring (GCM) free of charge under the
spanner.googleapis.com/internal/client/namespace. If these high-frequency histograms were automatically duplicated to a customer’s customMeterProvider(which may export to Datadog, New Relic, Dynatrace, or custom GCM ingestion pipelines), the customer could incur substantial unexpected monitoring and ingestion costs. Therefore, on Cloud Spanner, exporting built-in metrics to the customMeterProviderdefaults tofalse(even when thebuiltin-metricsCargo feature is compiled out). Callers must explicitly opt in by callingwith_export_builtin_metrics_to_custom_provider(true)if they want built-in metrics sent to their custom OpenTelemetry sink. -
Spanner Omni: Spanner Omni instances run outside GCP where Cloud Monitoring is not active. Omni customers providing a custom
MeterProviderrely on it as their primary metrics sink. Therefore, on Spanner Omni, exporting built-in metrics to the customMeterProviderdefaults totrue. -
Emulator: When connecting to the Spanner emulator, all built-in metrics collection and export are disabled.
Sourcefn with_export_builtin_metrics_to_cloud_monitoring(self, export: bool) -> Self
Available on crate feature builtin-metrics only.
fn with_export_builtin_metrics_to_cloud_monitoring(self, export: bool) -> Self
builtin-metrics only.Configures whether built-in request and attempt latency metrics should be exported to Google Cloud Monitoring.
§Example
let client = Spanner::builder()
.with_export_builtin_metrics_to_cloud_monitoring(false)
.build()
.await?;§Default & Environment Overrides
-
Cloud Spanner: Defaults to
true. Export to Google Cloud Monitoring can also be disabled by setting the environment variableSPANNER_DISABLE_BUILTIN_METRICS=true. When explicitly configured via this method, the programmatic setting takes precedence. -
Spanner Omni & Emulator: Defaults to
false. Cloud Monitoring export is never enabled for Spanner Omni instances or when connecting to the Spanner emulator.
§Independence from Custom Provider Export
Disabling Cloud Monitoring export does not affect built-in metrics exported to a
custom MeterProvider configured via with_meter_provider and
with_export_builtin_metrics_to_custom_provider (available when the unstable-metrics
feature is enabled).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".