AWS Lambda supports development and deployment of functions in a variety of programming languages including Node.js, Go, Java, and Python.
Instana has previously announced automated tracing of AWS Lambda Functions for Node.js and Python. We are now extending our best-in-class Lambda distributed tracing to Go and Java.
The simplest Go Lambda function
A barebones AWS Lambda function written in Go looks as follows:
package main import ( "github.com/aws/aws-lambda-go/lambda" ) func main() { lambda.Start(Handle) } func Handle() (string, error) { // handler code }
The logic of your function goes in the Handle()
method. You may rename the Handle()
method to whatever suits you, as long as its signature satisfies a number of constraints involving parameters and return types.
After you have coded your Handle()
function, one compilation and one deployment later, your function is good to serve load.
The Go runtime for AWS Lambda is a peculiar one
Presumably due to the compile nature of Go applications, the AWS Lambda runtime for Go does not have as much in terms of extensibility as its siblings. For example, as of November 26th, 2020, the Go runtime for AWS Lambda does not support the Extension API.
Indeed, some of the logic that in other Lambda runtimes is outside your function code. In other runtimes, like Java or Python, your application will often receive requests and events using an HTTP server that is independent from the runtime. With Go, your function polls the Runtime API for requests and events as of the lambda.Start()
or lambda.StartHandler()
call, which sets up for you a loop that fetches new requests to serve from the surrounding runtime. Indeed, the design of the lambda.Start()
facility is similar to the net/http HTTP server, in that you effectively register the Handle()
callback via the lambda.Start()
method. A side-effect of lambda.Start()
acting as a sort of pull loop, is that the invocation of lambda.Start()
is blocking and does not return.[1]
Automated Distributed Tracing of Go Lambda Functions with Instana
Adding Instana tracing is equally simple. Using the wrapper-based approach that we apply to all our Go instrumentations (and that is discussed in depth in the awesome Achieving Observability in Go post), all it takes is adding two imports, one line more of code and a wrapper around the Handle()
function:
package main import ( "github.com/aws/aws-lambda-go/lambda" instana "github.com/instana/go-sensor" "github.com/instana/go-sensor/instrumentation/instalambda" ) func main() { // Initialize the instana.Sensor instance sensor := instana.NewSensor() // Pass the handler to the lambda.StartHandler() invoke loop lambda.StartHandler(instalambda.NewHandler(Handle, sensor)) } func Handle() (string, error) { // handler code }
Due to the compile nature of Go, and unlike the other Lambda runtimes we support, we do not offer a Lambda layer, as our wrapper will take care of everything. After adding the handler, the only thing you need to add to your Lambda function configuration are the two usual environment variables INSTANA_ENDPOINT_URL and INSTANA_AGENT_KEY that tell the instrumentation where to find the Instana backend and the agent key for authentication, respectively.
Understand Every Dependency Across Every Platform with Trace Continuity
Simply apply the instrumentation and it automatically traces every distributed request flowing through Lambda. This happens in a way that is entirely compatible with other systems traced by Instana making it easy to visualize every trace and every function. Doing so enables developers to immediately understand what went wrong, where it went wrong, and, most importantly, how to fix it. Instana’s Application and Service dependency map highlights what the actual architecture is at any given point in time, even as services and functions scale up and down.
Instana ensures all of your services, applications, and databases are automatically discovered and each request is traced no matter where or how they run. This enables developers with access to every request into Lambda functions and out into their services whether those services are running on-prem, in another cloud provider, or any other SaaS offering. By capturing all the distributed traces and contextual information Instana ensures you always have immediate access to the exact trace you need, when you need it.
Start optimizing your Lambda applications today
Instana’s best-in-class Go tracing is available today for your AWS Lambda functions. As with all technologies Instana monitors, it is blazing fast, entirely interoperable with everything else you monitor with Instana, and incredibly easy to configure in your environments.
Give yourself and your functions a boon and monitor your applications on AWS Lambda today. And if you do not have Instana just yet, a free trial of Instana, no string attached, is just a click away.