Problem/Motivation
Depends on #3352851: Allow assertions on the number of database queries run during tests which adds assertions for database queries (and cache operations) to PerformanceTestTrait.
This issue adds open telemetry spans for the database queries too - this means you can go to the Grafana dashboard, click on a trace, and see every query that was recorded for the request.
Because we cumulatively record database queries, if there is a redirect, AJAX requests, asset or image style route requests while recording, it will include those database queries too, so you get a complete view of what was executed as a result of the thing you were testing.
A potential follow-up would be to add EXPLAIN output for each of the queries too, but we might want to do that after fully separating out cache and other database queries, since there's no point EXPLAIN-ing dozens of identical cache gets #3396196: Separate cache operations from database queries in OpenTelemetry and assertions.
Steps to reproduce
If you want to manually test this, and have an existing core install based on ddev that can run functional javascript tests, you can do the following:
$ ddev add tag1consulting/gander
$ ddev restart
Then run any test from the Umami OpenTelemetry tests, e.g.:
../vendor/bin/phpunit profiles/demo_umami/tests/src/FunctionalJavascript/OpenTelemetryNodePagePerformanceTest.php --filter=warm
You can then go to http://localhost:3000/d/teMVIdjVz/umami?orgId=1&refresh=30s and browse through the traces.
https://github.com/tag1consulting/ddev-gander
Once it's merged, the same thing will be available via core branch runs on http://grafana.tag1demo.tag1.io/d/teMVIdjVz/umami?orgId=1&refresh=30s
Proposed resolution
The database API has query start/end events, we can use those verbatim to create open telemetry spans within PerformanceTestTrait.
It will then be possible to go to to the grafana dashboard, click on a trace, and see all the queries executed, the query string, the caller etc.
Remaining tasks
User interface changes

API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | Screenshot from 2023-11-28 23-26-27.png | 275.01 KB | catch |
Issue fork drupal-3377657
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
catchComment #3
catchComment #5
catchImplemented this. Only a lines on top of #3352851: Allow assertions on the number of database queries run during tests.
Comment #6
catchComment #7
catchAdded testing instructions to the issue summary.
Comment #8
mondrakeInteresting... maybe in the future we could build over #3384999: Introduce a Schema::executeDdlStatement method and the dynamic queries API to provide more metadata as to the type of statement being executed - Data Definition (DDL), Data Manipulation (DML), etc...
See https://github.com/doctrine/dbal/blob/3.7.x/src/Connection.php#L1163-L1182 for definitions
Comment #9
catchIf possible it would be great to at least get INSERT vs SELECT into the query events, both for assertions and for scannability here, but I'm not sure if we have access to that in the spot where those are populated.
Comment #10
mondrakeWe could by implementing some self describing metadata in the Database\Query classes and their extensions, and passing those into the events. Not immediate, but surely possible.
Comment #11
smustgrave commentedbased on the IS this is postponed on #3352851: Allow assertions on the number of database queries run during tests which is up for review but may be out of my wheelhouse but will try and keep an eye on it.
Comment #12
catch#3352851: Allow assertions on the number of database queries run during tests landed.
Comment #13
catchComment #14
smustgrave commentedMuch easier to review. THanks for also updating issue summary.
Comment #15
heddnYou got to it before me. But +1 on RTBC.
Comment #16
fabianx commentedRTBC + 1
Comment #17
alexpottCommitted and pushed 0907775505 to 11.x and 571aeb51d8 to 10.2.x. Thanks!