【问题标题】:Capture user info in Sentry在 Sentry 中捕获用户信息
【发布时间】:2016-08-25 05:57:14
【问题描述】:

我最近刚开始在我的 Laravel 5.1 应用程序上使用 Sentry。

我在那里看到了文档和入门资料,参考了capturing user information

他们给出的传递 this 的例子,如下所示:

Raven.setUserContext({
    email: 'foo@example.com'
});

在关注他们的setup instructions for Laravel 之后,我没有看到关于它可以去哪里的参考资料,或者文档中关于如何在配置文件或 Laravel 的任何内容中设置它的任何参考资料。

关于如何设置它以发送用户信息的任何想法?用户在使用我的应用程序时将始终处于登录状态。

【问题讨论】:

    标签: php laravel laravel-5.1 sentry


    【解决方案1】:

    我知道这个问题已经三个月了,如果你已经找到了答案,我们深表歉意。

    我有同样的要求(在 Sentry 中将用户记录为异常的一部分),所以我自己也进行了一些挖掘。

    Raven.setUserContext() 似乎是 JavaScript SDK 特有的函数。 PHP SDK 在 Raven 客户端上有一个 set_user_data($id, $email, $data) 方法,您可以在应用程序的某处使用该方法(很可能在您实际将异常发送到 Sentry 之前的异常处理程序中)。

    这样的事情应该可以工作:

    public function report(Exception $e)
    {
        // Will only enter if statement if request has a user
        if ($user = request()->user()) {
            app('sentry')->set_user_data($user->getAuthIdentifier(), $user->email);
        }
    
        app('sentry')->captureException($e);
    
        return parent::report($e);
    }
    

    【讨论】:

    • 这看起来是个不错的方法。我求助于使用过时的包并稍微修改它,因为这是我能找到的唯一解决方案。不过,我会试一试 - 谢谢!
    • 如何为 react.js-redux 做这个?
    • @Qui-GonJinn 我不知道。这个问题是关于 Laravel 的。
    • @James 这回答了你的问题吗……?
    • @MartinBean TBH 我现在不记得了,那个项目早就消失了!不过,我会假设是这样。
    猜你喜欢
    • 2014-05-08
    • 2021-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-24
    • 1970-01-01
    • 2016-10-26
    相关资源
    最近更新 更多