@ -20,6 +20,9 @@
# include <unordered_map>
# include "absl/flags/flag.h"
# include "opentelemetry/exporters/prometheus/exporter_factory.h"
# include "opentelemetry/exporters/prometheus/exporter_options.h"
# include "opentelemetry/sdk/metrics/meter_provider.h"
# include <grpc/grpc.h>
# include <grpc/support/alloc.h>
@ -30,6 +33,7 @@
# include "src/core/lib/gpr/string.h"
# include "src/core/lib/gprpp/crash.h"
# include "src/cpp/ext/otel/otel_plugin.h"
# include "test/core/util/test_config.h"
# include "test/cpp/interop/client_helper.h"
# include "test/cpp/interop/interop_client.h"
@ -136,6 +140,8 @@ ABSL_FLAG(
" grpc-status and error message to the console, in a stable format. " ) ;
ABSL_FLAG ( bool , enable_observability , false ,
" Whether to enable GCP Observability " ) ;
ABSL_FLAG ( bool , enable_otel_plugin , false ,
" Whether to enable OpenTelemetry Plugin " ) ;
using grpc : : testing : : CreateChannelForTestCase ;
using grpc : : testing : : GetServiceAccountJsonKey ;
@ -214,6 +220,25 @@ int main(int argc, char** argv) {
}
}
// TODO(stanleycheung): switch to CsmObservabilityBuilder once xds setup is
// ready
if ( absl : : GetFlag ( FLAGS_enable_otel_plugin ) ) {
gpr_log ( GPR_DEBUG , " Registering Prometheus exporter " ) ;
opentelemetry : : exporter : : metrics : : PrometheusExporterOptions opts ;
// default was "localhost:9464" which causes connection issue across GKE
// pods
opts . url = " 0.0.0.0:9464 " ;
auto prometheus_exporter =
opentelemetry : : exporter : : metrics : : PrometheusExporterFactory : : Create (
opts ) ;
auto meter_provider =
std : : make_shared < opentelemetry : : sdk : : metrics : : MeterProvider > ( ) ;
meter_provider - > AddMetricReader ( std : : move ( prometheus_exporter ) ) ;
grpc : : internal : : OpenTelemetryPluginBuilder otel_builder ;
otel_builder . SetMeterProvider ( std : : move ( meter_provider ) ) ;
otel_builder . BuildAndRegisterGlobal ( ) ;
}
grpc : : testing : : ChannelCreationFunc channel_creation_func ;
std : : string test_case = absl : : GetFlag ( FLAGS_test_case ) ;
if ( absl : : GetFlag ( FLAGS_additional_metadata ) . empty ( ) ) {