Skip to content

chore(http_server): emit pre-request web event - #19799

Closed
litianningdatadog wants to merge 2 commits into
tianning.li/2-flask-web-request-starting-eventfrom
tianning.li/3-http-server-request-starting-event
Closed

chore(http_server): emit pre-request web event#19799
litianningdatadog wants to merge 2 commits into
tianning.li/2-flask-web-request-starting-eventfrom
tianning.li/3-http-server-request-starting-event

Conversation

@litianningdatadog

@litianningdatadog litianningdatadog commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Description

Follow-up to #19779. Adds a stdlib http_server integration for raw http.server handlers that need to emit WEB_REQUEST_STARTING before request handling continues.

The integration wraps http.server.BaseHTTPRequestHandler.parse_request and dispatches the event with (method, path) after the request line parses successfully. It does not create spans. It is default-enabled like other auto-patched integrations and can be disabled with DD_TRACE_HTTP_SERVER_ENABLED=false; it intentionally has no service-name config.

This PR also adds the integration metadata needed for auto-patching, docs discovery, suite selection, and supported-configuration validation. The .riot/requirements/*.txt files are generated locks for the new http_server Riot env across the Python versions selected by select_pys(). The supported-configuration checker now allows no-span integrations to skip DD_{NAME}_SERVICE[_NAME] entries.

Testing

  • scripts/lint fmt ddtrace/_monkey.py ddtrace/contrib/internal/http_server/__init__.py ddtrace/contrib/internal/http_server/patch.py ddtrace/internal/settings/_supported_configurations.py riotfile.py scripts/supported_configurations.py tests/contrib/http_server/__init__.py tests/contrib/http_server/test_http_server_patch.py tests/contrib/http_server/test_microvm_identity_refresh.py
  • scripts/lint style ddtrace/_monkey.py ddtrace/contrib/internal/http_server/__init__.py ddtrace/contrib/internal/http_server/patch.py ddtrace/internal/settings/_supported_configurations.py riotfile.py scripts/supported_configurations.py tests/contrib/http_server/__init__.py tests/contrib/http_server/test_http_server_patch.py tests/contrib/http_server/test_microvm_identity_refresh.py
  • scripts/lint supported-config-check
  • scripts/run-tests --venv 13ed954 tests/contrib/http_server

Release note

No Reno fragment. This is internal runtime-identity plumbing for a no-span integration and does not change trace output by itself. Use changelog/no-changelog.

Additional Notes

Depends on #19779 and #19778.

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against tianning.li/2-flask-web-request-starting-event using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

.riot/requirements/1362718.txt                                          @DataDog/apm-python
.riot/requirements/13ed954.txt                                          @DataDog/apm-python
.riot/requirements/1638d0f.txt                                          @DataDog/apm-python
.riot/requirements/180047f.txt                                          @DataDog/apm-python
.riot/requirements/3cb8c3c.txt                                          @DataDog/apm-python
.riot/requirements/43423a3.txt                                          @DataDog/apm-python
ddtrace/_monkey.py                                                      @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/contrib/internal/http_server/__init__.py                        @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/contrib/internal/http_server/patch.py                           @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/internal/settings/_supported_configurations.py                  @DataDog/apm-python
docs/integrations.rst                                                   @DataDog/python-guild
riotfile.py                                                             @DataDog/apm-python
scripts/integration_registry/registry.yaml                              @DataDog/apm-idm-python
scripts/supported_configurations.py                                     @DataDog/apm-sdk-capabilities-python
supported-configurations.json                                           @DataDog/apm-python
tests/contrib/http_server/__init__.py                                   @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/http_server/test_http_server_patch.py                     @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/http_server/test_microvm_identity_refresh.py              @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/suitespec.yml                                             @DataDog/python-guild
tests/tracer/test_monkey.py                                             @DataDog/apm-sdk-capabilities-python

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 20, 2026

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

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

Show existing violations (showing 5 of 250 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=135)
ddtrace.internal.opentelemetry.trace -×-> ddtrace.trace  (product:opentelemetry -> product:tracing, score=133)
ddtrace.debugging._debugger -×-> ddtrace.trace  (product:debugging -> product:tracing, score=133)
ddtrace.profiling.scheduler -×-> ddtrace.trace  (product:profiling -> product:tracing, score=133)
ddtrace.llmobs._integrations.google_adk -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=133)

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

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 20, 2026

Copy link
Copy Markdown

Circular import analysis

⚠️ Existing circular imports

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

ddtrace.llmobs -> ddtrace.llmobs._evaluators -> ddtrace.llmobs._evaluators.format -> ddtrace.llmobs._experiment -> ddtrace.llmobs
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
ddtrace.appsec._asm_request_context -> ddtrace.appsec._iast._iast_request_context_base -> ddtrace.appsec._iast._iast_env -> ddtrace.appsec._iast.reporter -> ddtrace.appsec._exploit_prevention.stack_traces -> ddtrace.appsec._asm_request_context

@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Aug 20, 2026

Copy link
Copy Markdown

Pipelines  Tests

Unblock PR with BitsAI

⚠️ Warnings

🚦 10 Pipeline jobs failed

DataDog/apm-reliability/dd-trace-py | contrib/http_server 1/4 — 🔧 Needs a code fix, caused by this PR

View in Datadog · View in GitLab

DataDog/apm-reliability/dd-trace-py | contrib/http_server 2/4 — 🔧 Needs a code fix, caused by this PR

View in Datadog · View in GitLab

DataDog/apm-reliability/dd-trace-py | contrib/http_server 3/4 — 🔧 Needs a code fix, caused by this PR

View in Datadog · View in GitLab

View all 10 failed jobs.

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

Useful? React with 👍 / 👎

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

@litianningdatadog litianningdatadog added the changelog/no-changelog A changelog entry is not required for this PR. label Aug 20, 2026
@litianningdatadog litianningdatadog changed the title feat(http_server): emit pre-request web event chore(http_server): emit pre-request web event Aug 20, 2026
@litianningdatadog litianningdatadog added changelog/no-changelog A changelog entry is not required for this PR. and removed changelog/no-changelog A changelog entry is not required for this PR. labels Aug 20, 2026
@pr-commenter

pr-commenter Bot commented Aug 20, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-08-23 21:36:51

Comparing candidate commit 55febfa in PR branch tianning.li/3-http-server-request-starting-event with baseline commit d59e112 in branch tianning.li/2-flask-web-request-starting-event.

📊 Benchmarking dashboard

Found 0 performance improvements and 10 performance regressions! Performance is the same for 612 metrics, 10 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

scenario:httppropagationinject-ids_only

  • 🟥 execution_time [+1.864µs; +2.022µs] or [+9.688%; +10.510%]

scenario:iastaspects-add_aspect

  • 🟥 execution_time [+19.355µs; +21.989µs] or [+19.193%; +21.805%]

scenario:iastaspects-join_aspect

  • 🟥 execution_time [+45.495µs; +50.314µs] or [+21.443%; +23.715%]

scenario:iastaspects-ljust_noaspect

  • 🟥 execution_time [+60.316µs; +65.703µs] or [+20.962%; +22.834%]

scenario:iastaspects-title_aspect

  • 🟥 execution_time [+68.666µs; +72.985µs] or [+25.764%; +27.385%]

scenario:iastaspectsospath-ospathbasename_aspect

  • 🟥 execution_time [+142.177µs; +148.905µs] or [+34.804%; +36.451%]

scenario:iastaspectssplit-rsplit_aspect

  • 🟥 execution_time [+15.589µs; +19.840µs] or [+10.757%; +13.691%]

scenario:span-start

  • 🟥 execution_time [+1.471ms; +1.621ms] or [+9.719%; +10.710%]

scenario:telemetryaddmetric-1-count-metric-1-times

  • 🟥 execution_time [+433.360ns; +476.188ns] or [+16.068%; +17.656%]

scenario:tracer-small

  • 🟥 execution_time [+27.656µs; +29.488µs] or [+8.488%; +9.050%]

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:coreapiscenario-context_with_data_listeners

  • unstable execution_time [-769.225ns; +730.525ns] or [-6.930%; +6.581%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-36.789ns; +30.002ns] or [-5.984%; +4.880%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1698.155ns; +1647.449ns] or [-9.881%; +9.586%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-1244.462ns; +1202.363ns] or [-9.680%; +9.353%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-290.124ns; +372.892ns] or [-7.874%; +10.120%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-277.150ns; +231.509ns] or [-9.456%; +7.899%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-86.840ns; +59.209ns] or [-7.557%; +5.153%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-3702.878ns; +4144.648ns] or [-9.205%; +10.303%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-738.114ns; +789.612ns] or [-9.245%; +9.890%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-59.186µs; +61.829µs] or [-9.248%; +9.661%]

@litianningdatadog
litianningdatadog requested review from brettlangdon and dubloom and a balanced review from Copilot August 20, 2026 20:16

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.

Pull request overview

Adds default-enabled http.server instrumentation that emits the pre-request event without creating spans.

Changes:

  • Wraps successful BaseHTTPRequestHandler.parse_request calls.
  • Registers configuration, auto-patching, documentation, and test-suite metadata.
  • Adds patch lifecycle and event-dispatch coverage.

Reviewed changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
ddtrace/contrib/internal/http_server/patch.py Implements patching and event dispatch.
ddtrace/contrib/internal/http_server/__init__.py Documents the integration.
ddtrace/_monkey.py Enables automatic patching.
supported-configurations.json Registers the enable flag.
ddtrace/internal/settings/_supported_configurations.py Updates generated configuration data.
scripts/supported_configurations.py Supports integrations without service configuration.
scripts/integration_registry/registry.yaml Registers integration metadata.
docs/integrations.rst Adds documentation discovery.
riotfile.py Defines the test environment.
tests/contrib/suitespec.yml Adds suite-selection metadata.
tests/contrib/http_server/__init__.py Marks the test package.
tests/contrib/http_server/test_http_server_patch.py Tests patch lifecycle.
tests/contrib/http_server/test_microvm_identity_refresh.py Tests event dispatch behavior.
.riot/requirements/180047f.txt Adds Python 3.9 test dependencies.
.riot/requirements/3cb8c3c.txt Adds Python 3.10 test dependencies.
.riot/requirements/13ed954.txt Adds Python 3.11 test dependencies.
.riot/requirements/1362718.txt Adds Python 3.12 test dependencies.
.riot/requirements/43423a3.txt Adds Python 3.13 test dependencies.
.riot/requirements/1638d0f.txt Adds Python 3.14 test dependencies.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.



def _get_http_server() -> ModuleType:
# DEV: When patch() is called from the on-import hook, we're running from inside
@litianningdatadog litianningdatadog added the aws-microvm Work related to AWS MicroVM onboarding label Aug 21, 2026
@litianningdatadog
litianningdatadog force-pushed the tianning.li/2-web-request-starting-event branch 2 times, most recently from 55acf22 to d59e112 Compare August 23, 2026 20:47
@litianningdatadog
litianningdatadog force-pushed the tianning.li/3-http-server-request-starting-event branch from 5acedc0 to 55febfa Compare August 23, 2026 21:02
@litianningdatadog
litianningdatadog deleted the tianning.li/3-http-server-request-starting-event branch August 23, 2026 21:15
@litianningdatadog

Copy link
Copy Markdown
Contributor Author

Renamed the branch to tianning.li/2-1-http-server-request-starting-event; GitHub closed this PR when the old head ref disappeared. Replacement PR: #19817.

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.

2 participants