From a10a591612731c201a303982674a875761552ab4 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Wed, 5 Oct 2022 15:35:06 -0700 Subject: [PATCH] GCP Observability: Disable OpenCensus Stats/Tracing if the config doesn't enable them (#31253) --- src/cpp/ext/gcp/observability.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/cpp/ext/gcp/observability.cc b/src/cpp/ext/gcp/observability.cc index df3d8858e90..14f2d789e55 100644 --- a/src/cpp/ext/gcp/observability.cc +++ b/src/cpp/ext/gcp/observability.cc @@ -74,6 +74,10 @@ absl::Status GcpObservabilityInit() { if (!config.ok()) { return config.status(); } + if (!config->cloud_trace.has_value() && + !config->cloud_monitoring.has_value()) { + return absl::OkStatus(); + } grpc::RegisterOpenCensusPlugin(); RegisterOpenCensusViewsForGcpObservability(); ChannelArguments args; @@ -91,6 +95,9 @@ absl::Status GcpObservabilityInit() { GoogleDefaultCredentials(), args)); opencensus::exporters::trace::StackdriverExporter::Register( std::move(trace_opts)); + } else { + // Disable OpenCensus tracing + EnableOpenCensusTracing(false); } if (config->cloud_monitoring.has_value()) { opencensus::exporters::stats::StackdriverOptions stats_opts; @@ -100,8 +107,11 @@ absl::Status GcpObservabilityInit() { kGoogleStackdriverStatsAddress, GoogleDefaultCredentials(), args)); opencensus::exporters::stats::StackdriverExporter::Register( std::move(stats_opts)); + } else { + // Disable OpenCensus stats + EnableOpenCensusStats(false); } - return absl::Status(); + return absl::OkStatus(); } } // namespace experimental