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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass returned sentry id to view #3

Closed
jtraulle opened this issue Mar 27, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@jtraulle
Copy link

commented Mar 27, 2018

Hi,

First of all, thanks for this integration of sentry with CakePHP 3.5+ 馃槏
I was wondering if it will be possible to get back the incident/issue id returned by raven and to pass it to my error view.

Is it possible to do that ? Can you guide me ?

Thanks again 馃檪

@o0h

This comment has been minimized.

Copy link
Collaborator

commented Mar 29, 2018

Thank you for your feedback 馃槂

The plugin allows you to inject send_callback option to Raven client.
One of the my ideas is receiving last_event_id in send_callback and pass the value via session value.

ex)

// in app.php, setup callback closure for receiving event id from Raven.
'Sentry' => [
    'dsn' => env('SENTRY_DSN'),
    'options' => [
        'send_callback' => function ($data) {
            $request = \Cake\Http\ServerRequestFactory::fromGlobals();
            $session = $request->getSession();
            $session->write('last_event_id', $data['event_id']);
        }
    ],
],
// in ErrorController, set event-id in viewVars.
public function beforeFilter(Event $event)
{
    $sentryLastEventId = $this->request->getSession()->read('last_event_id');
    $this->set('sentry_last_event_id', $sentryLastEventId);
}

// in ErrorTemplate(error400.ctp, error500.ctp or custom elements), echo event-id
<?= $sentry_last_event_id ?>

@o0h o0h added the question label Mar 29, 2018

@jtraulle

This comment has been minimized.

Copy link
Author

commented Apr 1, 2018

Many thanks @o0h !
It worked flawlessly 馃檪

That way, I am able to trigger the User Feedback component from Sentry to allow users to submit details about what they were doing before the exception/error. I have also passed name and email to my view in beforeFilter() event to be able to auto-populate name/email from the authenticated user to the Sentry User Feedback dialog.

I think these kind of examples could be added in the README 馃槈
I can submit a PR if you don't wan't to do it.

Thanks again 馃憤

@o0h

This comment has been minimized.

Copy link
Collaborator

commented Apr 17, 2018

Sorry not to have answered sooner 馃槩

I'm glad to hear it went well in its approach.
And to update README.md for send_callback hook sounds nice also for me, I'll do it 馃憤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can鈥檛 perform that action at this time.