feat(aws-lambda-microvm): refresh identity on Flask run hook - #19825
Conversation
Codeowners resolved asResolved from the full PR diff against |
Circular import analysis🚨 New circular imports detected 🚨1 new circular import(s) have been introduced by this PR: Please consider refactoring your changes in accordance to the Separation of Concerns principle.
|
Dependency direction analysis📈 Existing violations got worse46 pre-existing violation(s) increased in severity (e.g. their target became more depended-on, or got pulled into an import cycle), though the edge itself isn't new: Show violations that got worse (showing 5 of 46 highest severity)
|
|
aba2924 to
5d444c6
Compare
BenchmarksBenchmark execution time: 2026-08-23 22:47:53 Comparing candidate commit 5d444c6 in PR branch Found 0 performance improvements and 4 performance regressions! Performance is the same for 383 metrics, 9 unstable metrics.
|
There was a problem hiding this comment.
Pull request overview
Adds AWS Lambda MicroVM-specific runtime identity rotation triggered by Flask’s pre-request web event, so restored MicroVM instances regenerate stable identifiers (runtime ID / RC client ID) on the platform /run lifecycle hook.
Changes:
- Register a
WEB_REQUEST_STARTINGlistener (MicroVM-only) that refreshes identity exactly once when the request matchesPOST /aws/lambda-microvms/runtime/v1/run. - Add subprocess and Flask integration tests covering exact-match behavior, ordering relative to root span creation, concurrency, and no-op behavior outside MicroVMs.
- Add a release note describing stable identifier regeneration for AWS Lambda MicroVM deployments.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
ddtrace/internal/runtime/__init__.py |
Adds MicroVM /run hook constants, listener registration, and the once-per-process guarded refresh logic. |
tests/tracer/runtime/test_runtime_id.py |
Adds unit/subprocess tests for hook matching, ordering vs. span creation, thread safety, and no-op cases. |
tests/contrib/flask/test_microvm_identity_refresh.py |
Updates Flask event assertions to use the real MicroVM /run hook path and verifies identity refresh via emitted events. |
releasenotes/notes/aws-lambda-microvm-identity-refresh-3a672cd6bcbad16d.yaml |
Documents the MicroVM-only stable identifier regeneration behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| # Same env var used by the MicroVM entropy fallback. Read once at import so listener | ||
| # registration is skipped outside MicroVM images. | ||
| _IS_AWS_LAMBDA_MICROVM = env.get("AWS_LAMBDA_MICROVM_IMAGE_ARN") is not None |
Description
This is the Flask-only MicroVM
/runactivation path. When running inside an AWS Lambda MicroVM image, runtime registers a listener for the pre-request web event emitted by Flask. The listener matches the fixed platform hook:and calls
runtime.refresh_identity()once per process. This keeps the activation path focused on Flask while the identity consumers are split across the 3-series draft PRs.Testing
scripts/lint fmt ddtrace/internal/runtime/__init__.py tests/tracer/runtime/test_runtime_id.py tests/contrib/flask/test_microvm_identity_refresh.pyscripts/lint format_check ddtrace/internal/runtime/__init__.py tests/tracer/runtime/test_runtime_id.py tests/contrib/flask/test_microvm_identity_refresh.pygit diff --checkscripts/run-tests tests/tracer/runtime/test_runtime_id.py --venv 1fa38a1 -- -- -q tests/tracer/runtime/test_runtime_id.pyImportError: cannot import name 'process_metrics' from 'ddtrace.internal.native._native'scripts/run-tests tests/contrib/flask/test_microvm_identity_refresh.py --venv 1c6c710 -- -- -q tests/contrib/flask/test_microvm_identity_refresh.pyImportError: cannot import name 'process_metrics' from 'ddtrace.internal.native._native'Stack
Stacked on #19816.
Extracted from #19781 (closed)