Skip to content

[SVLS-10133] Warn when instrumenting Lambda functions below 256 MB - #775

Open
avangelillo wants to merge 3 commits into
mainfrom
alex.angelillo/svls-10133-low-memory-warning
Open

avangelillo wants to merge 3 commits into
mainfrom
alex.angelillo/svls-10133-low-memory-warning

Conversation

@avangelillo

@avangelillo avangelillo commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

The plugin now prints a warning for each instrumented function with less than 256 MB of memory. It still instruments those functions exactly as before. Set custom.datadog.suppressLowMemoryWarning: true to silence it.

Effective memory is functions.<fn>.memorySize ?? provider.memorySize ?? 1024 (the Serverless Framework default). Values that aren't plain numbers, such as unresolved variables, are not flagged. Excluded functions, and those the plugin doesn't add layers to, are skipped. The warning goes through the existing logToCliOnce with the plugin's usual Warning: prefix.

Motivation

The Datadog Lambda Extension and tracer layers run inside the function and add memory overhead, about 70 MB with the Python tracer. On functions with 128 MB of memory and short timeouts, that overhead can cause out-of-memory errors and timeouts once the function is instrumented. Datadog's automatic setup now skips first-time installs on functions below 256 MB, recording the reason lambda_low_memory. This PR adds a matching safeguard here, with the same threshold and reason code, as part of SVLS-10133.

Companion PRs make the same change in datadog-ci, serverless-plugin-datadog, datadog-cdk-constructs, datadog-cloudformation-macro, terraform-aws-lambda-datadog and the public docs.

Testing Guidelines

A new low-memory warning suite runs the real before:package:createDeploymentArtifacts hook. It covers:

  • 128 MB warns and still adds the layers
  • 256 MB doesn't warn
  • provider-level memory is inherited, and a function-level value overrides it
  • unset memory doesn't warn
  • non-numeric values don't warn
  • the suppress option silences it
  • excluded functions don't warn
  • enabled: false prints nothing

yarn test (278), yarn lint, yarn check-formatting and yarn build pass.

Additional Notes

Warn-only, so this is not a breaking change. An opt-in skip mode was left out of scope.

Types of changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@avangelillo
avangelillo marked this pull request as ready for review November 20, 2026 20:07
@avangelillo
avangelillo requested review from a team as code owners November 20, 2026 20:07

@git-thuerk-done git-thuerk-done left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this! The wording matches the other SVLS-10133 PRs well: same threshold, reason code, and warn-only behavior. A few optional suggestions are inline.

  • Across the five SVLS-10133 PRs, the four tools say "about 69 MB for Python" and the docs PR says "about 70 MB". Could you align them? Also, is the figure stable enough to hard-code in the warning text, or might it change between tracer releases?

Comment thread README.md Resolved
Co-authored-by: Alicia Thuerk <alicia.thuerk@datadoghq.com>
@avangelillo

Copy link
Copy Markdown
Contributor Author

Thanks for adding this! The wording matches the other SVLS-10133 PRs well: same threshold, reason code, and warn-only behavior. A few optional suggestions are inline.

  • Across the five SVLS-10133 PRs, the four tools say "about 69 MB for Python" and the docs PR says "about 70 MB". Could you align them? Also, is the figure stable enough to hard-code in the warning text, or might it change between tracer releases?

@git-thuerk-done I'll align them to 70MB for now, and double check if that is stable enough to keep the number at all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@avangelillo

Copy link
Copy Markdown
Contributor Author

Thanks! I aligned the figure on about 70 MB in all five PRs (afa596e here). It's a rounded, approximate number in the warning, and the docs have the details, so it won't need to change with every tracer release.

@ava-silver ava-silver left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated AI Review (human curated)

Threshold, provider.memorySize inheritance, Serverless 1024 MB default handling, and logToCliOnce integration look good. One inline issue where functions that receive no Datadog layers still trigger the warning.

Comment thread src/index.ts
Comment on lines +142 to +146
if (config.suppressLowMemoryWarning !== true) {
for (const warning of getLowMemoryWarnings(this.serverless.service, handlers)) {
this.logToCliOnce(`Warning: ${warning}`);
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This runs before checking config.addLayers / config.addExtension, and getLowMemoryWarnings only skips RuntimeType.UNSUPPORTED. As a result, functions that get no Datadog layers still warn -- for example:

  • A 128 MB Python function with addLayers: false and addExtension: false receives no layers but still prints a warning blaming extension and tracer layer overhead.
  • A 128 MB .NET or Java function with addExtension: false receives no layers (since applyLambdaLibraryLayers skips those runtimes without the extension) but still warns.

This also differs from the PR description ("those the plugin doesn't add layers to, are skipped"). Consider gating on config.addLayers || config.addExtension and skipping extension-only runtimes when !config.addExtension (or updating the PR description if warning unconditionally is intended).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants