From 481e0ea88119ef51284a71a3b1c70eb01d08e425 Mon Sep 17 00:00:00 2001 From: Gianluca Bortoli Date: Wed, 27 Nov 2024 18:10:16 +0100 Subject: [PATCH] Unify check for APM enabled into a helper function --- cmd/serverless/main.go | 4 +--- comp/trace/config/setup.go | 4 +--- pkg/config/utils/miscellaneous.go | 8 ++++++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cmd/serverless/main.go b/cmd/serverless/main.go index 4386909207c16..77f46c01fded4 100644 --- a/cmd/serverless/main.go +++ b/cmd/serverless/main.go @@ -344,10 +344,8 @@ func startOtlpAgent(wg *sync.WaitGroup, metricAgent *metrics.ServerlessMetricAge func startTraceAgent(wg *sync.WaitGroup, lambdaSpanChan chan *pb.Span, coldStartSpanId uint64, serverlessDaemon *daemon.Daemon, tagger tagger.Component, rcService *remoteconfig.CoreAgentService) { defer wg.Done() - apmEnabled := (pkgconfigsetup.Datadog().GetBool("apm_config.enabled") && configUtils.IsCoreAgentEnabled(pkgconfigsetup.Datadog())) || - pkgconfigsetup.Datadog().GetBool("apm_config.error_tracking_standalone.enabled") traceAgent := trace.StartServerlessTraceAgent(trace.StartServerlessTraceAgentArgs{ - Enabled: apmEnabled, + Enabled: configUtils.IsAPMEnabled(pkgconfigsetup.Datadog()), LoadConfig: &trace.LoadConfig{Path: datadogConfigPath, Tagger: tagger}, LambdaSpanChan: lambdaSpanChan, ColdStartSpanID: coldStartSpanId, diff --git a/comp/trace/config/setup.go b/comp/trace/config/setup.go index b5ef44c1b5571..c095990736ceb 100644 --- a/comp/trace/config/setup.go +++ b/comp/trace/config/setup.go @@ -194,9 +194,7 @@ func applyDatadogConfig(c *config.AgentConfig, core corecompcfg.Component) error c.SkipSSLValidation = core.GetBool("skip_ssl_validation") } if core.IsSet("apm_config.enabled") { - isAPMEnabled := (core.GetBool("apm_config.enabled") && utils.IsCoreAgentEnabled(core)) || - core.GetBool("apm_config.error_tracking_standalone.enabled") - c.Enabled = isAPMEnabled + c.Enabled = utils.IsAPMEnabled(core) } if pkgconfigsetup.Datadog().IsSet("apm_config.log_file") { c.LogFilePath = pkgconfigsetup.Datadog().GetString("apm_config.log_file") diff --git a/pkg/config/utils/miscellaneous.go b/pkg/config/utils/miscellaneous.go index 807165c7c7417..faf3572d318d3 100644 --- a/pkg/config/utils/miscellaneous.go +++ b/pkg/config/utils/miscellaneous.go @@ -49,3 +49,11 @@ func IsCoreAgentEnabled(cfg pkgconfigmodel.Reader) bool { return true } + +// IsAPMEnabled checks if APM is enabled or if Error Tracking standalone is enabled, simplifying the setup for +// 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)) || + cfg.GetBool("apm_config.error_tracking_standalone.enabled") +}