Skip to content

chore(serverless): emit MicroVM request start for WSGI & ASGI-based applications - #19898

Open
litianningdatadog wants to merge 1 commit into
tianning.li/1-runtime-identity-refreshfrom
tianning.li/2-wsgi-asgi-integration
Open

litianningdatadog wants to merge 1 commit into
tianning.li/1-runtime-identity-refreshfrom
tianning.li/2-wsgi-asgi-integration

Conversation

@litianningdatadog

@litianningdatadog litianningdatadog commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Stacked PRs:

Description

MicroVMs call the language runtime through a local /run endpoint before the user request is served. The identity refresh stack needs a request-start signal before the framework root span is created; otherwise the first span for a fresh MicroVM run can still pick up the previous runtime ID.

The WSGI and ASGI entry points now recognize the AWS Lambda MicroVM runtime request and emit the existing web.request.starting event before root-span creation. Normal application requests, non-MicroVM environments, and non-matching paths keep the old behavior.

Path construction is deferred until after the POST and MicroVM-environment checks, so ordinary non-POST requests avoid the additional path normalization and concatenation.

The WSGI/Django paths also now:

  • dispatch from automatically instrumented Django WSGI requests, which bypass the generic WSGI middleware;
  • coalesce nested WSGI and Django middleware so one runtime request emits one event; and
  • mark the request only after a matching event was actually dispatched.

Reference

Testing

Added focused WSGI, ASGI, Django WSGI, and runtime-detection coverage for:

  • dispatching web.request.starting for the MicroVM runtime request;

  • preserving normal request behavior;

  • mounted and full-path WSGI/ASGI path representations;

  • skipping the MicroVM environment check for non-POST requests;

  • dispatching the request event before span creation in both WSGI and ASGI middleware;

  • preventing duplicate dispatch through nested WSGI middleware and Django WSGI instrumentation; and

  • MicroVM environment detection for set, unset, and whitespace-only values.

  • ASGI-based Django test shows the run event can be intercepted

image - WSGI-based Flask [test](https://us-east-2.console.aws.amazon.com/cloudwatch/home?region=us-east-2#logsV2:log-groups/log-group/$252Faws$252Flambda-microvms$252Fsample-flask-app/log-events/2026$252F09$252F04$255B18.0$255Dmicrovm-672def42-7c09-3b3d-a1cf-a6bff1be0e64$3FfilterPattern%3DMicroVM%26start%3D1788494400000%26end%3D1788580799000) shows the run event can be intercepted image

Validation:

  • scripts/lint fmt
  • scripts/lint style
  • scripts/lint typing
  • focused ASGI hook tests: 48 passed
  • focused WSGI hook tests: 7 passed
  • MicroVM detector tests: 3 passed
  • focused WSGI regression test: 1 passed in venv 13873ec
  • focused Django WSGI regression tests: 2 passed in venv 7e85837

Risks

Low. The new event is limited to AWS Lambda MicroVM runtime metadata and leaves non-matching ASGI/WSGI requests unchanged. This PR is internal plumbing; customer-facing release-note content belongs with follow-up PR #19939.

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against tianning.li/1-runtime-identity-refresh using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

ddtrace/contrib/_events/web_framework.py                                @DataDog/python-guild @DataDog/apm-idm-python
ddtrace/contrib/internal/asgi/middleware.py                             @DataDog/python-guild @DataDog/apm-idm-python
ddtrace/contrib/internal/django/response.py                             @DataDog/python-guild @DataDog/apm-idm-python
ddtrace/contrib/internal/web.py                                         @DataDog/python-guild @DataDog/apm-idm-python
ddtrace/contrib/internal/wsgi/wsgi.py                                   @DataDog/python-guild @DataDog/apm-idm-python
ddtrace/internal/constants.py                                           @DataDog/apm-core-python
ddtrace/internal/serverless/__init__.py                                 @DataDog/apm-core-python
tests/contrib/asgi/test_asgi.py                                         @DataDog/python-guild @DataDog/apm-idm-python
tests/contrib/django/test_django.py                                     @DataDog/python-guild @DataDog/apm-idm-python
tests/contrib/wsgi/test_wsgi.py                                         @DataDog/python-guild @DataDog/apm-idm-python
tests/internal/test_serverless.py                                       @DataDog/apm-serverless @DataDog/asm-python @DataDog/serverless-aws @DataDog/serverless-azure-and-gcp

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Circular import analysis

⚠️ Existing circular imports

There are 1 circular imports that already exist on the base branch and have not been changed by this PR.

ddtrace.errortracking._handled_exceptions.bytecode_injector -> ddtrace.errortracking._handled_exceptions.callbacks -> ddtrace.errortracking._handled_exceptions.collector -> ddtrace.errortracking._handled_exceptions.bytecode_reporting -> ddtrace.errortracking._handled_exceptions.bytecode_injector

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

There are 205 dependency direction violations that already exist on the base branch and have not been changed by this PR.

Show existing violations (showing 5 of 205 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=132)
ddtrace.appsec._listeners -×-> ddtrace.trace  (product:appsec -> product:tracing, score=130)
ddtrace.internal.ci_visibility.recorder -×-> ddtrace.trace  (product:ci_visibility -> product:tracing, score=130)
ddtrace.profiling.collector.pytorch -×-> ddtrace.trace  (product:profiling -> product:tracing, score=130)
ddtrace.debugging._signal.tracing -×-> ddtrace.trace  (product:debugging -> product:tracing, score=130)

To see all violations, download the layers-base.json and layers-pr.json artifacts from this CI job and run:

uv run --script scripts/import-analysis/layers.py compare layers-base.json layers-pr.json

@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 7398b18 | Docs | View more details | Give us feedback!

@litianningdatadog litianningdatadog changed the title feat(serverless): emit MicroVM request start feat(serverless): emit MicroVM request start for WSGI & ASGI-based applications Aug 27, 2026
@litianningdatadog litianningdatadog added the aws-microvm Work related to AWS MicroVM onboarding label Aug 31, 2026
@litianningdatadog
litianningdatadog force-pushed the tianning.li/2-wsgi-asgi-integration branch 2 times, most recently from 4aebb33 to 206cd22 Compare September 3, 2026 20:32
@litianningdatadog
litianningdatadog force-pushed the tianning.li/2-wsgi-asgi-integration branch from 206cd22 to f3ea773 Compare September 3, 2026 20:47
@litianningdatadog
litianningdatadog force-pushed the tianning.li/2-wsgi-asgi-integration branch from f3ea773 to 68bf61e Compare September 4, 2026 15:37
@litianningdatadog
litianningdatadog requested a balanced review from Copilot September 4, 2026 16:23
@litianningdatadog
litianningdatadog force-pushed the tianning.li/2-wsgi-asgi-integration branch from 68bf61e to 8e26c22 Compare September 4, 2026 16:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The environment detector lacks direct coverage, and the release note announces behavior completed only by a follow-up PR.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds pre-span MicroVM request detection to WSGI and ASGI instrumentation, supporting the runtime identity refresh stack.

Changes:

  • Dispatches web.request.starting for matching MicroVM requests.
  • Adds explicit runtime identity refresh callbacks while preserving fork lineage.
  • Adds focused integration/runtime tests and a release note.
File summaries
File Description
ddtrace/contrib/_events/web_framework.py Defines the request-start event.
ddtrace/contrib/internal/web.py Matches and dispatches MicroVM requests.
ddtrace/contrib/internal/asgi/middleware.py Dispatches before ASGI span creation.
ddtrace/contrib/internal/wsgi/wsgi.py Dispatches before WSGI span creation.
ddtrace/internal/serverless/__init__.py Detects the MicroVM environment.
ddtrace/internal/runtime/__init__.py Adds explicit identity refresh support.
tests/contrib/asgi/test_asgi.py Tests ASGI matching and ordering.
tests/contrib/wsgi/test_wsgi.py Tests WSGI request matching.
tests/tracer/runtime/test_runtime_id.py Tests refresh and fork semantics.
releasenotes/notes/add-lambda-microvm-web-request-starting-ffa6841a15e3c57c.yaml Announces MicroVM request detection.
Review details
  • Files reviewed: 8/8 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread ddtrace/internal/serverless/__init__.py Outdated
Comment thread releasenotes/notes/add-lambda-microvm-web-request-starting-ffa6841a15e3c57c.yaml Outdated
@litianningdatadog
litianningdatadog force-pushed the tianning.li/2-wsgi-asgi-integration branch from 8e26c22 to cdc53d4 Compare September 4, 2026 16:39
@litianningdatadog
litianningdatadog force-pushed the tianning.li/2-wsgi-asgi-integration branch 2 times, most recently from d28bc4e to 0d5cf10 Compare September 21, 2026 20:46
@litianningdatadog litianningdatadog added the changelog/no-changelog A changelog entry is not required for this PR. label Sep 23, 2026
@litianningdatadog
litianningdatadog force-pushed the tianning.li/2-wsgi-asgi-integration branch from 0d5cf10 to 4654514 Compare September 23, 2026 14:38
@litianningdatadog
litianningdatadog requested review from a team as code owners September 23, 2026 18:45
@litianningdatadog
litianningdatadog requested review from Lewis-E, avara1986, brettlangdon, lym953 and quinna-h and removed request for a team September 23, 2026 18:45
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-23T18:53:55.747647Z 24e4d34 Draft marked ready
🔒 Security Review ✅ Completed 2026-09-23T18:50:33.781425Z 24e4d34 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 24e4d34d84

ℹ️ 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".

Comment thread ddtrace/contrib/internal/wsgi/wsgi.py Outdated
Comment thread ddtrace/contrib/internal/wsgi/wsgi.py Outdated
@litianningdatadog
litianningdatadog force-pushed the tianning.li/2-wsgi-asgi-integration branch from 24e4d34 to 2d71731 Compare September 24, 2026 16:18

@jcstorms1 jcstorms1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just looked at the files we own. LGTM

@litianningdatadog
litianningdatadog requested review from a team and mabdinur and removed request for a team September 24, 2026 19:45
@litianningdatadog
litianningdatadog force-pushed the tianning.li/2-wsgi-asgi-integration branch from 2d71731 to bfe3d91 Compare September 25, 2026 15:50
@litianningdatadog
litianningdatadog added this pull request to stack #20582 September 25, 2026 15:50
@litianningdatadog
litianningdatadog force-pushed the tianning.li/2-wsgi-asgi-integration branch from bfe3d91 to a44c5ce Compare September 25, 2026 15:50
@litianningdatadog
litianningdatadog requested a review from a team as a code owner September 25, 2026 21:37
@litianningdatadog
litianningdatadog force-pushed the tianning.li/2-wsgi-asgi-integration branch from a44c5ce to 7398b18 Compare September 25, 2026 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aws-microvm Work related to AWS MicroVM onboarding changelog/no-changelog A changelog entry is not required for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants