Skip to content

refactor(contrib): decouple database monitoring setup from integrations - #22047

Draft
quinna-h wants to merge 1 commit into
quinna/db-events-migrationfrom
codex/dbm-boundary-proof
Draft

quinna-h wants to merge 1 commit into
quinna/db-events-migrationfrom
codex/dbm-boundary-proof

Conversation

@quinna-h

@quinna-h quinna-h commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

Follow-up to #21859 that removes direct DBM implementation imports from database integrations.

Integrations declare query argument layouts and driver-specific comment adapters. DBM registers through the existing integration hooks and owns propagation configuration, comment generation, correlation, and listener lifecycle. Tracing continues to own database spans.

Shared database contracts move to ddtrace.internal.database, with compatibility imports retained. Legacy cursor interfaces, explicit propagation suppression, and driver-specific query representations are preserved.

Customer impact

Testing

Risks

Additional Notes

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against quinna/db-events-migration using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

ddtrace/_trace/subscribers/database.py                                  @DataDog/apm-python-guild @DataDog/apm-idm-python
ddtrace/contrib/_events/dbapi.py                                        @DataDog/apm-python-guild @DataDog/apm-idm-python
ddtrace/contrib/dbapi.py                                                @DataDog/apm-python-guild @DataDog/apm-idm-python
ddtrace/contrib/internal/aiomysql/patch.py                              @DataDog/apm-python-guild @DataDog/apm-idm-python
ddtrace/contrib/internal/asyncpg/patch.py                               @DataDog/apm-python-guild @DataDog/apm-idm-python
ddtrace/contrib/internal/django/database.py                             @DataDog/apm-python-guild @DataDog/apm-idm-python
ddtrace/contrib/internal/django/patch.py                                @DataDog/apm-python-guild @DataDog/apm-idm-python
ddtrace/contrib/internal/mysql/patch.py                                 @DataDog/apm-python-guild @DataDog/apm-idm-python
ddtrace/contrib/internal/mysqldb/patch.py                               @DataDog/apm-python-guild @DataDog/apm-idm-python
ddtrace/contrib/internal/psycopg/patch.py                               @DataDog/apm-python-guild @DataDog/apm-idm-python
ddtrace/contrib/internal/pymongo/patch.py                               @DataDog/apm-python-guild @DataDog/apm-idm-python
ddtrace/contrib/internal/pymysql/patch.py                               @DataDog/apm-python-guild @DataDog/apm-idm-python
ddtrace/internal/database.py                                            @DataDog/apm-core-python
ddtrace/propagation/_database_monitoring.py                             @DataDog/apm-sdk-capabilities
docs/contributing-integrations.rst                                      @DataDog/apm-python-guild
pyproject.toml                                                          @DataDog/apm-python-guild
tests/contrib/asyncpg/test_asyncpg.py                                   @DataDog/apm-python-guild @DataDog/apm-idm-python
tests/contrib/dbapi/test_database_boundary.py                           @DataDog/apm-python-guild @DataDog/apm-idm-python
tests/contrib/django/test_django_dbm.py                                 @DataDog/apm-python-guild @DataDog/apm-idm-python
tests/contrib/pymysql/test_pymysql.py                                   @DataDog/apm-python-guild @DataDog/apm-idm-python
tests/contrib/suitespec.yml                                             @DataDog/apm-python-guild
tests/internal/test_integration_hooks.py                                @DataDog/apm-core-python

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

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

Show existing violations (showing 5 of 22 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=101)
ddtrace.llmobs._integrations.bedrock_agents -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=99)
ddtrace.llmobs._integrations.base -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=99)
ddtrace.internal.span_bus -×-> ddtrace._trace.span  (internal-core -> product:tracing, score=35)
ddtrace.llmobs._llmobs -×-> ddtrace._trace.span  (product:llmobs -> product:tracing, score=33)

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-prod-us1

datadog-datadog-prod-us1 Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Pipelines  Tests

✨ Unblock PR with BitsAI

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 12 Pipeline jobs failed

System Tests | tracer-release / End-to-end #2 / flask-poc 2 — ❌ 1 test failed · 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

❌ tests.integrations.test_dbm.Test_Dbm_Comment_Python_Asyncpg.test_dbm_comment[flask-poc] from system_tests_suite
AssertionError: Request: http://localhost:7777/stub_dbm?integration=asyncpg&operation=execute wasn't successful.
assert 500 == 200
 +  where 500 = HttpResponse(status_code:500, headers:{'Server': 'gunicorn', 'Date': 'Mon, 23 Nov 2026 23:47:02 GMT', 'Connection': 'k...and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>\n).status_code
 +    where HttpResponse(status_code:500, headers:{'Server': 'gunicorn', 'Date': 'Mon, 23 Nov 2026 23:47:02 GMT', 'Connection': 'k...and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>\n) = <tests.integrations.test_dbm.Test_Dbm_Comment_Python_Asyncpg object at 0x7cd6100f9190>.r

self = <tests.integrations.test_dbm.Test_Dbm_Comment_Python_Asyncpg object at 0x7cd6100f9190>

    def test_dbm_comment(self):
>       assert self.r.status_code == 200, f"Request: {self.r.request.url} wasn't successful."
E       AssertionError: Request: http://localhost:7777/stub_dbm?integration=asyncpg&operation=execute wasn't successful.
...
System Tests | tracer-release / End-to-end #2 / uds-flask 2 — ❌ 1 test failed · 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

❌ tests.integrations.test_dbm.Test_Dbm_Comment_Python_Asyncpg.test_dbm_comment[uds-flask] from system_tests_suite
AssertionError: Request: http://localhost:7777/stub_dbm?integration=asyncpg&operation=execute wasn't successful.
assert 500 == 200
 +  where 500 = HttpResponse(status_code:500, headers:{'Server': 'gunicorn', 'Date': 'Mon, 23 Nov 2026 23:47:35 GMT', 'Connection': 'k...and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>\n).status_code
 +    where HttpResponse(status_code:500, headers:{'Server': 'gunicorn', 'Date': 'Mon, 23 Nov 2026 23:47:35 GMT', 'Connection': 'k...and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>\n) = <tests.integrations.test_dbm.Test_Dbm_Comment_Python_Asyncpg object at 0x79b7005760c0>.r

self = <tests.integrations.test_dbm.Test_Dbm_Comment_Python_Asyncpg object at 0x79b7005760c0>

    def test_dbm_comment(self):
>       assert self.r.status_code == 200, f"Request: {self.r.request.url} wasn't successful."
E       AssertionError: Request: http://localhost:7777/stub_dbm?integration=asyncpg&operation=execute wasn't successful.
...
System Tests | tracer-release / End-to-end #2 / uwsgi-poc 2 — ❌ 1 test failed · 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

❌ tests.integrations.test_dbm.Test_Dbm_Comment_Python_Asyncpg.test_dbm_comment[uwsgi-poc] from system_tests_suite
AssertionError: Request: http://localhost:7777/stub_dbm?integration=asyncpg&operation=execute wasn't successful.
assert 500 == 200
 +  where 500 = HttpResponse(status_code:500, headers:{'Content-Type': 'text/html; charset=utf-8', 'Content-Length': '265'}, text:<!do...and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>\n).status_code
 +    where HttpResponse(status_code:500, headers:{'Content-Type': 'text/html; charset=utf-8', 'Content-Length': '265'}, text:<!do...and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>\n) = <tests.integrations.test_dbm.Test_Dbm_Comment_Python_Asyncpg object at 0x70a24fc35d60>.r

self = <tests.integrations.test_dbm.Test_Dbm_Comment_Python_Asyncpg object at 0x70a24fc35d60>

    def test_dbm_comment(self):
>       assert self.r.status_code == 200, f"Request: {self.r.request.url} wasn't successful."
E       AssertionError: Request: http://localhost:7777/stub_dbm?integration=asyncpg&operation=execute wasn't successful.
...

View all 12 failed jobs.

ℹ️ Info

No other issues found (see more)

❄️ No new flaky tests detected

Useful? React with 👍 / 👎

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

@pr-commenter

pr-commenter Bot commented Nov 24, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-24 00:10:08

Comparing candidate commit 9d8f75e in PR branch codex/dbm-boundary-proof with baseline commit 52de33a in branch quinna/db-events-migration.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 638 metrics, 10 unstable metrics, 1 flaky benchmarks without significant changes.

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 ----------------------------------'

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 [-629.368ns; +775.181ns] or [-5.828%; +7.179%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-38.837ns; +36.232ns] or [-6.004%; +5.601%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1851.418ns; +1838.148ns] or [-9.142%; +9.077%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-1804.873ns; +1751.421ns] or [-9.289%; +9.014%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-335.618ns; +409.608ns] or [-7.704%; +9.402%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-218.962ns; +225.547ns] or [-7.915%; +8.153%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-81.692ns; +94.135ns] or [-5.937%; +6.841%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-3731.494ns; +5287.146ns] or [-7.698%; +10.907%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-970.862ns; +849.226ns] or [-9.403%; +8.225%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-58.812µs; +53.712µs] or [-10.002%; +9.135%]

Known flaky benchmarks

These benchmarks are marked as flaky and will not trigger a failure. Modify FLAKY_BENCHMARKS_REGEX to control which benchmarks are marked as flaky.

Known flaky benchmarks without significant changes:

  • scenario:packagespackageforrootmodulemapping-cache_off

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