OpenTelemetry Go AWS Lambda Instrumentation

otellambda instrumentation provides OpenTelemetry Go instrumentation for AWS Lambda.

AWS Lambda

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

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 uptrace-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's next?

Next, instrument more operations, for example, database queries, errors, and logs. You can also learn about OpenTelemetry Go Tracing API to create your own instrumentations.

Popular instrumentations:

Last Updated: