jenssegers / laravel-rollbar

Rollbar error monitoring integration for Laravel projects
329 stars 99 forks source link

Updates ReadMe with more detail on passing user-specific context #87

Open cameronscott137 opened 7 years ago

cameronscott137 commented 7 years ago

Updates the ReadMe to include:

aginev commented 4 years ago

@cameronscott137 think that this will report the error twice to Rollbar because of the parent::report($exception); which at the end will call

$logger->error(
       $e->getMessage(),
       array_merge($this->context(), ['exception' => $e]
));

Think that the better way is to overwrite the context method from Illuminate\Foundation\Exceptions\Handler like so:

/**
 * Get the default context variables for logging.
 *
 * @return array
 */
protected function context()
{
    $context = [
        'userId' => Auth::id(),
        // 'email' => optional(Auth::user())->email,
    ];

    // If we have authenticated user
    if (Auth::check()) {
        $user = Auth::user();

        $context['person'] = [
            'id'       => $user->id,
            'username' => $user->name,
            'email'    => $user->email,
        ];
    }

    try {
        return array_filter($context);
    } catch (Throwable $e) {
        return [];
    }
}

What do you think?

Regards