diff --git a/pkg/config/utils/miscellaneous.go b/pkg/config/utils/miscellaneous.go index faf3572d318d3..a1de732654318 100644 --- a/pkg/config/utils/miscellaneous.go +++ b/pkg/config/utils/miscellaneous.go @@ -54,6 +54,6 @@ func IsCoreAgentEnabled(cfg pkgconfigmodel.Reader) bool { // Error Tracking standalone only via the apm_config.error_tracking_standalone.enabled option instead of requiring // to enable also apm_config.enabled. func IsAPMEnabled(cfg pkgconfigmodel.Reader) bool { - return (cfg.GetBool("apm_config.enabled") && IsCoreAgentEnabled(cfg)) || + return cfg.GetBool("apm_config.enabled") || cfg.GetBool("apm_config.error_tracking_standalone.enabled") } diff --git a/pkg/config/utils/miscellaneous_test.go b/pkg/config/utils/miscellaneous_test.go index 96c65f5b33b9c..59ee253bcb09f 100644 --- a/pkg/config/utils/miscellaneous_test.go +++ b/pkg/config/utils/miscellaneous_test.go @@ -6,11 +6,12 @@ package utils import ( - "github.com/stretchr/testify/assert" "testing" configmock "github.com/DataDog/datadog-agent/pkg/config/mock" "github.com/DataDog/datadog-agent/pkg/config/model" + + "github.com/stretchr/testify/assert" ) func TestIsCoreAgentEnabled(t *testing.T) { @@ -64,3 +65,46 @@ func TestIsCoreAgentEnabled(t *testing.T) { }) } } + +func TestIsAPMEnabled(t *testing.T) { + tests := []struct { + name string + apmEnabled, errorTrackingEnable, expected bool + }{ + { + name: "APM enabled and Error Tracking standalone disabled", + apmEnabled: false, + errorTrackingEnable: false, + expected: false, + }, + { + name: "APM enabled and Error Tracking standalone disabled", + apmEnabled: true, + errorTrackingEnable: false, + expected: true, + }, + { + name: "APM disabled and Error Tracking standalone enabled", + apmEnabled: false, + errorTrackingEnable: true, + expected: true, + }, + { + name: "APM enabled and Error Tracking standalone enabled", + apmEnabled: true, + errorTrackingEnable: true, + expected: true, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + mockConfig := configmock.New(t) + mockConfig.SetWithoutSource("apm_config.enabled", test.apmEnabled) + mockConfig.SetWithoutSource("apm_config.error_tracking_standalone.enabled", test.errorTrackingEnable) + assert.Equal(t, + test.expected, IsAPMEnabled(mockConfig), + "Was expecting IsAPMEnabled to return", test.expected) + }) + } +}