Repository: newrelic/newrelic-ruby-agent (Ruby)

Issue:
Hybrid Agent: Add Supportability metric
Generate the following Supportability metric when the OpenTelemetryBridge initializes: 
`Supportability/Tracing/{language}/OpenTelemetryBridge/{enabled|disabled}` (If the feature is enabled/disabled)



Discussion:
https://new-relic.atlassian.net/browse/NR-471802



Patch:
diff --git a/lib/new_relic/agent/configuration/default_source.rb b/lib/new_relic/agent/configuration/default_source.rb
index 5503e78408..4c39e7b9ea 100644
--- a/lib/new_relic/agent/configuration/default_source.rb
+++ b/lib/new_relic/agent/configuration/default_source.rb
@@ -2556,8 +2556,14 @@ def self.convert_to_constant_list(raw_value)
           :allowed_from_server => true,
           :description => 'Number of seconds betwixt connections to the New Relic span event collection services.'
         },
-        # TODO: Sync with the other agents to see what the config should be named, how it should be enabled, how it should be described
         :'opentelemetry.enabled' => {
+          :default => false,
+          :public => false,
+          :type => Boolean,
+          :allowed_from_server => false,
+          :description => 'A global configuration option for disabling all OpenTelemetry signals sent through New Relic. If false, no OpenTelemetry signals will be sent to New Relic. If true, the signal-specific enabled config option (e.g. opentelemetry.traces.enabled) determines whether telemetry of that signal type will be reported to New Relic.'
+        },
+        :'opentelemetry.traces.enabled' => {
           :default => false,
           :public => false,
           :type => Boolean,
diff --git a/lib/new_relic/agent/opentelemetry_bridge.rb b/lib/new_relic/agent/opentelemetry_bridge.rb
index b18d5cd2a6..7b1632bddd 100644
--- a/lib/new_relic/agent/opentelemetry_bridge.rb
+++ b/lib/new_relic/agent/opentelemetry_bridge.rb
@@ -6,11 +6,14 @@ module NewRelic
   module Agent
     class OpenTelemetryBridge
       def initialize
-        # no-op without OpenTelemetry API & config
-        return unless defined?(OpenTelemetry) &&
-          NewRelic::Agent.config[:'opentelemetry.enabled']
-
-        OpenTelemetryBridge.install
+        # currently, we only have support for traces
+        # this method should change when we add support for metrics and logs.
+        if defined?(OpenTelemetry) && Agent.config[:'opentelemetry.enabled'] && Agent.config[:'opentelemetry.traces.enabled']
+          OpenTelemetryBridge.install
+          NewRelic::Agent.record_metric('Supportability/Tracing/Ruby/OpenTelemetryBridge/enabled', 0.0)
+        else
+          NewRelic::Agent.record_metric('Supportability/Tracing/Ruby/OpenTelemetryBridge/disabled', 0.0)
+        end
       end
 
       private


Test patch:
diff --git a/test/multiverse/suites/hybrid_agent/config/newrelic.yml b/test/multiverse/suites/hybrid_agent/config/newrelic.yml
index 2ea3d6d190..bbad9321f4 100644
--- a/test/multiverse/suites/hybrid_agent/config/newrelic.yml
+++ b/test/multiverse/suites/hybrid_agent/config/newrelic.yml
@@ -15,4 +15,6 @@ development:
     stack_trace_threshold: 0.5
     transaction_threshold: 1.0
   capture_params: false
-  opentelemetry.enabled: true
+  opentelemetry:
+    enabled: true
+    traces.enabled: true
diff --git a/test/new_relic/agent/opentelemetry_bridge_test.rb b/test/new_relic/agent/opentelemetry_bridge_test.rb
index 0158fced88..5bcabc5e56 100644
--- a/test/new_relic/agent/opentelemetry_bridge_test.rb
+++ b/test/new_relic/agent/opentelemetry_bridge_test.rb
@@ -10,29 +10,71 @@ module Agent
     class OpenTelemetryBridgeTest < Minitest::Test
       class BridgeInstallationError < StandardError; end
 
+      def setup
+        @config = {
+          :'opentelemetry.enabled' => true,
+          :'opentelemetry.traces.enabled' => true
+        }
+        NewRelic::Agent.config.add_config_for_testing(@config)
+      end
+
+      def teardown
+        NewRelic::Agent.config.reset_to_defaults
+      end
+
       def test_does_not_run_requires_without_opentelemetry_api_gem
-        with_config(:'opentelemetry.enabled' => true) do
-          assert NewRelic::Agent::OpenTelemetryBridge.new
+        assert NewRelic::Agent::OpenTelemetryBridge.new
+      end
+
+      def test_does_not_install_if_overall_flag_off_but_traces_on
+        with_config(:'opentelemetry.enabled' => false, :'opentelemetry.traces.enabled' => true) do
+          NewRelic::Agent::OpenTelemetryBridge.stub(:install, -> { raise BridgeInstallationError.new }) do
+            refute_raises(BridgeInstallationError) { NewRelic::Agent::OpenTelemetryBridge.new }
+          end
+        end
+      end
+
+      def test_does_not_install_if_overall_flag_on_but_traces_off
+        with_config(:'opentelemetry.enabled' => true, :'opentelemetry.traces.enabled' => false) do
+          NewRelic::Agent::OpenTelemetryBridge.stub(:install, -> { raise BridgeInstallationError.new }) do
+            refute_raises(BridgeInstallationError) { NewRelic::Agent::OpenTelemetryBridge.new }
+          end
         end
       end
 
       def test_does_not_run_requires_without_config
         with_config(:'opentelemetry.enabled' => false) do
-          Object.stub_const(:OpenTelemetry, nil) do
+          Object.stub_const(:OpenTelemetry, nil) do # pretend like the opentelemetry-api gem is installed
             assert NewRelic::Agent::OpenTelemetryBridge.new
           end
         end
       end
 
       def test_installs_bridge_when_configured
-        with_config(:'opentelemetry.enabled' => true) do
-          Object.stub_const(:OpenTelemetry, nil) do
-            NewRelic::Agent::OpenTelemetryBridge.stub(:install, -> { raise BridgeInstallationError.new }) do
-              assert_raises(BridgeInstallationError) { NewRelic::Agent::OpenTelemetryBridge.new }
-            end
+        Object.stub_const(:OpenTelemetry, nil) do # pretend like the opentelemetry-api gem is installed
+          NewRelic::Agent::OpenTelemetryBridge.stub(:install, -> { raise BridgeInstallationError.new }) do
+            assert_raises(BridgeInstallationError) { NewRelic::Agent::OpenTelemetryBridge.new }
           end
         end
       end
+
+      def test_adds_supportability_metric_when_opentelemetry_enabled
+        Object.stub_const(:OpenTelemetry, nil) do # pretend like the opentelemetry-api gem is installed
+          NewRelic::Agent::OpenTelemetryBridge.stub(:install, -> { nil }) do
+            NewRelic::Agent::OpenTelemetryBridge.new
+
+            assert_metrics_recorded('Supportability/Tracing/Ruby/OpenTelemetryBridge/enabled')
+          end
+        end
+      end
+
+      def test_adds_supportability_metric_when_opentelemetry_disabled
+        with_config(:'opentelemetry.enabled' => false) do
+          NewRelic::Agent::OpenTelemetryBridge.new
+
+          assert_metrics_recorded('Supportability/Tracing/Ruby/OpenTelemetryBridge/disabled')
+        end
+      end
     end
   end
 end