Monitoring AWS Lambda Durable Functions

Datadog provides full visibility into the metrics, logs, and traces for AWS Lambda Durable Function executions. In a single view, you can monitor your AWS Lambda Durable Functions alongside your other serverless compute services to spot bottlenecks and fix errors.

Supported runtimes: Node.js, Python

Setup

Instrument your Lambda function

  1. Follow the steps for instrumenting a Lambda function, confirming that the Datadog Lambda Library is installed and that both tracing and log collection are enabled (log collection is enabled by default). Use the following versions:

    • Datadog Lambda Extension: v99+
    • Datadog Node.js Lambda layer: v142+
    • Datadog Python Lambda layer: v127+
  2. Set the following environment variable on your Lambda function:

    DD_LAMBDA_DURABLE_FUNCTION_LOG_BUFFER_SIZE=5
    

    This environment variable configures the Datadog Lambda Extension to buffer logs and enrich them with the durable execution context sent by the Datadog Lambda Library. Set its value to a non-negative integer specifying the maximum number of invocations whose logs are buffered. The default, 0, disables enrichment, so durable executions do not appear in Datadog.

Forward durable execution events

Deploy the CloudFormation stack

To forward durable execution status change events to Datadog, deploy the CloudFormation stack to your AWS account:

  1. Log in to the AWS account and region where your durable functions run, then click Launch Stack to open the stack:

    Launch Stack

  2. Provide your Datadog API key using exactly one of the following parameters:

    • DdApiKey: your Datadog API key in plaintext
    • DdApiKeySecretArn: the ARN of an AWS Secrets Manager secret whose value is your Datadog API key
    • DdApiKeySsmParameterName: the name of an AWS Systems Manager Parameter Store SecureString parameter that holds your Datadog API key
  3. Set DdSite to your Datadog site. The default is datadoghq.com.

  4. Optionally, restrict which events are forwarded:

    • Statuses: a comma-separated list of execution statuses to forward. Valid values are RUNNING, SUCCEEDED, FAILED, TIMED_OUT, and STOPPED. Leave this empty to forward all statuses.
    • FunctionArnFilter1 through FunctionArnFilter5: up to five unqualified Lambda function ARNs or EventBridge wildcard patterns, such as arn:aws:lambda:us-east-2:123456789012:function:my-durable-*. Do not include a version or alias suffix. Leave all five empty to forward events from every function in the region.
    • BufferIntervalSeconds: the Amazon Data Firehose buffer interval, in seconds (60-900, default 60). Higher values reduce the number of outbound requests at the cost of freshness.
  5. Click Create stack and wait for the stack to finish creating.

  6. If your durable functions run in multiple AWS regions, repeat these steps in each region.

Install the AWS Lambda integration

In Datadog, install the AWS Lambda integration, which provides the out-of-the-box logs pipeline that transforms the forwarded events.

Create a trace retention filter

Create a trace retention filter with the retention query operation_name:aws.durable.execute.

Querying in Datadog

The Executions tab on the Lambda function page lists durable executions. Use the log attributes, span tags, and metrics below to search for durable executions, or to build dashboards and monitors.

Logs

To scope a log query to one function, filter on the function ARN:

@lambda.arn:"<FUNCTION_ARN>"

The Datadog Lambda Extension adds these attributes to a durable function’s logs:

Log attributeDescription
@lambda.durable_function.execution_nameThe execution name. Groups all logs from one execution.
@lambda.durable_function.execution_idThe execution ID.
@lambda.durable_function.first_invocationtrue on logs from the execution’s first invocation, false otherwise.
@lambda.durable_function.execution_statusThe execution’s state when the invocation ended: SUCCEEDED, FAILED, or PENDING, where PENDING means the execution suspended and resumes in a later invocation. On the END log, or on the REPORT log for executions on Lambda Managed Instances.

Example queries (add @lambda.arn:"<FUNCTION_ARN>" to scope to one function):

  • All logs for one durable execution:

    @lambda.durable_function.execution_name:"<EXECUTION_NAME>"
    
  • Each execution’s START log, which marks when it began:

    "START RequestId:" @lambda.durable_function.first_invocation:true
    
  • Each execution’s last log, which marks when it ended:

    "END RequestId:" OR "REPORT RequestId:"
    

    Lambda Managed Instances emit no END log, so query both.

Status change events

The events forwarded by the CloudFormation stack arrive as logs, matched by:

@detail-type:"Durable Execution Status Change"

The AWS Lambda integration pipeline maps these events onto the following attributes:

Log attributeDescription
@lambda.durable_function.execution_statusOne of RUNNING, SUCCEEDED, FAILED, TIMED_OUT, or STOPPED.
@lambda.durable_function.execution_start_timeWhen the execution started, in UNIX milliseconds.
@lambda.durable_function.execution_end_timeWhen the execution reached a terminal status, in UNIX milliseconds.

Treat these events as the source of truth for terminal status, as END and REPORT logs cannot report TIMED_OUT or STOPPED.

Terminal events are timestamped when the execution finished, so a time range selects executions that finished within it.

Traces

To scope a span query to one function, filter on the function ARN:

@function_arn:"<FUNCTION_ARN>"

The durable execution span

The tracer creates one aws.durable.execute span per invocation and stitches an execution’s invocations into a single trace.

Span tagDescription
@aws.durable.execution_arnThe full durable execution ARN, which contains the execution name. This span does not carry the execution name as a separate tag.
@aws.durable.invocation_statusThe execution’s state when this invocation ended: succeeded, failed, or pending. pending means the execution suspended and resumes in a later invocation.
@aws.durable.replayedfalse on the invocation that starts an execution, true on each later invocation that resumes it after a suspend.

The Lambda invocation span

Each invocation also produces the standard aws.lambda span, tagged with the durable execution context:

Span tagDescription
@aws.durable.execution_nameThe execution name.
@aws.durable.execution_idThe execution ID.
@aws.durable.first_invocationtrue on the first invocation of an execution.
@aws.durable.execution_statusThe execution’s state when the invocation ended: SUCCEEDED, FAILED, or PENDING.

Operation spans

Each operation called on the durable context produces a child span:

Operation nameNode.js methodPython method
aws.durable.stepstepstep
aws.durable.invokeinvokeinvoke
aws.durable.waitwaitwait
aws.durable.wait_for_conditionwaitForConditionwait_for_condition
aws.durable.wait_for_callbackwaitForCallbackwait_for_callback
aws.durable.create_callbackcreateCallbackcreate_callback
aws.durable.mapmapmap
aws.durable.parallelparallelparallel
aws.durable.child_contextrunInChildContextrun_in_child_context
Span tagDescription
@aws.durable.operation_nameThe operation’s name.
@aws.durable.operation_idA hash of the operation’s step ID.
@aws.durable.operation_attemptThe attempt number, on the retryable operations aws.durable.step and aws.durable.wait_for_condition. 0 is the original attempt, 1 the first retry.
@aws.durable.replayedtrue when the operation’s result was served from a checkpoint instead of executed, whether that stored result was a success or a failure.
@aws.durable.invoke.function_nameThe target function, on aws.durable.invoke spans.

Metrics

AWS publishes these durable execution metrics to CloudWatch. They reach Datadog through the AWS Lambda integration and are tagged with functionname.

MetricDescriptionAggregation
aws.lambda.durable_execution_startedNumber of durable executions started.sum as count
aws.lambda.durable_execution_succeededNumber of durable executions that completed successfully.sum as count
aws.lambda.durable_execution_failedNumber of durable executions that completed with failure.sum as count
aws.lambda.durable_execution_timed_outNumber of durable executions that exceeded their timeout.sum as count
aws.lambda.durable_execution_stoppedNumber of durable executions stopped with the StopDurableExecution API.sum as count
aws.lambda.durable_execution_durationWall-clock time a durable execution spent in the RUNNING state, in milliseconds.avg
aws.lambda.durable_execution_operationsCumulative number of operations performed by durable executions.sum as count
aws.lambda.durable_execution_storage_written_bytesCumulative amount of data persisted by durable executions, in bytes.sum
aws.lambda.approximate_running_durable_executionsNumber of durable executions in the RUNNING state.avg
aws.lambda.approximate_running_durable_executions_utilizationPercentage of the durable execution quota in use.avg

For example, to graph failed executions for one function:

sum:aws.lambda.durable_execution_failed{functionname:<FUNCTION_NAME>}.as_count()

Limitations and feedback

Runtimes other than Node.js and Python are not supported. If you encounter an issue with another runtime, open an issue in the datadog-lambda-extension GitHub repository.

If you encounter an issue with the CloudFormation stack, open an issue in the cloudformation-template GitHub repository.