Instrumenting Go Applications
New announcements from Dash: Incident Management, Continuous Profiler, and more! New announcements from Dash!

Instrumenting Go Applications

After you have installed the AWS integration and the Datadog Forwarder, follow the steps below to instrument your application to send metrics, logs, and traces to Datadog.


Install the Datadog Lambda Library

You can install the Datadog Lambda Library locally by running the following command:

go get

Configure the Function

  1. Set environment variable DD_FLUSH_TO_LOG to true.
  2. Enable AWS X-Ray active tracing for your Lambda function.

Subscribe the Datadog Forwarder to the Log Groups

You need to subscribe the Datadog Forwarder Lambda function to each of your function’s log groups, in order to send metrics, traces and logs to Datadog.

  1. Install the Datadog Forwarder if you haven’t.
  2. Ensure the option DdFetchLambdaTags is enabled.
  3. Subscribe the Datadog Forwarder to your function’s log groups.

Explore Datadog Serverless Monitoring

After you have configured your function following the steps above, you should be able to view metrics, logs and traces on the Serverless Homepage.

If you would like to submit a custom metric, see the sample code below:

package main

import (

func main() {
  // Wrap your handler function
  lambda.Start(ddlambda.WrapHandler(myHandler, nil))

func myHandler(ctx context.Context, event MyEvent) (string, error) {
  // Submit a custom metric
    "coffee_house.order_value", // Metric name
    12.45, // Metric value
    "product:latte", "order:online" // Associated tags

  req, err := http.NewRequest("GET", "")

  // Add the datadog distributed tracing headers
  ddlambda.AddTraceHeaders(ctx, req)

  client := http.Client{}