How To Get Lightning Fast Observability For Go On AWS Lambda

Achieving Observability in Go

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.

Word Image 362

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.

Word Image 363

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.

The first time I wrote a Go Lambda function, I had utterly failed to RTFM inexplicably missed the fact that lambda.Start() would never return. I actually had expected the Go binary to be invoked separately for every request, and that lambda.Start() would terminate after one request was served, and got very surprised when some debugging statements placed after the lambda.Start() never seemed to get triggered (specifically, some code to measure the overall execution time of Handle() ).

Play with Instana’s APM Observability Sandbox

Announcement, Product
This blog post was originally published by IBM What is IBM Observability by Instana? IBM Observability by Instana provides businesses with advanced application performance monitoring and observability capabilities, manages the performance of...
|
Product, Thought Leadership
It’s just been a few months since IBM acquired Instana, but we’ve been working hard to make the world of AIOps and Observability a better place. Recently, the two sides of the...
|
Featured, Thought Leadership
The Muddy Messaging of Observability and Application Performance Management Here's a question I get asked quite a bit: “How is Enterprise Observability different from APM and/or just plain Observability?” It’s a reasonable...
|

Start your FREE TRIAL today!

Instana, an IBM company, provides an Enterprise Observability Platform with automated application monitoring capabilities to businesses operating complex, modern, cloud-native applications no matter where they reside – on-premises or in public and private clouds, including mobile devices or IBM Z.

Control hybrid modern applications with Instana’s AI-powered discovery of deep contextual dependencies inside hybrid applications. Instana also gives visibility into development pipelines to help enable closed-loop DevOps automation.

This provides actionable feedback needed for clients as they to optimize application performance, enable innovation and mitigate risk, helping Dev+Ops add value and efficiency to software delivery pipelines while meeting their service and business level objectives.

For further information, please visit instana.com.