-
-
Notifications
You must be signed in to change notification settings - Fork 178
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] Add Laravel event QueryExecuted support (Sentry support) #501
base: 1.7
Are you sure you want to change the base?
Conversation
$executionTime = microtime(true) - $this->start; | ||
// TODO get connection name | ||
// this class is Laravel connection wrapper (QueryExecuted needs getName()) | ||
$object = new class { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should actually be a \Illuminate\Database\Connection
instance. Though implementing that seems like a pretty huge task.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The laravel-telescope QueryWatcher uses the ->connection->prepareBindings on this event: https://github.com/laravel/telescope/blob/e39423d3ee18898eeb1e0adf2fbe7b74a4cc4996/src/Watchers/QueryWatcher.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have 2 options i guess.
- extend my anonymous object (add prepareBindings)
- try to implement ConnectionInterface with empty methods. This methots could be extended in future if it will be nessesery.
I will try the 2nd option. Create a wrapper for DoctrineConnection with Laravel ConnectionInterface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. Could you make some tests for this too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. Could you make some tests for this too?
I've check Sentry support and it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about PHPUnit test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added few tests.
I would do it more cleanly without public properties and with DI for EventDispatcher mocking ability: But this feature is not a Logger. You are dispatching an event, which means that Illuminate Query has been executed and some applications and packages handle this event, and in some cases this can be fatal. So, IMHO, this feature makes sense, but this is not a logger. You can use the Sentry SDK to create a some SentryLogger and send queries through it... |
@rosamarsky Thank you for your proposal. I used them. I know it is not a Logger. But I think it fits there. It is optional developers can enable it optionaly. Implement this like a standard event is better because it could support more libraries, solutions... So it solve Sentry SDK support (error tracing and performance monitoring) and it could support Laravel Telescope etc. |
{ | ||
$this->start = microtime(true); | ||
$this->query = $sql; | ||
$this->params = $params; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using an array as binding (for IN clauses) this will break:
PDO::quote(): Argument #1 ($string) must be of type string, array given
Telescope QueryWatcher
tries to quote values that are not int/float:
if ($binding === null) {
$binding = 'null';
} elseif (! is_int($binding) && ! is_float($binding)) {
$binding = $this->quoteStringBinding($event, $binding);
}
Using a join()
makes it work while keeping the query readable:
Changes proposed in this pull request: