public final class CustomOpenTelemetryMetricsProvider implements MetricsProviderA MetricsProvider that records Spanner client metrics on a caller-provided OpenTelemetry instance. The caller owns the metrics pipeline (readers, exporters and resource); Spanner only records the client metric instruments on it. The caller-owned sink is never exported to Google Cloud Monitoring by the Spanner client and is independent of the built-in Cloud Monitoring export.
Metrics recorded through this provider use the spanner/client/ instrument namespace
instead of the reserved spanner.googleapis.com/internal/client/ namespace that is used
for the Cloud Monitoring export, so that re-exporting the caller-owned pipeline to Cloud
Monitoring does not conflict with the curated Spanner metric descriptors.
It is recommended to register the Spanner client-metrics views on the io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder with SpannerMetrics#configureMeterProviderBuilder(io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder) before creating the OpenTelemetry instance. Without the views, metrics are still recorded, but with the raw instrument names, default histogram buckets and without attribute filtering. When registering the views, use a meter provider that is dedicated to Spanner client metrics; see SpannerMetrics#configureMeterProviderBuilder(io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder) for details.
gRPC-layer metrics are only recorded if the given OpenTelemetry instance is an instance of io.opentelemetry.sdk.OpenTelemetrySdk; for any other implementation they are skipped. All other client metrics work with any OpenTelemetry implementation.
Client metrics are not recorded when the client runs against the Spanner emulator, regardless of the configured MetricsProvider; the caller-owned sink is inactive in that mode.
This provider is independent of the default Cloud Monitoring export: the caller-owned
destination recorded here keeps recording even when the Cloud Monitoring (GCM) sink is disabled
via SpannerOptions.Builder#setBuiltInMetricsEnabled(boolean) or the
SPANNER_DISABLE_BUILTIN_METRICS environment variable. On SpannerOptions.InstanceType#OMNI clients, where the GCM sink is never active, this provider is
the way to export client metrics.
Example usage:
SdkMeterProviderBuilder meterProviderBuilder =
SdkMeterProvider.builder().registerMetricReader(PeriodicMetricReader.create(myExporter));
SpannerMetrics.configureMeterProviderBuilder(meterProviderBuilder);
OpenTelemetry openTelemetry =
OpenTelemetrySdk.builder().setMeterProvider(meterProviderBuilder.build()).build();
SpannerOptions options =
SpannerOptions.newBuilder()
.setClientMetricsProvider(CustomOpenTelemetryMetricsProvider.create(openTelemetry))
.build();
Implements
MetricsProviderStatic Methods
create(OpenTelemetry openTelemetry)
public static CustomOpenTelemetryMetricsProvider create(OpenTelemetry openTelemetry)Creates a provider that records Spanner client metrics on the given caller-owned OpenTelemetry instance.
| Parameter | |
|---|---|
| Name | Description |
openTelemetry |
io.opentelemetry.api.OpenTelemetry |
| Returns | |
|---|---|
| Type | Description |
CustomOpenTelemetryMetricsProvider |
|
Methods
getOpenTelemetry()
public OpenTelemetry getOpenTelemetry()Returns the caller-owned OpenTelemetry instance used for client metrics.
| Returns | |
|---|---|
| Type | Description |
io.opentelemetry.api.OpenTelemetry |
|