Repository navigation
chore(runtime): refresh MicroVM identity - #19939
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
Conversation
|
✅ All CI checks and tests passed. 🎉 All green!🧪 All tests passed 🔗 Commit SHA: 174c28b | Docs | View more details | Give us feedback! |
Dependency direction analysis
|
Circular import analysis
|
Codeowners resolved asResolved from the full PR diff against No remaining files require a CODEOWNERS review. |
BenchmarksBenchmark execution time: 2026-10-10 04:17:36 Comparing candidate commit 174c28b in PR branch Found 0 performance improvements and 4 performance regressions! Performance is the same for 351 metrics, 9 unstable metrics, 4 known flaky benchmarks, 4 flaky benchmarks without significant changes.
|
There was a problem hiding this comment.
Pull request overview
This PR wires AWS Lambda MicroVM “/run” lifecycle detection into ddtrace startup so the runtime identity can be refreshed after import-time when a MicroVM reuses the same Python process for a new logical runtime.
Changes:
- Adds a MicroVM
/runrequest listener (web.request.starting) that refreshes runtime identity once per process, with a forksafe/threadsafe guard. - Centralizes MicroVM
/runmethod/path constants and reuses them from the contrib web dispatch helper. - Adds subprocess + integration test coverage to ensure refresh happens before root span creation and is thread-safe.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
ddtrace/internal/runtime/__init__.py |
Adds MicroVM /run hook constants and request-event listener that refreshes identity once per process. |
ddtrace/__init__.py |
Registers the MicroVM identity-refresh hook during ddtrace import. |
ddtrace/contrib/internal/web.py |
Uses the shared MicroVM /run constants when dispatching web.request.starting. |
ddtrace/contrib/_events/web_framework.py |
Minor formatting-only change. |
tests/tracer/runtime/test_runtime_id.py |
Adds focused subprocess tests for hook registration behavior, matching logic, ordering vs. root span, thread-safety, and fork reset. |
tests/contrib/asgi/test_asgi.py |
Adds ASGI integration coverage that /run refreshes identity exactly once. |
tests/contrib/wsgi/test_wsgi.py |
Adds WSGI integration coverage that /run refreshes identity exactly once. |
releasenotes/notes/aws-lambda-microvm-identity-refresh-3a672cd6bcbad16d.yaml |
Adds a release note entry for the MicroVM identity refresh feature. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
2593fa8 to
4aebb33
Compare
73d9d64 to
53a921c
Compare
4aebb33 to
206cd22
Compare
53a921c to
7b4a217
Compare
206cd22 to
f3ea773
Compare
2c58627 to
99e2b4e
Compare
f3ea773 to
68bf61e
Compare
676adf4 to
18c03c4
Compare
8e26c22 to
cdc53d4
Compare
6e5799f to
75def6a
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cddc13b4a8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 09ba3d964b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1063bc02b4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 25e8bb8778
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
mabdinur
left a comment
There was a problem hiding this comment.
Focused review of fork safety, transition stability, and request-path cost. I left the remaining findings inline.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6d2daa1e70
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
More details
The MicroVM refresh guard prevents concurrent observers from rotating identity more than once and resets after fork. Listener registration remains deferred to the later stacked PR, so this change alone does not activate request-triggered refresh.
🤖 Bits Code Review · Commit ef4471a
Detect the AWS Lambda MicroVM /run hook from the shared WSGI/ASGI web.request.starting event and rotate the runtime ID once per process, before the /run root span is created. - maybe_refresh_identity checks completion first without a lock, matches only POST /aws/lambda-microvms/runtime/v1/run, and refreshes once. /run reaches a process once, so callback failures are logged, not retried; each consumer keeps its own state consistent with get_runtime_id(). - No lock is shared with consumers, and nothing registers the listener here: the top of the stack registers it once every in-scope component can refresh. - WebFrameworkEvents.WEB_REQUEST_STARTING aliases the internal constant. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
/merge |
|
View all feedbacks in Devflow UI.
It will be processed automatically as soon as GitHub reports it as mergeable. View in MergeQueue UI.
devflow unqueued this merge request: It did not become mergeable within the expected time |
|
/code blockers |
|
View all feedbacks in Devflow UI.
Checking merge blockers for #19939...
Detected 1 merge blocker(s) to address: 🔴 Blocking
|
|
/code blockers |
|
View all feedbacks in Devflow UI.
Checking merge blockers for #19939...
Detected 1 merge blocker(s) to address: 🔴 Blocking
|
|
/code blocker |
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
|
Stacked PRs:
/runlistener and identity refreshDescription
This PR adds the MicroVM side of the
web.request.startingevent that #19898 publishes. The method and path check lives in a MicroVM-specific listener instead of the integrations, as asked in r4146791727.maybe_refresh_identity(method, path)matches onlyPOST /aws/lambda-microvms/runtime/v1/runand callsrefresh_identity()once per process.Nothing in this PR registers
maybe_refresh_identity(). #19822 registers it withcore.on()inside its MicroVM check, at the top of the stack, once the tracer, telemetry and runtime metrics can each rebuild on refresh. Merging this PR alone doesn't change runtime behavior.WSGI and Django can both observe the same
/runrequest, so the refresh has to happen exactly once. Aforksafe.Eventrecords that it's done and is checked first without a lock, so after the refresh the listener costs one flag check per request. A lock private to_runtime_id.pyguards the refresh itself, so concurrent observers still rotate the ID once. No other module takes that lock./runreaches a process once, so there's no retry. If a refresh callback fails, the failure is logged and the remaining callbacks still run. Each consumer keeps its own state consistent withget_runtime_id().Smaller changes:
WEB_REQUEST_STARTING_EVENTmoves toddtrace.internal.constants, andWebFrameworkEvents.WEB_REQUEST_STARTINGaliases it. chore(runtime): refresh runtime metric identity and collector state #19822 registers the listener fromddtrace/trace/__init__.py, which can't importddtrace.contrib: its package__init__loadstrace_handlers, which importsddtrace.traceback beforetracerexists.MICROVM_RUN_HOOK_METHODandMICROVM_RUN_HOOK_PATHlive inddtrace.internal.serverless.Testing
tests/tracer/runtime/test_runtime_id.py:test_maybe_refresh_identity_matches_microvm_run_hook,test_maybe_refresh_identity_ignores_other_requests: onlyPOSTto the/runpath refreshes.test_identity_refresh_hook_runs_before_root_span_creation: the refresh happens before the/runroot span is created.test_maybe_refresh_identity_is_thread_safe: concurrent observers rotate the ID once.test_identity_refresh_callback_failure_is_logged_and_not_retriedtest_microvm_refresh_guard_resets_after_forktest_maybe_refresh_identity_noop_outside_microvm,test_identity_refresh_listener_noop_outside_microvm,test_identity_refresh_listener_noop_for_blank_microvm_envtest_import_ddtrace_in_microvm_environment,test_import_ddtrace_outside_microvm_does_not_import_coreIntegration tests:
test_microvm_run_hook_refreshes_identityin bothtests/contrib/wsgi/test_wsgi.pyandtests/contrib/asgi/test_asgi.py: a/runrequest refreshes the identity end to end.tests/contrib/wsgi/test_wsgi.py::test_web_request_starting_isolates_listener_errors: a failing listener doesn't fail the request.Risks
None outside a MicroVM: nothing in this PR registers the listener, #19822 registers it only inside a MicroVM, and
maybe_refresh_identity()returns early. The import tests above check that the no-op path doesn't importddtrace.internal.core. Inside a MicroVM nothing changes until #19822 registers the listener.Additional Notes
An earlier revision shared a refresh lock with consumers (
get_runtime_identity_refresh_lock()) and retried failed callbacks against the same identity. I dropped both after review:Reference