Skip to content

feat(lambda-lite): detect Lambda Lite environment and write mini agent sentinel file#81

Draft
litianningdatadog wants to merge 3 commits intomainfrom
tianning.li/lambda-lite-poc
Draft

feat(lambda-lite): detect Lambda Lite environment and write mini agent sentinel file#81
litianningdatadog wants to merge 3 commits intomainfrom
tianning.li/lambda-lite-poc

Conversation

@litianningdatadog
Copy link
Contributor

https://datadoghq.atlassian.net/browse/SVLS-8571

What does this PR do?

Adds Lambda Lite detection to datadog-serverless-compat and uses it to write a sentinel file on startup that signals co-located Node.js tracers to switch transport modes.

  • Introduces is_lambda_lite() in http_utils, which reads AWS_LAMBDA_INITIALIZATION_TYPE and returns true when the value is "native-http" (the value Lambda Lite sets to distinguish itself from standard on-demand invocations).
  • On startup, MiniAgent writes an empty sentinel file to /tmp/datadog/mini_agent_ready when running in Lambda Lite mode. dd-trace (Node.js) polls this path (via DATADOG_MINI_AGENT_PATH in constants.js) to decide whether to use
    AgentExporter (HTTP to :8126) instead of LogExporter (stdout).
  • Tightens the release profile: lto = "fat" (full cross-crate LTO), strip = "symbols" (explicit symbol stripping), and panic = "abort" (eliminates unwinding code for a smaller binary).

Motivation

Lambda Lite (web function / snap-start mode) runs as a long-lived HTTP server rather than a short-lived invocation handler. The standard Lambda Extension path (/opt/extensions/datadog-agent) is not available in this environment, so dd-trace has no automatic signal that a local agent is present and defaults to shipping traces via stdout. Writing the sentinel file gives dd-trace the signal it needs to switch to the more efficient HTTP path without requiring any customer configuration.

Additional Notes

  • /opt is read-only in Lambda Lite. /tmp/datadog/ is writable and is pre-created by the serverless-compat JS layer before this binary is spawned, so no directory creation is needed here.
  • The detection logic is intentionally a pure function of the env var string (is_lambda_lite_from_env) to keep it fully unit-testable without spawning processes or touching the filesystem.
  • Release profile changes are Lambda Lite–motivated (minimising cold-start binary size) but apply to all targets.

Describe how to test/QA your changes

  • Unit tests for all four AWS_LAMBDA_INITIALIZATION_TYPE states (native-http, on-demand, empty string, unset) are added in http_utils.rs and can be run with: cargo test -p datadog-trace-agent test_is_lambda_lite
  • End-to-end: deploy datadog-serverless-compat in a Lambda Lite environment and confirm /tmp/datadog/mini_agent_ready exists after startup, and that a Node.js app instrumented with dd-trace sends spans via HTTP to :8126 rather than stdout.

litianningdatadog and others added 3 commits February 3, 2026 17:42
Preparing for git worktree usage to enable isolated development
workspaces.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add `is_lambda_lite()` in http_utils to detect Lambda Lite via
  `AWS_LAMBDA_INITIALIZATION_TYPE=native-http`; includes unit tests for
  all env var states (native-http, on-demand, empty, unset)
- Write `/tmp/datadog/mini_agent_ready` sentinel on startup when running
  in Lambda Lite mode so dd-trace Node.js can switch from LogExporter
  (stdout) to AgentExporter (HTTP :8126)
- Refine release profile: use fat LTO, explicit symbol stripping, and
  `panic = "abort"` for smaller binary size
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.

1 participant