@@ -124,6 +124,33 @@ custom_content: |
124124 This feature is available once you upgrade to version 2.16.0 and above.
125125 Follow the guide on https://cloud.google.com/bigtable/docs/client-side-metrics-setup to enable.
126126
127+ ## Client side metrics
128+
129+ Since version 2.38.0, [client side metrics](https://cloud.google.com/bigtable/docs/client-side-metrics)
130+ is enabled by default. This feature collects useful telemetry data in the client and is recommended to
131+ use in conjunction with server-side metrics to get a complete, actionable view of your Bigtable
132+ performance. There is no additional cost to publish and view client-side metrics
133+ in Cloud Monitoring.
134+
135+ ### Opt-out client side metrics
136+
137+ You can opt-out client side metrics with the following settings:
138+
139+ ```
140+ BigtableDataSettings settings = BigtableDataSettings.newBuilder()
141+ .setProjectId("my-project")
142+ .setInstanceId("my-instance")
143+ .setMetricsProvider(NoopMetricsProvider.INSTANCE)
144+ .build();
145+ ```
146+
147+ ### Use a custom OpenTelemetry instance
148+
149+ If your application already has OpenTelemetry integration, you can register client side metrics on
150+ your OpenTelemetry instance. You can refer to
151+ [CustomOpenTelemetryMetricsProvider](https://github.com/googleapis/java-bigtable/blob/main/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/CustomOpenTelemetryMetricsProvider.java)
152+ on how to set it up.
153+
127154 ## Client request tracing: OpenCensus Tracing
128155
129156 Cloud Bigtable client supports [OpenCensus Tracing](https://opencensus.io/tracing/),
@@ -138,13 +165,13 @@ custom_content: |
138165 <dependency>
139166 <groupId>io.opencensus</groupId>
140167 <artifactId>opencensus-impl</artifactId>
141- <version>0.24.0 </version>
168+ <version>0.31.1 </version>
142169 <scope>runtime</scope>
143170 </dependency>
144171 <dependency>
145172 <groupId>io.opencensus</groupId>
146173 <artifactId>opencensus-exporter-trace-stackdriver</artifactId>
147- <version>0.24.0 </version>
174+ <version>0.31.1 </version>
148175 <exclusions>
149176 <exclusion>
150177 <groupId>io.grpc</groupId>
@@ -197,140 +224,46 @@ custom_content: |
197224 );
198225 ```
199226
200- ## Enabling Cloud Bigtable Metrics: OpenCensus Stats
201-
202- ---
203- Note: We recommend [enabling client side built-in metrics](#enabling-client-side-metrics)
204- if you want to view your metrics on cloud monitoring. This integration is only for exporting the
205- metrics to a third party dashboard.
206- ---
207-
208- Cloud Bigtable client supports [Opencensus Metrics](https://opencensus.io/stats/),
209- which gives insight into the client internals and aids in debugging production issues.
210- All Cloud Bigtable Metrics are prefixed with `cloud.google.com/java/bigtable/`. The
211- metrics will be tagged with:
212- * `bigtable_project_id`: the project that contains the target Bigtable instance.
213- Please note that this id could be different from project that the client is running
214- in and different from the project where the metrics are exported to.
215- * `bigtable_instance_id`: the instance id of the target Bigtable instance
216- * `bigtable_app_profile_id`: the app profile id that is being used to access the target
217- Bigtable instance
218-
219- ### Available operation level metric views:
220-
221- * `cloud.google.com/java/bigtable/op_latency`: A distribution of latency of
222- each client method call, across all of it's RPC attempts. Tagged by
223- operation name and final response status.
224-
225- * `cloud.google.com/java/bigtable/completed_ops`: The total count of
226- method invocations. Tagged by operation name and final response status.
227+ ### Disable Bigtbale traces
227228
228- * `cloud.google.com/java/bigtable/read_rows_first_row_latency`: A
229- distribution of the latency of receiving the first row in a ReadRows
230- operation.
229+ If your application already has OpenCensus Tracing integration and you want to disable Bigtable
230+ traces, you can do the following:
231231
232- * `cloud.google.com/java/bigtable/attempt_latency`: A distribution of latency of
233- each client RPC, tagged by operation name and the attempt status. Under normal
234- circumstances, this will be identical to op_latency. However, when the client
235- receives transient errors, op_latency will be the sum of all attempt_latencies
236- and the exponential delays.
237-
238- * `cloud.google.com/java/bigtable/attempts_per_op`: A distribution of attempts that
239- each operation required, tagged by operation name and final operation status.
240- Under normal circumstances, this will be 1.
241-
242- #### GFE metric views:
243- * `cloud.google.com/java/bigtable/gfe_latency`: A distribution of the latency
244- between Google's network receives an RPC and reads back the first byte of
245- the response.
246-
247- * `cloud.google.com/java/bigtable/gfe_header_missing_count`: A counter of the
248- number of RPC responses received without the server-timing header, which
249- indicates that the request probably never reached Google's network.
250-
251- By default, the functionality is disabled. For example to enable metrics using
252- [Google Stackdriver](https://cloud.google.com/monitoring/docs/):
253-
254-
255- [//]: # (TODO: figure out how to keep opencensus version in sync with pom.xml)
256-
257- If you are using Maven, add this to your pom.xml file
258- ```xml
259- <dependency>
260- <groupId>io.opencensus</groupId>
261- <artifactId>opencensus-impl</artifactId>
262- <version>0.24.0</version>
263- <scope>runtime</scope>
264- </dependency>
265- <dependency>
266- <groupId>io.opencensus</groupId>
267- <artifactId>opencensus-exporter-stats-stackdriver</artifactId>
268- <version>0.24.0</version>
269- <exclusions>
270- <exclusion>
271- <groupId>io.grpc</groupId>
272- <artifactId>*</artifactId>
273- </exclusion>
274- <exclusion>
275- <groupId>com.google.auth</groupId>
276- <artifactId>*</artifactId>
277- </exclusion>
278- </exclusions>
279- </dependency>
280- ```
281- If you are using Gradle, add this to your dependencies
282- ```Groovy
283- compile 'io.opencensus:opencensus-impl:0.24.0'
284- compile 'io.opencensus:opencensus-exporter-stats-stackdriver:0.24.0'
285232 ```
286- If you are using SBT, add this to your dependencies
287- ```Scala
288- libraryDependencies += "io.opencensus" % "opencensus-impl" % "0.24.0"
289- libraryDependencies += "io.opencensus" % "opencensus-exporter-stats-stackdriver" % "0.24.0"
233+ public static class MySampler extends Sampler {
234+
235+ private final Sampler childSampler;
236+
237+ MySampler(Sampler child) {
238+ this.childSampler = child;
239+ }
240+
241+ @Override
242+ public boolean shouldSample(@Nullable SpanContext parentContext,
243+ @Nullable Boolean hasRemoteParent,
244+ TraceId traceId,
245+ SpanId spanId,
246+ String name,
247+ List<Span> parentLinks) {
248+ if (name.contains("Bigtable")) {
249+ return false;
250+ }
251+ return childSampler.shouldSample(parentContext, hasRemoteParent, traceId, spanId, name, parentLinks);
252+ }
253+
254+ @Override
255+ public String getDescription() {
256+ return "from my sampler";
257+ }
258+ }
290259 ```
291260
292- At the start of your application configure the exporter and enable the Bigtable stats views:
293-
294- ```java
295- import io.opencensus.exporter.stats.stackdriver.StackdriverStatsConfiguration;
296- import io.opencensus.exporter.stats.stackdriver.StackdriverStatsExporter;
297-
298- StackdriverStatsExporter.createAndRegister(
299- StackdriverStatsConfiguration.builder()
300- .setProjectId("YOUR_PROJECT_ID")
301- .build()
302- );
303-
304- BigtableDataSettings.enableOpenCensusStats();
305- // Enable GFE metric views
306- BigtableDataSettings.enableGfeOpenCensusStats();
261+ And use this sampler in your trace config:
307262 ```
308-
309- You can view the metrics on the Google Cloud Platform Console
310- [Metrics explorer](https://console.cloud.google.com/monitoring/metrics-explorer)
311- page.
312-
313- You can configure how frequently metrics are pushed to StackDriver and the
314- [Monitored resource type](https://cloud.google.com/monitoring/api/resources) by
315- updating `StackdriverStatsConfiguration`:
316-
317- ``` java
318- // Example: configuring export interval and monitored resource type
319- StackdriverStatsExporter.createAndRegister(
320- StackdriverStatsConfiguration.builder()
321- .setProjectId("YOUR_PROJECT_ID")
322- // Exporting metrics every 10 seconds
323- .setExportInterval(Duration.create(10, 0))
324- // Configure monitored resource type. A common practice is to use the
325- // monitored resource objects that represent the physical resources
326- // where your application code is running. See the full list of
327- // monitored resource type here:
328- // https://cloud.google.com/monitoring/api/resources
329- .setMonitoredResource(MonitoredResource.newBuilder()
330- .setType("global")
331- .putLabels("project_id", "YOUR_PROJECT_ID")
332- .build())
333- .build()
263+ Tracing.getTraceConfig().updateActiveTraceParams(
264+ Tracing.getTraceConfig().getActiveTraceParams().toBuilder()
265+ .setSampler(new MySampler(Samplers.probabilitySampler(0.1)))
266+ .build()
334267 );
335268 ```
336269
0 commit comments