Skip to content

Commit

Permalink
Unify check for APM enabled into a helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaBortoli committed Nov 27, 2024
1 parent da90b9a commit 481e0ea
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 1 addition & 3 deletions cmd/serverless/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions comp/trace/config/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 8 additions & 0 deletions pkg/config/utils/miscellaneous.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit 481e0ea

Please sign in to comment.