getsentry / sentry-laravel

The official Laravel SDK for Sentry (sentry.io)
https://sentry.io
MIT License
1.26k stars 188 forks source link

How to send exceptions to sentry with post/get/delete/put request data also? #220

Closed novaknole closed 5 years ago

novaknole commented 5 years ago

I'm using This package for my laravel 5.8 .

I use the following code in report.php file.

public function report(Exception $exception)
    {
        if (app()->bound('sentry')){
            if($user = request()->user){
                app('sentry')->configureScope(function (Scope $scope) use ($user): void  {
                    $scope->setUser(["id" => $user->id, 'email' => $user->email, "name" => $user->name]);
                });
            }

            app('sentry')->captureException($exception);
        }

        parent::report($exception);
    }

The thing is I also want to send request data (doesn't matter if it's post/put/get/delete or whatever request) to sentry. but couldn't find docs for that . I couldn't find anything. could you provide me with docs or sample code how do I achieve that? I found tags_context but didn't help , because it's something else.

Thank you.

stayallive commented 5 years ago

Hi @novaknole, this is a bit of a tricky one and something we don't have implemented (yet) with an easy to flip switch.

You can however put any data you like via the setExtra method on the scope.

However be very careful with this since you are very easily sending personally identifiable data to Sentry and possibly even secret values like passwords or authentication tokens. Something to keep in mind when doing this! There is some server side obfuscation but that might not catch all the secrets, so be mindful.

I also discussed this with the PHP team and it might be a nice (optional) addition to the Laravel (and base PHP) SDK to implement an easier way to do this so I marked this as a feature request, thanks!

novaknole commented 5 years ago

I was searching other issues on this project and found many interesting thing.

1) how did this man make it possible? Image: http://joxi.net/GrqgnBRtQ8OY72 . here was his issue https://github.com/getsentry/sentry-laravel/issues/63

stayallive commented 5 years ago

Hey @novaknole, sorry for my late reply.

You are correct on version 1.x on the base SDK (and thus 0.11.x of the laravel integration) the request body was sent with the request.

There is an open issue re-implementing the feature: getsentry/sentry-php#803 (open PR implementing it: getsentry/sentry-php#807)

I will close this issue since it's not a Laravel integration issue, you can follow the progress on the issue mentioned above! It will also become available for Laravel once it's completed.