GCP Observability: Disable OpenCensus Stats/Tracing if the config doesn't enable them (#31253)

This commit is contained in:
Yash Tibrewal 2022-10-05 15:35:06 -07:00 committed by GitHub
parent a310ceebf9
commit a10a591612
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions

View File

@ -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