Did you try just copy pasting the code from the example page here? https://docs.sentry.io/platforms/php/guides/laravel/enriching-events/tags/
Jan 16, 2022
4
Level 12
Add Sentry tags in exception
I hope there is somebody who is working with sentry and have a good idea for me. I try to add tags for some exceptions in my laravel. I know it worked in the past, but i cant remember how. This is the last thing I tried:
class MyTestException extends Exception
{
public function __construct($message = "", $code = 0, Throwable $previous = null)
{
app('sentry')->withScope(function (\Sentry\State\Scope $scope) {
$scope->setTag('saysometing','hello world');
});
parent::__construct($message, $code, $previous);
}
}
I want to search later at sentry for tags.
Level 12
Ok. The following code works, but maybe have somebody an idea, if it is better to place the code anywhere else or is the constructor ok for this?
use Exception;
use Throwable;
use Sentry\State\Scope;
use function Sentry\configureScope;
class MyTestException extends Exception
{
public function __construct($message = "", $code = 0, Throwable $previous = null)
{
configureScope(function (Scope $scope) {
$scope->setTag('saysomething', 'hello world');
});
parent::__construct($message, $code, $previous);
}
}
Please or to participate in this conversation.