DataDog / datadog-lambda-go

The Datadog AWS Lambda package for Go
Apache License 2.0
59 stars 40 forks source link

Not running handler #135

Closed pixie79 closed 1 year ago

pixie79 commented 1 year ago

I have the following code, which I can see is building and connects to Datadog but it seems to not execute anything in the myHandler function. I don't see the log entries appear in CloudWatch or the metric appear in DD.

Any ideas where I have gone wrong?

Goland is complaining that build constraints exclude all GO files, but it builds ok. I set go.mod to 1.18

package main

import (
    "context"
    "fmt"
    ddLambda "github.com/DataDog/datadog-lambda-go"
    "github.com/aws/aws-lambda-go/events"
    "github.com/aws/aws-lambda-go/lambda"
    log "github.com/sirupsen/logrus"
    "os"
)

func init() {
    log.SetFormatter(&log.JSONFormatter{
        PrettyPrint: false,
    })
}

func main() {
    // Start the lambda handler
    lambda.Start(ddLambda.WrapHandler(myHandler, nil))
}

func myHandler(ctx context.Context, event events.KafkaEvent) (string, error) {
    log.Info(fmt.Sprintf("Running Lambda against region: %s", getEnv("AWS_REGION", "eu-west-1")))
    lenEventRecords := len(event.Records)
    if lenEventRecords > 0 {
        log.Info(fmt.Sprintf("Kafka records recieved: %+v", lenEventRecords))
        for key, element := range event.Records {
            log.Info(fmt.Sprintf("%+v, %+v", key, element))
        }
        ddLambda.Metric(
            "redpanda.event_received",           // Metric name
            float64(lenEventRecords),            // Metric value
            "topic:test", "producer:producer_1", // Associated tags
        )
    }
    return "", nil
}

// GetEnv Simple helper function to read an environment or return a default value
func getEnv(key string, defaultVal string) string {
    if value, exists := os.LookupEnv(key); exists {
        return value
    }
    return defaultVal
}
astuyve commented 1 year ago

Hi @pixie79 - that code looks good at a glance, so my best guess is that there's an issue with the configuration in AWS Lambda like an API Key, DD_SITE/DD_ENV config, or maybe an issue with the datadog extension?

Do you think you could open a support ticket with us directly? That'll help us troubleshoot those other contributing factors which can't be handled in an open source github ticket.

Thanks!

pixie79 commented 1 year ago

issue was the handler needed to be called - bootstrap and the go needed to be compiled to a file called bootstrap as this is what the DD Handler is looking for it appears