Monitor AWS Lambda Golang with OpenTelemetry

AWS Lambda is a serverless, event-driven compute service that lets you run code without provisioning or managing servers.

This article explains how you can monitor and optimize AWS Lambda Golang performance using OpenTelemetry observability framework.

What is OpenTelemetry?

OpenTelemetryopen in new window is an open source and vendor-neutral API for OpenTelemetry tracingopen in new window (including logs and errors) and OpenTelemetry metricsopen in new window.

Otel specifies how to collect and export telemetry data in a vendor agnostic way. With OpenTelemetry, you can instrument your application once and then add or change vendors without changing the instrumentation, for example, many open source tracing toolsopen in new window already support OpenTelemetry.

OpenTelemetry is available for most programming languages and provides interoperability across different languages and environments.

AWS Lambda containers

Lambda runs the code in isolated containers dynamically scaling the number of containers as needed. When there are no new requests, Lambda freezes idle containers.

When the container is frozen, all processes in the container will be frozen as well. If the process uses a timer to flush the buffered data, the timer won’t fire until the container thaws. The interval between the frozen and the thaw state is unpredictable, ranging from seconds to hours.

To mitigate that problem, the instrumentation has to flush data out before the Lambda function returns.


To install OpenTelemetry AWS Lambda instrumentation:

go get -u


You can instrument your AWS Lambda function with OpenTelemetry like this:

import ""

func main() {

To use otellambda with OpenTelemetry Goopen in new window, you need to configure otellambda.WithFlusher with the tracer provider used by Uptrace.

import (

func main() {
	ctx := context.Background()

		// copy your project DSN here or use UPTRACE_DSN env var

	defer uptrace.Shutdown(ctx)

	tp := uptrace.TracerProvider()
		// Flush buffered spans to Uptrace.

See aws-lambdaopen in new window example for details.

OpenTelemetry Lambda

Alternatively, you can add opentelemetry-lambdaopen in new window as a Lambda layer, but it does not offer any advantages at the moment. See exampleopen in new window for details.

What is Uptrace?

Uptrace is an open source APMopen in new window for OpenTelemetry with an intuitive query builder, rich dashboards, automatic alerts, and integrations for most languages and frameworks.

You can get startedopen in new window with Uptrace by downloading a DEB/RPM package or a pre-compiled Go binary.

What's next?

Next, instrumentopen in new window more operations, for example, database queries, errors, and logs. You can also learn about OpenTelemetry Go Tracing APIopen in new window to create your own instrumentations.

Popular instrumentations:

Last Updated: