Skip to content
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

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

Open
wants to merge 1 commit into
base: master
from

Conversation

@cameronscott137
Copy link

cameronscott137 commented Jun 6, 2017

Updates the ReadMe to include:

  • How to pass user-specific data using Laravel's Auth facade.
  • How to pass only exceptions that are not included within the user's $dontReport array.
Updates the readme to include:

* How to pass user-specific data using Laravel's `Auth` facade.
* How to pass only exceptions that are not included within the user's `$dontReport` array.
@aginev

This comment has been minimized.

Copy link

aginev commented Oct 16, 2019

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.