【发布时间】:2021-05-21 17:10:04
【问题描述】:
正如 Sentry Docs 中所解释的,我正在尝试向我的 PHP 应用程序添加一些上下文: https://docs.sentry.io/platforms/php/enriching-events/context/
我已将 configureScope 置于异常中,但由于我只在没有上下文的情况下收到错误,所以我问自己它是否是设置它的正确位置。我进行了搜索,发现的所有信息都是关于特定框架的。
注意:在你问之前,会话数据不为空。
<?php
require '../vendor/autoload.php';
Sentry\init([
'dsn' => 'https://.......<secret>.........',
'environment' => Environment::get(),
]);
try {
new Application();
} catch (\Throwable $exception) {
Sentry\configureScope(function (Sentry\State\Scope $scope): void {
$scope->setExtra('email', Session::get('user_email'));
$scope->setExtra('cart', Session::get('cart'));
$scope->setExtra('token', Session::get('token'));
});
Sentry\captureException($exception);
}
【问题讨论】:
-
您好,我已经尝试了您的确切代码,它运行良好,您没有提及您使用的 SDK 版本,如果您使用的是自托管版本或只是哨兵,也没有提及.io,这可能很重要,但通常您显示的代码有效。确保您滚动到 Sentry UI 中的“附加数据”部分并且没有丢失它:)