Skip to content

aws.lambda.enhanced.out_of_memory not emitted when Lambda reaches memory limit but AWS reports as timeout #1237

Open

Description

@Hamdi-Hassan-seccl

Hi Team

We are investigating an incident where a Lambda reached its memory limit but our Datadog monitor based on aws.lambda.enhanced.out_of_memory did not trigger.

We tried reproducing a similar case in sandbox Lambda. Enhanced metrics are working generally as expected as we can see that aws.lambda.enhanced.invocations and aws.lambda.enhanced.max_memory_used.
However, the `out_of_memory one remains no-data even when Lambda memory usage reaches the configured limit. ( see screenshot attached below)

Image

Example CloudWatch output we've observed in when reproduced the issue:

INIT_REPORT Init Duration: 180000.45 ms Phase: invoke Status: timeout
REPORT RequestId: 514789fd-5e24-49c5-a41c-24c049a36e2a
Duration: 180000.00 ms
Billed Duration: 180000 ms
Memory Size: 192 MB
Max Memory Used: 192 MB
Status: timeout

We also saw similar tests where memory was very close to the limit:

Memory Size: 128 MB
Max Memory Used: 127 MB
Status: timeout
and:
Memory Size: 256 MB
Max Memory Used: 252–254 MB

In these cases, Datadog emitted aws.lambda.enhanced.max_memory_used, but did not emit aws.lambda.enhanced.out_of_memory.
The Datadog extension appears to be running and subscribed to telemetry:

TELEMETRY Name: datadog-agent State: Already subscribed Types: [Platform, Extension, Function]
EXTENSION Name: datadog-agent State: Ready Events: [INVOKE, SHUTDOWN]

### Question
Is aws.lambda.enhanced.out_of_memory metric expected to emit only for explicit runtime OOM signatures, such as:

Runtime exited with error: signal: killed
Runtime.ExitError
OutOfMemoryError
JavaScript heap out of memory

Or should it also emit when the Lambda REPORT line shows memory saturation, for example:

Memory Size: 192 MB
Max Memory Used: 192 MB
Status: timeout

From an operational perspective, this looks like memory exhaustion leading to timeout, but the OOM metric does not emit.
Could you confirm whether this is expected behaviour?
Environment variables used:

Runtime: nodejs22.x
Datadog Lambda Extension version: Datadog-Extension-ARM v92
Architecture: arm64
Region: eu-west-1

Activity

  1. changed the title [-]aws.lambda.enhanced.out_of_memory not emitted when Lambda reaches memory limit but AWS reports invocation as timeout[/-] [+]aws.lambda.enhanced.out_of_memory not emitted when Lambda reaches memory limit but AWS reports as timeout[/+] on May 22, 2026
  2. self-assigned this
    on May 22, 2026
  3. lym953 commented on May 22, 2026

    @lym953
    Collaborator

    Thanks for the report!

    OOMs are tricky to capture, and here's how we currently capture OOMs for each runtime:

    • Node: runtime-specific log message:
      • JavaScript heap out of memory, or
      • Runtime exited with error: signal: killed
    • Java: runtime-specific log message:
      • java.lang.OutOfMemoryError
    • .NET: runtime-specific log message:
      • OutOfMemoryException
    • Python and Ruby: Runtime.OutOfMemory in PlatformReport event from Lambda telemetry API
    • Go: max memory used == memory size

    For Node, we are not also using max memory used == memory size (in addition to runtime-specific log message) to avoid double counting.

    However, in your case, seems JavaScript heap out of memory or Runtime exited with error: signal: killed logs were not emitted for your function. Do you see any other symptom of OOM besides max memory used == memory size? If yes, then we can consider using that to capture OOM as well.

  4. Hamdi-Hassan-seccl commented on May 25, 2026

    @Hamdi-Hassan-seccl
    Author

    Hi,
    Unfortunately, no. I was also hoping to see something along the lines of signal: killed, but the only thing we can see is a timeout.

    That said, your documentation suggests there may be some inconsistencies with this specific metric, and recommends reaching out here if we encounter this kind of case?

  5. lym953 commented on May 26, 2026

    @lym953
    Collaborator

    That said, your documentation suggests there may be some inconsistencies with this specific metric, and recommends reaching out here if we encounter this kind of case?

    Yes, that statement in the doc was added by me. Let me do some investigation.

  6. lym953 commented on May 29, 2026

    @lym953
    Collaborator

    I'm still working on this.

  7. lym953 commented on Jun 5, 2026

    @lym953
    Collaborator

    The PR is merged and will be released in v98 (maybe in 2–3 weeks). With that, when max memory used == memory size, the metric aws.lambda.enhanced.out_of_memory will be emitted.

    Regarding the scenario "where memory was very close to the limit", this sounds like a new feature request, and I'm not sure whether it's a good feature to add right now. As an alternative, have you explored setting up a Datadog monitor using aws.lambda.enhanced.max_memory_used and aws.lambda.memory_size? You can start by checking the pre-defined metric query "Max Memory Used/Memory Size" on the Lambda side panel.

    Image
  8. Hamdi-Hassan-seccl commented on Jun 16, 2026

    @Hamdi-Hassan-seccl
    Author

    Thank you @lym953 for looking into this, looking forward for the fix 🤞🏻

  9. lym953 commented on Jun 26, 2026

    @lym953
    Collaborator

    v98 is out! Could you try it?

  10. Hamdi-Hassan-seccl commented on Jun 30, 2026

    @Hamdi-Hassan-seccl
    Author

    Hi @lym953
    Yes we've this now and we have got the below logs
    REPORT RequestId: 6a6d9d35-8015-4333-aebe-782127c2ae33 Duration: 10945.21 ms Billed Duration: 10946 ms Memory Size: 192 MB Max Memory Used: 192 MB Status: error Error Type: Runtime.OutOfMemory

    One thing I wanted to clarify, although I haven’t tested this yet: previously, when a Lambda went OOM, the agent wasn’t reporting those logs to Datadog, so they were only available in CloudWatch Logs. Is that still the case?

  11. lym953 commented on Jun 30, 2026

    @lym953
    Collaborator

    Is that still the case?

    Likely yes because I don't expect my latest PR to affect this behavior.

    To be specific, in your case, if multiple back-to-back invocations went OOM, I expect the log you mentioned to be missing only for the last invocation. For example, that log for the 1st invocation should be captured by the extension when the 2nd started. However, the log for the last invocation might be lost. Is that what you see?

  12. Hamdi-Hassan-seccl commented on Jun 30, 2026

    @Hamdi-Hassan-seccl
    Author

    Yeah, I was trying to understand whether the logs would still be available in Datadog when the Lambda fails due to OOM.
    Basically, I’m asking whether the agent would still be able to fire the logs to Datadog before the function dies, or whether those logs would only be available in CloudWatch?
    e.g this log line or similar
    REPORT RequestId: 77415041-e184-4246-8c0a-c7e306d359b0 Duration: 13956.16 ms Billed Duration: 13957 ms Memory Size: 192 MB Max Memory Used: 192 MB Status: error Error Type: Runtime.OutOfMemory

    Does that make any sense?

  13. Hamdi-Hassan-seccl commented on Jul 1, 2026

    @Hamdi-Hassan-seccl
    Author

    Ok os based on my findings, I tested this by intentionally causing a function to OOM.
    What I observed is that we are getting a log entry in Datadog, as shown in the screenshot below

    Image However, in CloudWatch Logs, I can see this log entry for OOM.

    REPORT RequestId: 77415041-e184-4246-8c0a-c7e306d359b0 Duration: 13956.16 ms Billed Duration: 13957 ms Memory Size: 192 MB Max Memory Used: 192 MB Status: error Error Type: Runtime.OutOfMemory

    We are currently discussing whether we need to ingest the CloudWatch logs into Datadog specifically for OOM scenarios. We are a bit hesitant because we are already being alerted through the existing monitors, and the main thing missing in Datadog is the explicit Runtime.OutOfMemory error type.

    I am also not sure whether there is a way to ingest CloudWatch logs into Datadog only for this specific scenario. Otherwise, ingesting broader CloudWatch logs could have a significant cost implication.
    What’s your take on this? Do you think it is worth ingesting the CloudWatch logs for this, or should we rely on the existing Datadog monitors we can do with the missing Runtime.OutOfMemory details?

  14. lym953 commented on Jul 1, 2026

    @lym953
    Collaborator

    The two logs you shared (one from CloudWatch Logs, one from Datadog) are not from the same request. Is that a mistake?

    I am also not sure whether there is a way to ingest CloudWatch logs into Datadog only for this specific scenario. Otherwise, ingesting broader CloudWatch logs could have a significant cost implication.

    I don't know a way to ingest logs just for this scenario. Datadog forwarder should be able to capture all the CloudWatch logs including those for this scenario, but I agree it's an overkill.

    What’s your take on this? Do you think it is worth ingesting the CloudWatch logs for this, or should we rely on the existing Datadog monitors we can do with the missing Runtime.OutOfMemory details?

    I think it depends on what you want to achieve. For example, if you want to:

    1. get alerted when OOM happens, and
    2. check some samples of error messages and failed invocations

    then an inaccurate aws.lambda.out_of_memory metric and partial exception logs may still help achieve the goal to a large extent, though monitor threshold can be affected.

    Do you think you can achieve most of what you want given the current constraints?

  15. lym953 commented on Jul 1, 2026

    @lym953
    Collaborator

    Basically, I’m asking whether the agent would still be able to fire the logs to Datadog before the function dies, or whether those logs would only be available in CloudWatch?

    In some cases, OOM kills the extension, so the logs would only be available in CloudWatch and not in Datadog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions