Skip to content

feat: [SVLS-10133] Warn when instrumenting Lambda functions below 256 MB - #793

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

avangelillo wants to merge 4 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?

DatadogLambda now adds a CDK warning annotation (datadog-cdk-constructs-v2:lambdaLowMemory) to each instrumented function with less than 256 MB of memory. It still instruments those functions exactly as before. Set the new suppressLowMemoryWarning: true prop (suppress_low_memory_warning in Python) to silence it.

Memory is read from the underlying CfnFunction, including for SingletonFunction. Unset memory counts as the AWS default of 128 MB, so it warns. Token values are not flagged. The check runs inside addLambdaFunctions, so functions added in later calls are covered too.

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

Eight new tests cover:

  • 128 MB warns with the exact text and is still instrumented
  • 255 warns; 256 doesn't
  • unset memory warns
  • a token doesn't warn
  • the suppress prop silences it and the function is still instrumented
  • SingletonFunction warns
  • a second addLambdaFunctions call is checked

npx projen test (482 tests plus eslint), npx projen compile (jsii) and check-formatting pass.

Additional Notes

Warn-only, so this is not a breaking change. The README has a new "Memory requirements" section.

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

avangelillo and others added 2 commits November 20, 2026 14:47
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@avangelillo avangelillo changed the title [SVLS-10133] Warn when instrumenting Lambda functions below 256 MB feat: [SVLS-10133] Warn when instrumenting Lambda functions below 256 MB Nov 20, 2026
@avangelillo
avangelillo marked this pull request as ready for review November 20, 2026 20:09
@avangelillo
avangelillo requested review from a team as code owners November 20, 2026 20:09

@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! A few optional suggestions are inline.

Comment thread README.md Outdated
| `llmObsEnabled` | `llm_obs_enabled` | Toggle to enable submitting data to LLM Observability Defaults to `false`. |
| `llmObsMlApp` | `llm_obs_ml_app` | The name of your LLM application, service, or project, under which all traces and spans are grouped. This helps distinguish between different applications or experiments. See [Application naming guidelines](https://docs.datadoghq.com/llm_observability/sdk/?tab=nodejs#application-naming-guidelines) for allowed characters and other constraints. To override this value for a given root span, see [Tracing multiple applications](https://docs.datadoghq.com/llm_observability/sdk/?tab=nodejs#tracing-multiple-applications). Required if `llmObsEnabled` is `true` |
| `llmObsAgentlessEnabled` | `llm_obs_agentless_enabled` | Only required if you are not using the Datadog Lambda Extension, in which case this should be set to `true`. Defaults to `false`. |
| `suppressLowMemoryWarning` | `suppress_low_memory_warning` | When set to `true`, skip the warning emitted for functions with less than 256 MB of memory. See [Memory requirements](#memory-requirements). Defaults to `false`. |

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Optional: the other SVLS-10133 PRs (and line 290 here) use "silence" for this option, so consider matching it.

Suggested change
| `suppressLowMemoryWarning` | `suppress_low_memory_warning` | When set to `true`, skip the warning emitted for functions with less than 256 MB of memory. See [Memory requirements](#memory-requirements). Defaults to `false`. |
| `suppressLowMemoryWarning` | `suppress_low_memory_warning` | When set to `true`, silence the warning emitted for functions with less than 256 MB of memory. See [Memory requirements](#memory-requirements). Defaults to `false`. |

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied in dc503fc, using about 70 MB to match the rounded figure now used in all the SVLS-10133 PRs.

Comment thread README.md Outdated

#### Memory requirements

The Datadog Lambda Extension and tracer add memory overhead to your function (about 69 MB for Python), which can cause out-of-memory errors and timeouts on functions with little memory. When `addLambdaFunctions` instruments a function with less than 256 MB of memory, the construct emits a CDK warning with the reason `lambda_low_memory`. If `memorySize` is not set, the function uses the Lambda default of 128 MB, so the warning is emitted. If `memorySize` is a token that is only resolved at deploy time, no warning is emitted.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Optional: consider splitting the first sentence and naming the construct as the subject, so each case says who acts. Does this read well to you?

Suggested change
The Datadog Lambda Extension and tracer add memory overhead to your function (about 69 MB for Python), which can cause out-of-memory errors and timeouts on functions with little memory. When `addLambdaFunctions` instruments a function with less than 256 MB of memory, the construct emits a CDK warning with the reason `lambda_low_memory`. If `memorySize` is not set, the function uses the Lambda default of 128 MB, so the warning is emitted. If `memorySize` is a token that is only resolved at deploy time, no warning is emitted.
The Datadog Lambda Extension and tracer add memory overhead to your function (about 69 MB for Python). On functions with little memory, this overhead can cause out-of-memory errors and timeouts. When `addLambdaFunctions` instruments a function with less than 256 MB of memory, the construct emits a CDK warning with the reason `lambda_low_memory`. If `memorySize` is not set, the function uses the Lambda default of 128 MB, so the construct emits the warning. If `memorySize` is a token that resolves only at deploy time, the construct doesn't emit a warning.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied in dc503fc, using about 70 MB to match the rounded figure now used in all the SVLS-10133 PRs.

Comment thread README.md Outdated

The Datadog Lambda Extension and tracer add memory overhead to your function (about 69 MB for Python), which can cause out-of-memory errors and timeouts on functions with little memory. When `addLambdaFunctions` instruments a function with less than 256 MB of memory, the construct emits a CDK warning with the reason `lambda_low_memory`. If `memorySize` is not set, the function uses the Lambda default of 128 MB, so the warning is emitted. If `memorySize` is a token that is only resolved at deploy time, no warning is emitted.

The function is still instrumented. To avoid issues, increase the function's memory to at least 256 MB. To silence the warning, set `suppressLowMemoryWarning` to `true`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Optional: naming the actual risks instead of "issues" might help readers decide whether to raise memory or silence the warning.

Suggested change
The function is still instrumented. To avoid issues, increase the function's memory to at least 256 MB. To silence the warning, set `suppressLowMemoryWarning` to `true`.
The construct still instruments the function. To avoid out-of-memory errors and timeouts, increase the function's memory to at least 256 MB. To silence the warning, set `suppressLowMemoryWarning` to `true`.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied in dc503fc, using about 70 MB to match the rounded figure now used in all the SVLS-10133 PRs.

Comment thread src/interfaces.ts Outdated
readonly llmObsAgentlessEnabled?: boolean;
/**
* Silence the warning emitted when an instrumented Lambda function has less than 256 MB of memory.
* The function is instrumented either way.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Optional: active voice for the IDE tooltip.

Suggested change
* The function is instrumented either way.
* The construct instruments the function either way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied in dc503fc, using about 70 MB to match the rounded figure now used in all the SVLS-10133 PRs.

avangelillo and others added 2 commits November 20, 2026 15:42
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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)

Clean implementation and good test coverage across thresholds, tokens, SingletonFunction, and multiple addLambdaFunctions calls. Two small cleanup notes inline.

Comment thread src/datadog-lambda.ts
Comment on lines +270 to +273
function getCfnFunction(lambdaFunction: LambdaFunction): lambda.CfnFunction | undefined {
return (lambdaFunction instanceof lambda.SingletonFunction ? lambdaFunction.permissionsNode : lambdaFunction.node)
.defaultChild as lambda.CfnFunction | undefined;
}

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.

addCdkConstructVersionTag right above duplicates this same SingletonFunction ? permissionsNode : node defaultChild lookup -- worth reusing getCfnFunction there to keep it in one place.

Comment thread src/datadog-lambda.ts
if (memorySize === undefined) {
return DEFAULT_LAMBDA_MEMORY_MB;
}
if (Token.isUnresolved(memorySize) || typeof memorySize !== "number") {

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.

typeof memorySize !== "number" is unreachable here: CfnFunction.memorySize is typed number | undefined, and numeric tokens from Token.asNumber(...) are already caught by Token.isUnresolved(memorySize). You can drop the typeof check.

This branch has not been deployed

No deployments
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