Commit da74dee
authored
feat(spanner): support user-provided OpenTelemetry for client metrics export (#13741)
## Summary
Adds **Client Metrics**: a new, opt-in feature that exports Spanner's
client-side metrics to a caller-provided OpenTelemetry pipeline (OTLP,
Prometheus, any exporter), including on Spanner Omni where the existing
Cloud Monitoring metrics are unavailable.
Fully opt-in and fully decoupled from the existing built-in (Cloud
Monitoring) metrics. Default behavior is unchanged: without a
client-metrics provider, nothing new happens, and built-in metrics
continue to export to Cloud Monitoring exactly as before.
> **Scope note:** This change was split out of a larger PR into two
focused PRs. This PR contains **only** the Client Metrics export
feature. The optional `endpoint` metric attribute for location-aware
routing is a separate follow-up: #13740.
## Two independent features
- **Built-in metrics** (existing, unchanged): export to Google Cloud
Monitoring. Controlled by `setBuiltInMetricsEnabled` and the
`SPANNER_DISABLE_BUILTIN_METRICS` environment variable, exactly as
today. Not available on Spanner Omni.
- **Client metrics** (new): export the client instruments to a
caller-owned OpenTelemetry. Controlled **solely** by
`setClientMetricsProvider(...)` — a `CustomOpenTelemetryMetricsProvider`
turns it on; `NoopMetricsProvider` (or no provider) turns it off. Works
on all instance types, Omni included.
The two are decoupled: `setBuiltInMetricsEnabled` and the env var affect
only the built-in Cloud Monitoring sink and have no effect on client
metrics; the client-metrics provider affects only the caller-owned sink
and has no effect on built-in metrics. Under the hood these are the same
client instruments, exported under the distinct `spanner/client`
namespace — the difference is the export path, not the metrics.
## Emulator handling
Client metrics are not recorded when Spanner is pointed at the emulator.
To make that reliable when the emulator is configured programmatically
(via `setEmulatorHost(...)`) and not only through the
`SPANNER_EMULATOR_HOST` environment variable, this PR broadens emulator
detection: `SpannerOptions.isEmulatorEnabled()` now also recognizes the
builder-configured emulator host, and the connection-check error message
is generalized to describe both the environment-variable and
programmatic configuration paths. This gates both the client and Cloud
Monitoring metrics sinks off against the emulator using a single
detection predicate. Called out explicitly here for reviewer visibility.
## Motivation
Client metrics currently export only to Cloud Monitoring, which is
unavailable on Spanner Omni. Customers running on Omni (or who
standardize on their own observability stack) had no way to receive
these metrics. This lets them route the metrics to any OpenTelemetry
exporter, independently of the built-in Cloud Monitoring configuration.
## API
```java
SdkMeterProviderBuilder meterProviderBuilder = SdkMeterProvider.builder();
SpannerMetrics.configureMeterProviderBuilder(meterProviderBuilder);
// ... attach your exporter to meterProviderBuilder ...
OpenTelemetry otel =
OpenTelemetrySdk.builder().setMeterProvider(meterProviderBuilder.build()).build();
SpannerOptions options =
SpannerOptions.newBuilder()
.setClientMetricsProvider(new CustomOpenTelemetryMetricsProvider(otel))
.build();
```1 parent c2ce8c1 commit da74dee
19 files changed
Lines changed: 1679 additions & 97 deletions
File tree
- java-spanner
- google-cloud-spanner/src
- main/java/com/google/cloud/spanner
- spi/v1
- test/java/com/google/cloud/spanner
- spi/v1
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | | - | |
| 56 | + | |
| 57 | + | |
58 | 58 | | |
59 | | - | |
60 | | - | |
61 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
71 | 111 | | |
72 | 112 | | |
73 | | - | |
| 113 | + | |
74 | 114 | | |
75 | 115 | | |
76 | 116 | | |
77 | 117 | | |
78 | | - | |
| 118 | + | |
79 | 119 | | |
80 | 120 | | |
81 | 121 | | |
| |||
129 | 169 | | |
130 | 170 | | |
131 | 171 | | |
132 | | - | |
| 172 | + | |
133 | 173 | | |
134 | 174 | | |
135 | 175 | | |
| |||
149 | 189 | | |
150 | 190 | | |
151 | 191 | | |
152 | | - | |
| 192 | + | |
153 | 193 | | |
154 | 194 | | |
155 | 195 | | |
156 | 196 | | |
157 | 197 | | |
158 | 198 | | |
159 | | - | |
| 199 | + | |
160 | 200 | | |
161 | 201 | | |
162 | 202 | | |
163 | 203 | | |
164 | | - | |
165 | | - | |
166 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
167 | 207 | | |
168 | 208 | | |
169 | 209 | | |
170 | | - | |
| 210 | + | |
171 | 211 | | |
172 | 212 | | |
173 | 213 | | |
174 | 214 | | |
175 | 215 | | |
176 | 216 | | |
177 | | - | |
| 217 | + | |
178 | 218 | | |
179 | | - | |
| 219 | + | |
180 | 220 | | |
181 | | - | |
182 | | - | |
| 221 | + | |
| 222 | + | |
183 | 223 | | |
184 | 224 | | |
185 | 225 | | |
186 | 226 | | |
187 | | - | |
| 227 | + | |
188 | 228 | | |
189 | 229 | | |
190 | 230 | | |
| |||
214 | 254 | | |
215 | 255 | | |
216 | 256 | | |
217 | | - | |
| 257 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
158 | | - | |
| 158 | + | |
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
| 166 | + | |
167 | 167 | | |
168 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
169 | 209 | | |
170 | 210 | | |
171 | 211 | | |
| |||
0 commit comments