Skip to content

Commit b45a498

Browse files
stayalliveJean85
andauthored
Add the execution time to the query breadcrumb (#283)
* Add the execution time to the query breadcrumb * Fix docblock typo Co-Authored-By: Alessandro Lai <[email protected]>
1 parent 5f329a4 commit b45a498

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/Sentry/Laravel/EventHandler.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,7 @@ protected function routeMatchedHandler(RouteMatched $match)
189189
*/
190190
protected function queryHandler($query, $bindings, $time, $connectionName)
191191
{
192-
$data = ['connectionName' => $connectionName];
193-
194-
if ($this->recordSqlBindings) {
195-
$data['bindings'] = $bindings;
196-
}
197-
198-
Integration::addBreadcrumb(new Breadcrumb(
199-
Breadcrumb::LEVEL_INFO,
200-
Breadcrumb::TYPE_USER,
201-
'sql.query',
202-
$query,
203-
$data
204-
));
192+
$this->addQueryBreadcrumb($query, $bindings, $time, $connectionName);
205193
}
206194

207195
/**
@@ -211,17 +199,34 @@ protected function queryHandler($query, $bindings, $time, $connectionName)
211199
*/
212200
protected function queryExecutedHandler(QueryExecuted $query)
213201
{
214-
$data = ['connectionName' => $query->connectionName];
202+
$this->addQueryBreadcrumb($query->sql, $query->bindings, $query->time, $query->connectionName);
203+
}
204+
205+
/**
206+
* Helper to add an query breadcrumb.
207+
*
208+
* @param string $query
209+
* @param array $bindings
210+
* @param float|null $time
211+
* @param string $connectionName
212+
*/
213+
private function addQueryBreadcrumb($query, $bindings, $time, $connectionName)
214+
{
215+
$data = ['connectionName' => $connectionName];
216+
217+
if ($time !== null) {
218+
$data['executionTimeMs'] = $time;
219+
}
215220

216221
if ($this->recordSqlBindings) {
217-
$data['bindings'] = $query->bindings;
222+
$data['bindings'] = $bindings;
218223
}
219224

220225
Integration::addBreadcrumb(new Breadcrumb(
221226
Breadcrumb::LEVEL_INFO,
222227
Breadcrumb::TYPE_USER,
223228
'sql.query',
224-
$query->sql,
229+
$query,
225230
$data
226231
));
227232
}

0 commit comments

Comments
 (0)