The Service Map for APM is here!

AWS Lambda

Crawler Crawler

Overview

Amazon Lambda is a compute service that runs code in response to events and automatically manages the compute resources required by that code.

Enable this integration to begin collecting Cloudwatch and custom metrics from your Lambda functions.

Setup

Installation

If you haven’t already, set up the Amazon Web Services integration first.

Metric collection

  1. In the AWS integration tile, ensure that Lambda is checked under metric collection.

  2. Add the following permissions to your Datadog IAM policy to collect Amazon Lambda metrics. For more information on Lambda policies, review the documentation on the AWS website.

    AWS Permission Description
    lambda:List* List Lambda functions, metadata, and tags.
    logs:DescribeLogGroups List available log groups.
    logs:DescribeLogStreams List available log streams for a group.
    logs:FilterLogEvents Fetch specific log events for a stream to generate metrics.
    tag:GetResources Get custom tags applied to Lambda functions.
  3. Install the Datadog - AWS Lambda integration.

Once this is completed, view all of your Lambda Functions in the Datadog Cloud Functions UI. This UI brings together metrics, traces, and logs from your AWS Lambda functions running serverless applications into one view. Detailed documentation on this feature can be found in the Datadog Cloud functions documentation.

Log collection

  1. Set up the Datadog log collection AWS Lambda function if you haven’t already.
  2. Once the Lambda function is installed, there are two ways to forward your Lambda logs to Datadog:

Once done, go to your Datadog Log section to start exploring your logs.

Trace collection

Datadog integrates with AWS X-Ray to collect and visualize your serverless traces from Lambda based applications in the Cloud Functions UI. Detailed documentation for setting up this integration can be found in the Datadog Cloud functions documentation.

Custom metrics

If your Lambda function is using a Python runtime, install the Datadog Lambda Layer to collect and send custom metrics. If you are using another runtime, log your custom metrics in a specific format to be picked up and parsed into metrics by Datadog.

Installing and using the Datadog Layer

Datadog’s Lambda Layer currently supports Python version 2.7, 3.6, and 3.7. If there is a runtime you would like Datadog to support reach out to the Datadog support team.

  1. Navigate to the Lambda function to which you want to add the Layer in your AWS console.
  2. Click on Layers on the main page of your function. 3 Scroll down, and click on Provide a layer version ARN.
  3. Enter an ARN in the following format, providing your desired region and Python version:

    arn:aws:lambda:<YOUR_AWS_REGION>:464622532012:layer:Datadog-Python36-metric:1
    
  4. Navigate to the Environment Variables section of your function and set two environment variables:

    • DATADOG_API_KEY
    • DATADOG_APP_KEY

Find these values from the API page within the Datadog Application.

In your function code, you must import the necessary methods from the layer and add a wrapper around your function handler:

from datadog import datadog_lambda_wrapper, lambda_metric

@datadog_lambda_wrapper
def lambda_handler(event, context):

Now, use the lambda_metric method to send custom metrics from your function to Datadog:

lambda_metric(metric_name, metric_value, tags=[])

Where:

  • <metric_name> uniquely identifies your metric and adheres to the metric naming policy.

  • <metric_value> MUST be a number (i.e. integer or float).

  • <tag_list> is optional and formatted, for example: ['owner:Datadog', 'env:demo', 'cooltag'].

Note: There is currently a max of 4 tags that can be applied to a metric. If you need more than 4 tags on these metrics, contact the Datadog support team to have this limit raised for your organization.

Detailed instructions for installing and configuring Lambda Layers can be found in the AWS main documentation.

Using CloudWatch Logs

To send custom metrics to Datadog from your Lambda logs, print a log line from your Lambda, using the following format:

MONITORING|<unix_epoch_timestamp>|<value>|<metric_type>|<metric_name>|#<tag_list>

Where:

  • MONITORING signals to the Datadog integration that it should collect this log entry.

  • <unix_epoch_timestamp> is in seconds, not milliseconds.

  • <value> MUST be a number (i.e. integer or float).

  • <metric_type> is count, gauge, histogram, or check.

  • <metric_name> uniquely identifies your metric and adheres to the metric naming policy.

  • <tag_list> is optional, comma separated, and must be preceded by #. The tag function_name:<name_of_the_function> is automatically applied to custom metrics.

Note: The sum for each timestamp is used for counts and the last value for a given timestamp is used for gauges. It is not recommended to print a log statement every time you increment a metric, as this increases the time it takes to parse your logs. Continually update the value of the metric in your code, and print one log statement for that metric before the function finishes.

Data Collected

Metrics

aws.lambda.duration
(gauge)
Measures the average elapsed wall clock time from when the function code starts executing as a result of an invocation to when it stops executing.
shown as millisecond
aws.lambda.duration.maximum
(gauge)
Measures the maximum elapsed wall clock time from when the function code starts executing as a result of an invocation to when it stops executing.
shown as millisecond
aws.lambda.duration.minimum
(gauge)
Measures the minimum elapsed wall clock time from when the function code starts executing as a result of an invocation to when it stops executing.
shown as millisecond
aws.lambda.duration.sum
(gauge)
Measures the total execution time of the lambda function executing.
shown as millisecond
aws.lambda.duration.p80
(gauge)
Measures the p80 elapsed wall clock time from when the function code starts executing as a result of an invocation to when it stops executing.
shown as millisecond
aws.lambda.duration.p95
(gauge)
Measures the p95 elapsed wall clock time from when the function code starts executing as a result of an invocation to when it stops executing.
shown as millisecond
aws.lambda.duration.p99
(gauge)
Measures the p99 elapsed wall clock time from when the function code starts executing as a result of an invocation to when it stops executing.
shown as millisecond
aws.lambda.duration.p99.9
(gauge)
Measures the p99.9 elapsed wall clock time from when the function code starts executing as a result of an invocation to when it stops executing.
shown as millisecond
aws.lambda.errors
(count)
Measures the number of invocations that failed due to errors in the function (response code 4XX).
shown as error
aws.lambda.invocations
(count)
Measures the number of times a function is invoked in response to an event or invocation API call.
shown as invocation
aws.lambda.throttles
(count)
Measures the number of Lambda function invocation attempts that were throttled due to invocation rates exceeding the customer's concurrent limits (error code 429). Failed invocations may trigger a retry attempt that succeeds.
shown as throttle
aws.lambda.iterator_age
(gauge)
Measures the age of the last record for each batch of records processed
shown as millisecond
aws.lambda.iterator_age.minimum
(gauge)
Measures the minimum age of the last record for each batch of records processed
shown as millisecond
aws.lambda.iterator_age.maximum
(gauge)
Measures the maximum age of the last record for each batch of records processed
shown as millisecond
aws.lambda.iterator_age.sum
(gauge)
Measures the sum of the ages of the last record for each batch of records processed
shown as millisecond
aws.lambda.dead_letter_errors
(count)
Measures the sum of times Lambda is unable to write the failed event payload to your configured Dead Letter Queues.
shown as error
aws.lambda.concurrent_executions
(gauge)
Measures the average of concurrent executions for a given function at a given point in time.
shown as execution
aws.lambda.concurrent_executions.minimum
(gauge)
Measures the minimum of concurrent executions for a given function at a given point in time.
shown as execution
aws.lambda.concurrent_executions.maximum
(gauge)
Measures the maximum of concurrent executions for a given function at a given point in time.
shown as execution
aws.lambda.concurrent_executions.sum
(gauge)
Measures the sum of concurrent executions for a given function at a given point in time.
shown as execution
aws.lambda.unreserved_concurrent_executions
(gauge)
Measures the sum of the concurrency of the functions that don't have a custom concurrency limit specified.
shown as execution

Each of the metrics retrieved from AWS is assigned the same tags that appear in the AWS console, including but not limited to function name, security-groups, and more.

Custom metrics are only tagged with function name.

Events

The AWS Lambda integration does not include any events.

Service Checks

The AWS Lambda integration does not include any service checks.

Troubleshooting

Need help? Contact Datadog support.

Further Reading