@@ -289,15 +289,11 @@ MonitoredResourceResult MakeMonitoredResource(
289289 return MonitoredResourceResult{std::move (project_id), std::move (resource)};
290290}
291291
292- void EnableGrpcMetrics (
292+ GrpcMetricsPluginConfig MakeGrpcMetricsPluginConfig (
293+ // NOLINTNEXTLINE(performance-unnecessary-value-param)
294+ opentelemetry::sdk::resource::Resource detected_resource,
293295 std::shared_ptr<monitoring_v3::MetricServiceConnection> const & conn,
294296 Options const & options, std::string const & client_uid) {
295- auto authority = options.get <AuthorityOption>();
296- if (!GrpcMetricsExporterRegistry::Singleton ().Register (authority)) return ;
297-
298- auto detector = otel::MakeResourceDetector ();
299- auto detected_resource = detector->Detect ();
300-
301297 auto dynamic_resource_fn =
302298 [options, client_uid, detected_resource = std::move (detected_resource)](
303299 opentelemetry::sdk::metrics::PointDataAttributes const & pda) {
@@ -357,7 +353,7 @@ void EnableGrpcMetrics(
357353 auto provider =
358354 MakeGrpcMeterProvider (std::move (exporter), std::move (reader_options));
359355
360- auto const metrics = std::vector<std::string_view>{
356+ auto metrics = std::vector<std::string_view>{
361357 std::string_view{" grpc.client.attempt.duration" },
362358 std::string_view{" grpc.lb.rls.default_target_picks" },
363359 std::string_view{" grpc.lb.rls.target_picks" },
@@ -370,13 +366,14 @@ void EnableGrpcMetrics(
370366 std::string_view{" grpc.subchannel.open_connections" },
371367 };
372368
373- auto const disable_metrics = std::vector<std::string_view>{
369+ auto disable_metrics = std::vector<std::string_view>{
374370 std::string_view{
375371 " grpc.client.attempt.sent_total_compressed_message_size" },
376372 std::string_view{
377373 " grpc.client.attempt.rcvd_total_compressed_message_size" },
378374 };
379375
376+ auto authority = options.get <AuthorityOption>();
380377 auto scope_filter =
381378 [authority = std::move (authority)](
382379 grpc::OpenTelemetryPluginBuilder::ChannelScope const & scope) {
@@ -386,15 +383,41 @@ void EnableGrpcMetrics(
386383 << " vs expected authority=" << authority;
387384 return scope.default_authority () == authority;
388385 };
386+
387+ auto generic_method_filter = [](std::string_view target) {
388+ return absl::StartsWith (target, " google.bigtable.v2" );
389+ };
390+
391+ return GrpcMetricsPluginConfig{
392+ std::move (provider), std::move (metrics),
393+ std::move (disable_metrics), std::move (generic_method_filter),
394+ std::move (scope_filter),
395+ };
396+ }
397+
398+ GrpcMetricsPluginConfig MakeGrpcMetricsPluginConfig (
399+ std::shared_ptr<monitoring_v3::MetricServiceConnection> const & conn,
400+ Options const & options, std::string const & client_uid) {
401+ auto detector = otel::MakeResourceDetector ();
402+ return MakeGrpcMetricsPluginConfig (detector->Detect (), conn, options,
403+ client_uid);
404+ }
405+
406+ void EnableGrpcMetrics (
407+ std::shared_ptr<monitoring_v3::MetricServiceConnection> const & conn,
408+ Options const & options, std::string const & client_uid) {
409+ auto const & authority = options.get <AuthorityOption>();
410+ if (!GrpcMetricsExporterRegistry::Singleton ().Register (authority)) return ;
411+
412+ auto config = MakeGrpcMetricsPluginConfig (conn, options, client_uid);
389413 auto status =
390414 grpc::OpenTelemetryPluginBuilder ()
391- .SetMeterProvider (provider)
392- .EnableMetrics (metrics)
393- .DisableMetrics (disable_metrics)
394- .SetGenericMethodAttributeFilter ([](std::string_view target) {
395- return absl::StartsWith (target, " google.bigtable.v2" );
396- })
397- .SetChannelScopeFilter (std::move (scope_filter))
415+ .SetMeterProvider (config.meter_provider )
416+ .EnableMetrics (config.enabled_metrics )
417+ .DisableMetrics (config.disabled_metrics )
418+ .SetGenericMethodAttributeFilter (
419+ std::move (config.generic_method_filter ))
420+ .SetChannelScopeFilter (std::move (config.channel_scope_filter ))
398421 .BuildAndRegisterGlobal ();
399422 if (!status.ok ()) {
400423 GCP_LOG (ERROR ) << " Cannot register provider status=" << status.ToString ();
0 commit comments