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.

You can use OpenTelemetry with AWS Lambda to enable distributed tracing and observability for serverless applications.

What is OpenTelemetry?

OpenTelemetryopen in new window defines APIs and protocols for collecting telemetry data such as metrics, traces, and logs, and provides a variety of libraries, agents, and integrations for popular programming languages and technologies.

OpenTelemetry is an open and vendor-neutral solution that provides a unified approach to observability, making it easier for organizations to manage the complexity of their cloud-native infrastructure. It enables organizations to collect telemetry from their applications and send it to a variety of of distributed tracing toolsopen in new window.

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 Go, 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 the exampleopen in new window for details.

What is Uptrace?

Uptrace is a DataDog alternativeopen in new window that supports distributed tracing, metrics, and logs. You can use it to monitor applications and troubleshoot issues.

Uptrace Overview

Uptrace comes with an intuitive query builder, rich dashboards, alerting rules with notifications, and integrations for most languages and frameworks.

Uptrace can process billions of spans and metrics on a single server and allows you to monitor your applications at 10x lower cost.

In just a few minutes, you can try Uptrace by visiting the cloud demoopen in new window (no login required) or running it locally with Dockeropen in new window. The source code is available on GitHubopen in new window.

What's next?

Next, instrument more operations to get a more detailed picture. Try to prioritize network calls, disk operations, database queries, error and logs.

You can also create your own instrumentations using OpenTelemetry Go Tracing APIopen in new window.

Last Updated: