Skip to content

Commit

Permalink
chore: add basic user details to sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
daveroverts committed Feb 22, 2022
1 parent 1e793ab commit 031ec1b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Kernel extends HttpKernel
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\SentryUser::class
],

'api' => [
Expand Down
33 changes: 33 additions & 0 deletions app/Http/Middleware/SentryUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Sentry\State\Scope;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class SentryUser
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next)
{
if (Auth::check() && app()->bound('sentry')) {
\Sentry\configureScope(function (Scope $scope): void {
$scope->setUser([
'id' => Auth::user()->id,
'email' => Auth::user()->email,
'name' => Auth::user()->full_name,
]);
});
}

return $next($request);
}
}

0 comments on commit 031ec1b

Please sign in to comment.