Repository navigation
feat: [SVLS-10133] Warn when instrumenting Lambda functions below 256 MB - #793
avangelillo wants to merge 4 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
git-thuerk-done
left a comment
There was a problem hiding this comment.
Thanks for adding this! A few optional suggestions are inline.
| | `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`. | |
There was a problem hiding this comment.
Optional: the other SVLS-10133 PRs (and line 290 here) use "silence" for this option, so consider matching it.
| | `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`. | |
There was a problem hiding this comment.
Applied in dc503fc, using about 70 MB to match the rounded figure now used in all the SVLS-10133 PRs.
|
|
||
| #### 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. |
There was a problem hiding this comment.
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?
| 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. |
There was a problem hiding this comment.
Applied in dc503fc, using about 70 MB to match the rounded figure now used in all the SVLS-10133 PRs.
|
|
||
| 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`. |
There was a problem hiding this comment.
Optional: naming the actual risks instead of "issues" might help readers decide whether to raise memory or silence the warning.
| 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`. |
There was a problem hiding this comment.
Applied in dc503fc, using about 70 MB to match the rounded figure now used in all the SVLS-10133 PRs.
| 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. |
There was a problem hiding this comment.
Optional: active voice for the IDE tooltip.
| * The function is instrumented either way. | |
| * The construct instruments the function either way. |
There was a problem hiding this comment.
Applied in dc503fc, using about 70 MB to match the rounded figure now used in all the SVLS-10133 PRs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ava-silver
left a comment
There was a problem hiding this comment.
Automated AI Review (human curated)
Clean implementation and good test coverage across thresholds, tokens, SingletonFunction, and multiple addLambdaFunctions calls. Two small cleanup notes inline.
| function getCfnFunction(lambdaFunction: LambdaFunction): lambda.CfnFunction | undefined { | ||
| return (lambdaFunction instanceof lambda.SingletonFunction ? lambdaFunction.permissionsNode : lambdaFunction.node) | ||
| .defaultChild as lambda.CfnFunction | undefined; | ||
| } |
There was a problem hiding this comment.
addCdkConstructVersionTag right above duplicates this same SingletonFunction ? permissionsNode : node defaultChild lookup -- worth reusing getCfnFunction there to keep it in one place.
| if (memorySize === undefined) { | ||
| return DEFAULT_LAMBDA_MEMORY_MB; | ||
| } | ||
| if (Token.isUnresolved(memorySize) || typeof memorySize !== "number") { |
There was a problem hiding this comment.
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.
What does this PR do?
DatadogLambdanow 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 newsuppressLowMemoryWarning: trueprop (suppress_low_memory_warningin Python) to silence it.Memory is read from the underlying
CfnFunction, including forSingletonFunction. Unset memory counts as the AWS default of 128 MB, so it warns. Token values are not flagged. The check runs insideaddLambdaFunctions, 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:
SingletonFunctionwarnsaddLambdaFunctionscall is checkednpx projen test(482 tests plus eslint),npx projen compile(jsii) andcheck-formattingpass.Additional Notes
Warn-only, so this is not a breaking change. The README has a new "Memory requirements" section.
Types of Changes
Check all that apply
🤖 Generated with Claude Code