Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions google-cloud-bigtable-deps-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Other opencensus packages' versions are pulled through com.google.cloud:third-party-dependencies, but has to be manually specified for this one. -->
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-contrib-resource-util</artifactId>
<version>0.31.1</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
19 changes: 0 additions & 19 deletions google-cloud-bigtable/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -382,23 +382,4 @@
<method>*</method>
<to>*</to>
</difference>
<!-- OpenCensus removal -->
<difference>
<differenceType>7002</differenceType>
<className>com/google/cloud/bigtable/data/v2/BigtableDataSettings</className>
<method>*OpenCensusStats*</method>
</difference>
<difference>
<differenceType>8001</differenceType>
<className>com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerFactory*</className>
</difference>
<difference>
<differenceType>8001</differenceType>
<className>com/google/cloud/bigtable/data/v2/stub/metrics/RpcMeasureConstants*</className>
</difference>
<difference>
<differenceType>8001</differenceType>
<className>com/google/cloud/bigtable/data/v2/stub/metrics/RpcViews*</className>
</difference>
<!-- /OpenCensus removal -->
</differences>
27 changes: 27 additions & 0 deletions google-cloud-bigtable/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-api</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-alts</artifactId>
Expand Down Expand Up @@ -180,6 +184,10 @@
<groupId>io.grpc</groupId>
<artifactId>grpc-util</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-googleapis</artifactId>
Expand Down Expand Up @@ -316,6 +324,11 @@
<artifactId>grpc-testing</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down Expand Up @@ -696,6 +709,20 @@
</dependencies>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<!--
grpc-auth is not directly used transitively, but is pulled to align with other grpc parts
opencensus-impl-core is brought in transitively through opencensus-impl
-->
<ignoredUsedUndeclaredDependencies>
<ignoredUsedUndeclaredDependency>io.opencensus:opencensus-impl-core</ignoredUsedUndeclaredDependency>
</ignoredUsedUndeclaredDependencies>
</configuration>
</plugin>

<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,62 @@ public static Builder newBuilderForEmulator(String hostname, int port) {
return builder;
}

/**
* @deprecated OpenCensus support is deprecated and will be removed in a future version
* Enables OpenCensus metric aggregations.
*
* <p>This will register Bigtable client relevant {@link io.opencensus.stats.View}s. When coupled
* with an exporter, it allows users to monitor client behavior.
*
* <p>Please note that in addition to calling this method, the application must:
* <ul>
* <li>Include openensus-impl dependency on the classpath
* <li>Configure an exporter like opencensus-exporter-stats-stackdriver
* </ul>
*
* <p>Example usage for maven:
* <pre>{@code
* <dependency>
* <groupId>io.opencensus</groupId>
* <artifactId>opencensus-impl</artifactId>
* <version>${opencensus.version}</version>
* <scope>runtime</scope>
* </dependency>
*
* <dependency>
* <groupId>io.opencensus</groupId>
* <artifactId>opencensus-exporter-stats-stackdriver</artifactId>
* <version>${opencensus.version}</version>
* </dependency>
* </pre>
*
* Java:
* <pre>{@code
* StackdriverStatsExporter.createAndRegister();
* BigtableDataSettings.enableOpenCensusStats();
* }</pre>
*/
@Deprecated
public static void enableOpenCensusStats() {
com.google.cloud.bigtable.data.v2.stub.metrics.RpcViews.registerBigtableClientViews();
// TODO(igorbernstein): Enable grpc views once we upgrade to grpc-java 1.24.0
// Required change: https://github.com/grpc/grpc-java/pull/5996
// io.opencensus.contrib.grpc.metrics.RpcViews.registerClientGrpcBasicViews();
}

/**
* @deprecated OpenCensus support is deprecated and will be removed in a future version Enables
* OpenCensus GFE metric aggregations.
* <p>This will register views for gfe_latency and gfe_header_missing_count metrics.
* <p>gfe_latency measures the latency between Google's network receives an RPC and reads back
* the first byte of the response. gfe_header_missing_count is a counter of the number of RPC
* responses received without the server-timing header.
*/
@Deprecated
public static void enableGfeOpenCensusStats() {
com.google.cloud.bigtable.data.v2.stub.metrics.RpcViews.registerBigtableClientGfeViews();
}

/**
* Register built in metrics.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.api.gax.batching.BatcherImpl;
import com.google.api.gax.batching.FlowController;
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.grpc.GaxGrpcProperties;
import com.google.api.gax.grpc.GrpcCallContext;
import com.google.api.gax.grpc.GrpcCallSettings;
import com.google.api.gax.grpc.GrpcRawCallableFactory;
Expand All @@ -47,6 +48,7 @@
import com.google.api.gax.rpc.UnaryCallSettings;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.api.gax.tracing.ApiTracerFactory;
import com.google.api.gax.tracing.OpencensusTracerFactory;
import com.google.api.gax.tracing.SpanName;
import com.google.api.gax.tracing.TracedServerStreamingCallable;
import com.google.api.gax.tracing.TracedUnaryCallable;
Expand Down Expand Up @@ -98,6 +100,8 @@
import com.google.cloud.bigtable.data.v2.stub.metrics.BigtableTracerUnaryCallable;
import com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsTracerFactory;
import com.google.cloud.bigtable.data.v2.stub.metrics.CompositeTracerFactory;
import com.google.cloud.bigtable.data.v2.stub.metrics.MetricsTracerFactory;
import com.google.cloud.bigtable.data.v2.stub.metrics.RpcMeasureConstants;
import com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersServerStreamingCallable;
import com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersUnaryCallable;
import com.google.cloud.bigtable.data.v2.stub.metrics.TracedBatcherUnaryCallable;
Expand All @@ -122,6 +126,7 @@
import com.google.cloud.bigtable.data.v2.stub.sql.SqlRowMergingCallable;
import com.google.cloud.bigtable.gaxx.retrying.ApiResultRetryAlgorithm;
import com.google.cloud.bigtable.gaxx.retrying.RetryInfoRetryAlgorithm;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Functions;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
Expand All @@ -130,6 +135,12 @@
import com.google.common.util.concurrent.MoreExecutors;
import com.google.protobuf.ByteString;
import io.grpc.MethodDescriptor;
import io.opencensus.stats.Stats;
import io.opencensus.stats.StatsRecorder;
import io.opencensus.tags.TagKey;
import io.opencensus.tags.TagValue;
import io.opencensus.tags.Tagger;
import io.opencensus.tags.Tags;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.common.Attributes;
import java.io.IOException;
Expand Down Expand Up @@ -215,11 +226,47 @@ public static BigtableClientContext createBigtableClientContext(
public static ApiTracerFactory createBigtableTracerFactory(
EnhancedBigtableStubSettings settings, @Nullable OpenTelemetry openTelemetry)
throws IOException {
return createBigtableTracerFactory(
settings, Tags.getTagger(), Stats.getStatsRecorder(), openTelemetry);
}

ImmutableList.Builder<ApiTracerFactory> tracerFactories = ImmutableList.builder();

tracerFactories.add(settings.getTracerFactory());
@VisibleForTesting
public static ApiTracerFactory createBigtableTracerFactory(
EnhancedBigtableStubSettings settings,
Tagger tagger,
StatsRecorder stats,
@Nullable OpenTelemetry openTelemetry)
throws IOException {
String projectId = settings.getProjectId();
String instanceId = settings.getInstanceId();
String appProfileId = settings.getAppProfileId();

ImmutableMap<TagKey, TagValue> attributes =
ImmutableMap.<TagKey, TagValue>builder()
.put(RpcMeasureConstants.BIGTABLE_PROJECT_ID, TagValue.create(projectId))
.put(RpcMeasureConstants.BIGTABLE_INSTANCE_ID, TagValue.create(instanceId))
.put(RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID, TagValue.create(appProfileId))
.build();

ImmutableList.Builder<ApiTracerFactory> tracerFactories = ImmutableList.builder();
tracerFactories
.add(
// Add OpenCensus Tracing
new OpencensusTracerFactory(
ImmutableMap.<String, String>builder()
// Annotate traces with the same tags as metrics
.put(RpcMeasureConstants.BIGTABLE_PROJECT_ID.getName(), projectId)
.put(RpcMeasureConstants.BIGTABLE_INSTANCE_ID.getName(), instanceId)
.put(RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID.getName(), appProfileId)
// Also annotate traces with library versions
.put("gax", GaxGrpcProperties.getGaxGrpcVersion())
.put("grpc", GaxGrpcProperties.getGrpcVersion())
.put("gapic", Version.VERSION)
.build()))
// Add OpenCensus Metrics
.add(MetricsTracerFactory.create(tagger, stats, attributes))
// Add user configured tracer
.add(settings.getTracerFactory());
BuiltinMetricsTracerFactory builtinMetricsTracerFactory =
openTelemetry != null
? BuiltinMetricsTracerFactory.create(openTelemetry, createBuiltinAttributes(settings))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
* This callable will
* <li>-Inject a {@link GrpcResponseMetadata} to access the headers returned by gRPC methods upon
* completion. The {@link BigtableTracer} will process metrics that were injected in the
* header/trailer and publish them. If {@link GrpcResponseMetadata#getMetadata()} returned null,
* it probably means that the request has never reached GFE, and it'll increment the
* gfe_header_missing_counter in this case.
* header/trailer and publish them to OpenCensus. If {@link GrpcResponseMetadata#getMetadata()}
* returned null, it probably means that the request has never reached GFE, and it'll increment
* the gfe_header_missing_counter in this case.
* <li>-This class will also access trailers from {@link GrpcResponseMetadata} to record zone and
* cluster ids.
* <li>-Call {@link BigtableTracer#onRequest(int)} to record the request events in a stream.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
* This callable will:
* <li>- Inject a {@link GrpcResponseMetadata} to access the headers returned by gRPC methods upon
* completion. The {@link BigtableTracer} will process metrics that were injected in the
* header/trailer and publish them. If {@link GrpcResponseMetadata#getMetadata()} returned null,
* it probably means that the request has never reached GFE, and it'll increment the
* gfe_header_missing_counter in this case.
* header/trailer and publish them to OpenCensus. If {@link GrpcResponseMetadata#getMetadata()}
* returned null, it probably means that the request has never reached GFE, and it'll increment
* the gfe_header_missing_counter in this case.
* <li>-This class will also access trailers from {@link GrpcResponseMetadata} to record zone and
* cluster ids.
* <li>-This class will also inject a {@link BigtableGrpcStreamTracer} that'll record the time an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ static TransportAttrs create(@Nullable String locality, @Nullable String backend

private TransportAttrs transportAttrs = null;

// Server histogram buckets use [start, end), however OpenTelemetry uses (start, end]. To work
// around this, we measure all the latencies in nanoseconds and convert them
// OpenCensus (and server) histogram buckets use [start, end), however OpenTelemetry uses (start,
// end]. To work around this, we measure all the latencies in nanoseconds and convert them
// to milliseconds and use DoubleHistogram. This should minimize the chance of a data
// point fall on the bucket boundary that causes off by one errors.
private final DoubleHistogram operationLatenciesHistogram;
Expand Down
Loading
Loading