Skip to content

Commit

Permalink
observability: replace current OpenCensus registerAllGrpcViews with o…
Browse files Browse the repository at this point in the history
…nly selected views for GCP observability (#9561)
  • Loading branch information
sanjaypujare authored Sep 23, 2022
1 parent 2289956 commit 0cda133
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@
import io.grpc.gcp.observability.logging.Sink;
import io.grpc.internal.TimeProvider;
import io.opencensus.common.Duration;
import io.opencensus.contrib.grpc.metrics.RpcViews;
import io.opencensus.contrib.grpc.metrics.RpcViewConstants;
import io.opencensus.exporter.stats.stackdriver.StackdriverStatsConfiguration;
import io.opencensus.exporter.stats.stackdriver.StackdriverStatsExporter;
import io.opencensus.exporter.trace.stackdriver.StackdriverTraceConfiguration;
import io.opencensus.exporter.trace.stackdriver.StackdriverTraceExporter;
import io.opencensus.metrics.LabelKey;
import io.opencensus.metrics.LabelValue;
import io.opencensus.stats.Stats;
import io.opencensus.stats.ViewManager;
import io.opencensus.trace.AttributeValue;
import io.opencensus.trace.Tracing;
import io.opencensus.trace.config.TraceConfig;
Expand Down Expand Up @@ -145,11 +147,23 @@ static ConditionalClientInterceptor getConditionalInterceptor(ClientInterceptor
(m, c) -> !SERVICES_TO_EXCLUDE.contains(m.getServiceName()));
}

private static void registerObservabilityViews() {
ViewManager viewManager = Stats.getViewManager();

// client views
viewManager.registerView(RpcViewConstants.GRPC_CLIENT_COMPLETED_RPC_VIEW);
viewManager.registerView(RpcViewConstants.GRPC_CLIENT_STARTED_RPC_VIEW);

// server views
viewManager.registerView(RpcViewConstants.GRPC_SERVER_COMPLETED_RPC_VIEW);
viewManager.registerView(RpcViewConstants.GRPC_SERVER_STARTED_RPC_VIEW);
}

@VisibleForTesting
void registerStackDriverExporter(String projectId, Map<String, String> customTags)
throws IOException {
if (config.isEnableCloudMonitoring()) {
RpcViews.registerAllGrpcViews();
registerObservabilityViews();
StackdriverStatsConfiguration.Builder statsConfigurationBuilder =
StackdriverStatsConfiguration.builder();
if (projectId != null) {
Expand Down

0 comments on commit 0cda133

Please sign in to comment.