Skip to content

Do not show error messages even if neither DD_API_KEY nor DD_KMS_API_KEY is set when Lambda Extension is running #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions ddlambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,17 @@ func initializeListeners(cfg *Config) []wrapper.HandlerListener {
logger.SetLogLevel(logger.LevelDebug)
}
extensionManager := extension.BuildExtensionManager()
isExtensionRunning := extensionManager.IsExtensionRunning()

// Wrap the handler with listeners that add instrumentation for traces and metrics.
tl := trace.MakeListener(cfg.toTraceConfig(), extensionManager)
ml := metrics.MakeListener(cfg.toMetricsConfig(), extensionManager)
ml := metrics.MakeListener(cfg.toMetricsConfig(isExtensionRunning), extensionManager)
return []wrapper.HandlerListener{
&tl, &ml,
}
}

func (cfg *Config) toMetricsConfig() metrics.Config {
func (cfg *Config) toMetricsConfig(isExtensionRunning bool) metrics.Config {

mc := metrics.Config{
ShouldRetryOnFailure: false,
Expand Down Expand Up @@ -263,8 +264,10 @@ func (cfg *Config) toMetricsConfig() metrics.Config {
if mc.KMSAPIKey == "" {
mc.KMSAPIKey = os.Getenv(DatadogKMSAPIKeyEnvVar)
}
if mc.APIKey == "" && mc.KMSAPIKey == "" && !mc.ShouldUseLogForwarder {
logger.Error(fmt.Errorf("couldn't read DD_API_KEY or DD_KMS_API_KEY from environment"))
if !isExtensionRunning && mc.APIKey == "" && mc.KMSAPIKey == "" && !mc.ShouldUseLogForwarder {
logger.Error(fmt.Errorf(
"couldn't read %s or %s from environment", DatadogAPIKeyEnvVar, DatadogKMSAPIKeyEnvVar,
))
}

enhancedMetrics := os.Getenv("DD_ENHANCED_METRICS")
Expand Down
7 changes: 6 additions & 1 deletion internal/metrics/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,14 @@ func MakeListener(config Config, extensionManager *extension.ExtensionManager) L
}
}

// canSendMetrics reports whether l can send metrics.
func (l *Listener) canSendMetrics() bool {
return l.isAgentRunning || l.apiClient.apiKey != "" || l.config.KMSAPIKey != "" || l.config.ShouldUseLogForwarder
}

// HandlerStarted adds metrics service to the context
func (l *Listener) HandlerStarted(ctx context.Context, msg json.RawMessage) context.Context {
if l.apiClient.apiKey == "" && l.config.KMSAPIKey == "" && !l.config.ShouldUseLogForwarder {
if !l.canSendMetrics() {
logger.Error(fmt.Errorf("datadog api key isn't set, won't be able to send metrics"))
}

Expand Down