This product is not supported for your selected Datadog site. ().
Join the Preview!

Datadog Serverless Monitoring for AWS Lambda MicroVMs is in Preview. To sign up, contact your Datadog representative.

Datadog collects logs, traces, and metrics, including CPU utilization, from your AWS Lambda MicroVMs throughout their lifecycle. MicroVMs run applications in isolated Firecracker virtual machines. Each instance starts from an image snapshot and can suspend when idle, then resume with its memory and disk state intact.

Prerequisites

To use Datadog Serverless Monitoring for AWS Lambda MicroVMs, you must have the following:

  • A Datadog API key and network egress to Datadog
  • An application that follows the AWS MicroVM service model

Optionally, to collect traces, install a Datadog SDK that meets the following minimum version. Without an SDK, serverless-init still collects logs and metrics.

ComponentMinimum version
Node.js SDK (dd-trace)6.15.0
Python SDK (ddtrace)4.17.0

If your application uses OpenSSL, use a snapshot-compatible version. AWS provides one in the public.ecr.aws/lambda/microvms:al2023-minimal container base image. You can also use your own base image with the patched OpenSSL library. See AWS guidance on snapshots for more information.

Setup

Instrument the image

  1. Add serverless-init v1.11.4 or later to your MicroVM image. Set it as the container entrypoint, with your application as the command. Sidecar mode is not supported. The image is available on Docker Hub and the Amazon ECR Public Gallery.

    The following examples include optional tracing and use an application on port 8080 and lifecycle hooks on port 9000. Replace the application filenames and startup commands as needed.

    Add dd-trace v6.15.0 or later to package.json and update package-lock.json, such as with npm install dd-trace@6.15.0. Install Node.js from the Amazon Linux packages to use snapshot-compatible OpenSSL.

    FROM public.ecr.aws/lambda/microvms:al2023-minimal
    WORKDIR /app
    RUN dnf install -y nodejs22 nodejs22-npm && dnf clean all
    COPY package.json package-lock.json ./
    RUN npm ci --omit=dev
    COPY . .
    COPY --from=datadog/serverless-init:1.11.4 /datadog-init /serverless-init
    ENV DD_AWS_MICROVM_USER_APP_PORT=8080 \
        DD_AWS_MICROVM_ENABLE_RUN=true
    EXPOSE 8080 9000
    ENTRYPOINT ["/serverless-init"]
    CMD ["node", "--require", "dd-trace/init", "app.js"]
    

    The --require dd-trace/init option initializes the SDK before loading application code. If app.js already calls require('dd-trace').init() before importing other libraries, use CMD ["node", "app.js"] instead.

    For more information, see Tracing Node.js Applications.

    Add ddtrace v4.17.0 or later to requirements.txt. Install the dependencies, then start the application with ddtrace-run:

    FROM public.ecr.aws/lambda/microvms:al2023-minimal
    WORKDIR /app
    RUN dnf install -y python3.12 python3.12-pip && dnf clean all
    COPY requirements.txt ./
    RUN python3.12 -m pip install --no-cache-dir -r requirements.txt
    COPY . .
    COPY --from=datadog/serverless-init:1.11.4 /datadog-init /serverless-init
    ENV PYTHONUNBUFFERED=1 \
        DD_AWS_MICROVM_USER_APP_PORT=8080 \
        DD_AWS_MICROVM_ENABLE_RUN=true
    EXPOSE 8080 9000
    ENTRYPOINT ["/serverless-init"]
    CMD ["ddtrace-run", "python3.12", "app.py"]
    

    ddtrace-run initializes tracing before the application starts. Python tracing supports WSGI and ASGI applications, including Flask, Django, FastAPI, and Starlette.

    For more information, see Tracing Python Applications.

    For tracing, forward the /run hook to your application, as shown in the examples. MicroVM instances start from the same image snapshot, so trace and span IDs can collide across instances. Forwarding /run allows the tracer to generate new IDs for each instance.

    To collect logs and metrics without tracing, omit the SDK dependency and tracer initialization. Use CMD ["node", "app.js"] for Node.js or CMD ["python3.12", "app.py"] for Python. You can also omit DD_AWS_MICROVM_USER_APP_PORT and DD_AWS_MICROVM_ENABLE_RUN unless your application needs forwarded lifecycle hooks.
  2. Set the following environment variables:

    DD_API_KEY=<DATADOG_API_KEY>
    DD_SITE=<DATADOG_SITE>
    DD_SERVICE=<SERVICE_NAME>
    DD_ENV=<ENVIRONMENT>
    DD_VERSION=<VERSION>
    

    Set DD_SITE to your Datadog site: .

  3. Enable the AWS Lambda MicroVM lifecycle hooks in the image configuration.

    serverless-init starts and supervises your application. It handles the /ready and /validate hooks during image setup, and the /run, /resume, /suspend, and /terminate hooks at runtime.

Enable logs

Set DD_LOGS_ENABLED=true to collect logs. To correlate logs with traces, enable log injection in your tracer and configure the logs pipeline to parse trace and span IDs. With log injection enabled, JSON logs include active trace and span IDs. Supported Node.js loggers include Bunyan, Pino, and Winston. For Python, use structlog.

See correlating logs and traces for Node.js and Python.

(Optional) Forward additional lifecycle hooks to your application

The Dockerfile examples in the Instrument the image section already forward the /run hook for tracing.

By default, serverless-init handles lifecycle hooks on port 9000 and does not forward them to your application. To forward a hook, set DD_AWS_MICROVM_USER_APP_PORT to the port your application listens on at 127.0.0.1, then set the matching DD_AWS_MICROVM_ENABLE_<HOOK> variable to true. The app and lifecycle ports must differ. You need both settings. Either one alone leaves forwarding disabled.

Environment variableDescriptionDefault
DD_AWS_MICROVM_LIFECYCLE_PORTPort serverless-init listens on for lifecycle hooks.9000
DD_AWS_MICROVM_USER_APP_PORTPort your application listens on at 127.0.0.1. Required to forward hooks.Not set (no forwarding)
DD_AWS_MICROVM_ENABLE_READYForward /ready to your application.false
DD_AWS_MICROVM_ENABLE_VALIDATEForward /validate to your application.false
DD_AWS_MICROVM_ENABLE_RUNForward /run to your application.false
DD_AWS_MICROVM_ENABLE_RESUMEForward /resume to your application.false
DD_AWS_MICROVM_ENABLE_SUSPENDForward /suspend to your application.false
DD_AWS_MICROVM_ENABLE_TERMINATEForward /terminate to your application.false
DD_AWS_MICROVM_READY_TIMEOUT_MSTimeout for a forwarded /ready hook, in milliseconds.30000 (30 s)
DD_AWS_MICROVM_VALIDATE_TIMEOUT_MSTimeout for a forwarded /validate hook, in milliseconds.30000 (30 s)
DD_AWS_MICROVM_FORWARD_TIMEOUT_MSTimeout for forwarded /run, /resume, /suspend, and /terminate hooks, in milliseconds.1000 (1 s)

Timeouts apply only to forwarded hooks. You don’t need to forward hooks to collect logs and metrics.

Collected data

Metrics

Datadog collects the following CPU utilization and lifecycle metrics for each MicroVM without additional setup:

MetricDescription
aws.lambda.microvm.enhanced.cpu.usageCPU usage for the MicroVM, in nanocores.
aws.lambda.microvm.enhanced.cpu.limitNumber of CPUs available to the guest, in nanocores.
aws.lambda.microvm.enhanced.validateNumber of validation hook events.
aws.lambda.microvm.enhanced.runNumber of run hook events.
aws.lambda.microvm.enhanced.resumeNumber of resume hook events.
aws.lambda.microvm.enhanced.suspendNumber of suspend hook events.
aws.lambda.microvm.enhanced.terminateNumber of termination hook events.
aws.lambda.microvm.enhanced.active_instancesPeriodic heartbeat while a MicroVM is running or resumed. This is a periodic sample, not an exact instance count.

CPU metrics

serverless-init samples CPU metrics every 3 seconds, starting when the MicroVM starts. CPU metrics are enabled by default. To disable them, set DD_ENHANCED_METRICS_ENABLED=false. Lifecycle and heartbeat metrics are still reported.

Both CPU metrics report raw values in nanocores: 1 CPU core equals 1,000,000,000 nanocores. The provided dashboard converts them to cores, the unit AWS uses for CPU capacity, by dividing the values by 1e9. The metrics use the same units as container.cpu.usage and container.cpu.limit.

CPU metrics are available with or without cgroups. When cgroups are unavailable, cpu.limit reflects the CPU count visible to the MicroVM, which can differ from its AWS CPU capacity.

Tags

Logs and traces include the MicroVM image ARN as resource_id, the image name as image_name, and the image version as lambda_microvm_image_version. CPU and lifecycle metrics include the resource_id and image_name tags. The instance heartbeat also includes the image ARN as microvm_image_arn.

After AWS sends the /run hook, logs, traces, lifecycle metrics, and the instance heartbeat also include the lambda_microvm_id instance ID tag. CPU metrics use image tags, not instance tags. When configured, CPU metrics, lifecycle metrics, and the instance heartbeat include the unified service tags env, service, and version.

Data flush on suspend and terminate

When a MicroVM suspends or terminates, serverless-init sends pending metrics, logs, and traces to Datadog.

Further reading