Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Laravel Debugbar Logging Middleware #567

Open
wants to merge 2 commits into
base: 2.0
Choose a base branch
from

Conversation

cheack
Copy link

@cheack cheack commented Oct 18, 2023

This pull request introduces middleware support for Laravel Debugbar, extending functionality by adding a middleware stack to log queries and measure query execution time.

Example queries:

app('em')->getConnection()->executeQuery("SELECT 'raw query'");
app('em')->getConnection()->executeQuery("SELECT :query", ['query' => 'prepared query']);
app('em')->getConnection()->executeQuery('SELECT pg_sleep(1)');
app('em')->getConnection()->executeQuery('SELECT pg_sleep(2)');
User::pluck('id');

Result:
image

Usage (doctrine.php config):

'middlewares' => [
    \LaravelDoctrine\ORM\DBAL\Middleware\LaravelDebugbarLogging\Middleware::class
]

I'm going to add the tests later, after one of the reviewers confirms that my changes make sense.

$result = $callable();
$end = microtime(true);

event(new QueryExecuted($sql, $params ?: [], ($end - $start) * 1000, app(DatabaseConnection::class)));
Copy link
Member

Choose a reason for hiding this comment

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

This is the wrong connection, most likely. And for us without Illuminate\Database\Connection in container at all will it crash 😭

Need to subclass this Connection with a "proxy" into the doctrine connection or something 🤔

Copy link
Author

@cheack cheack Oct 19, 2023

Choose a reason for hiding this comment

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

In fact, there will be a valid connection here, which is specified in the doctrine.managers.default.connection config, which in turn is configured in the database.connections config.
If there is no Illuminate\Database\Connection yet on this step, it will be created with above config.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds to me you have \Illuminate\Database\DatabaseServiceProvider enabled in config/app.php?

I do not, and it would be required for this to work, which seems weird.

@TomHAnderson
Copy link
Contributor

@cheack Do you have an interest in pursuing this PR?

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.

3 participants