Skip to content

Commit 22f74d4

Browse files
authored
Merge pull request #32 from getsentry/feature/transactions
Add transaction name support
2 parents 9a11bbb + 9834d75 commit 22f74d4

File tree

6 files changed

+95
-18
lines changed

6 files changed

+95
-18
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"require": {
1515
"php": ">=5.2.4",
1616
"illuminate/support": "4.*|5.*",
17-
"sentry/sentry": ">=0.16.0"
17+
"sentry/sentry": ">=1.5.0"
1818
},
1919
"require-dev": {
2020
"friendsofphp/php-cs-fixer": "^1.8.0",

examples/laravel-4.2/app/controllers/HomeController.php

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,38 @@
22

33
class HomeController extends BaseController {
44

5-
/*
6-
|--------------------------------------------------------------------------
7-
| Default Home Controller
8-
|--------------------------------------------------------------------------
9-
|
10-
| You may wish to use controllers instead of, or in addition to, Closure
11-
| based routes. That's great! Here is an example controller method to
12-
| get you started. To route to this controller, just add the route:
13-
|
14-
| Route::get('/', 'HomeController@showWelcome');
15-
|
16-
*/
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Default Home Controller
8+
|--------------------------------------------------------------------------
9+
|
10+
| You may wish to use controllers instead of, or in addition to, Closure
11+
| based routes. That's great! Here is an example controller method to
12+
| get you started. To route to this controller, just add the route:
13+
|
14+
| Route::get('/', 'HomeController@showWelcome');
15+
|
16+
*/
1717

18-
public function showWelcome()
19-
{
20-
return View::make('hello');
21-
}
18+
public function verifyCredentials()
19+
{
20+
Log::info('Verifying credentials');
21+
$user = DB::table('migrations')->where('migration', 'a migration')->first();
22+
throw new Exception('No credentials passed!');
23+
}
24+
25+
26+
public function authenticateUser()
27+
{
28+
Log::info('Authenticating the current user');
29+
$this->verifyCredentials();
30+
}
31+
32+
public function showWelcome($id)
33+
{
34+
Log::info('Rendering a page thats about to error');
35+
$this->authenticateUser();
36+
return View::make('hello');
37+
}
2238

2339
}

examples/laravel-4.2/app/routes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ function authenticateUser()
3030
Log::info('Rendering a page thats about to error');
3131
authenticateUser();
3232
});
33+
34+
Route::get('/welcome/{id}', 'HomeController@showWelcome');
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Http\Controllers\Controller;
6+
7+
class HomeController extends Controller {
8+
9+
/*
10+
|--------------------------------------------------------------------------
11+
| Default Home Controller
12+
|--------------------------------------------------------------------------
13+
|
14+
| You may wish to use controllers instead of, or in addition to, Closure
15+
| based routes. That's great! Here is an example controller method to
16+
| get you started. To route to this controller, just add the route:
17+
|
18+
| Route::get('/', 'HomeController@showWelcome');
19+
|
20+
*/
21+
22+
public function verifyCredentials()
23+
{
24+
\Log::info('Verifying credentials');
25+
$user = DB::table('users')->where('name', 'John')->first();
26+
throw new Exception('No credentials passed!');
27+
}
28+
29+
30+
public function authenticateUser()
31+
{
32+
\Log::info('Authenticating the current user');
33+
$this->verifyCredentials();
34+
}
35+
36+
public function showWelcome($id)
37+
{
38+
\Log::info('Rendering a page thats about to error');
39+
// $this->authenticateUser();
40+
return view('hello');
41+
}
42+
43+
}

examples/laravel-5.2/app/Http/routes.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ function authenticateUser()
2929
Route::get('/', function () {
3030
Log::info('Rendering a page thats about to error');
3131
authenticateUser();
32-
});
32+
})->name('index');
33+
34+
Route::get('/welcome/{id}', 'HomeController@showWelcome')->name('welcome');

src/Sentry/SentryLaravel/SentryLaravelEventHandler.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ public function onWildcardEvent()
3030
$args = func_get_args();
3131
$data = null;
3232
$level = 'info';
33+
if ($name === 'Illuminate\Routing\Events\RouteMatched') {
34+
$route = $args[0]->route;
35+
$routeName = $route->getActionName();
36+
if ($routeName && $routeName !== 'Closure') {
37+
$this->client->transaction->push($routeName);
38+
}
39+
} elseif ($name === 'router.matched') {
40+
$route = $args[0];
41+
$routeName = $route->getActionName();
42+
if ($routeName && $routeName !== 'Closure') {
43+
$this->client->transaction->push($routeName);
44+
}
45+
}
46+
3347
if ($name === 'Illuminate\Database\Events\QueryExecuted') {
3448
$name = 'sql.query';
3549
$message = $args[0]->sql;

0 commit comments

Comments
 (0)