Sentry-laravel: Your configuration files are not serializable

Created on 23 Aug 2019  路  6Comments  路  Source: getsentry/sentry-laravel

config/sentry.php

<?php

use Sentry\Event;

return [

    'dsn' => env('SENTRY_LARAVEL_DSN', env('SENTRY_DSN')),

    'before_send' => function (Event $event): ?Event {
        // literally anything
        return $event;
     },
];
php artisan config:cache

Screenshot from 2019-08-23 11-24-53

support

Most helpful comment

Yes, that is because you are using a closure in your configuration file which is not allowed :)

This is a Laravel limitation (and a good one because serializing closures is a hack).

You can get around this limitation by doing the following:

<?php

namespace App\Exceptions;

use Sentry\Event;

class Sentry
{
    public static function before(Event $event): ?Event
    {
        // literally anything

        return $event;
    }
}

Which you can set in your configuration like:

<?php

return [

    'dsn' => env('SENTRY_LARAVEL_DSN', env('SENTRY_DSN')),

    'before_send' => [App\Exceptions\Sentry::class, 'before'],

];

This works because we allow PHP callables to be passed for all callbacks.

All 6 comments

Yes, that is because you are using a closure in your configuration file which is not allowed :)

This is a Laravel limitation (and a good one because serializing closures is a hack).

You can get around this limitation by doing the following:

<?php

namespace App\Exceptions;

use Sentry\Event;

class Sentry
{
    public static function before(Event $event): ?Event
    {
        // literally anything

        return $event;
    }
}

Which you can set in your configuration like:

<?php

return [

    'dsn' => env('SENTRY_LARAVEL_DSN', env('SENTRY_DSN')),

    'before_send' => [App\Exceptions\Sentry::class, 'before'],

];

This works because we allow PHP callables to be passed for all callbacks.

Because I have not heard back I am going to assume my directions were sufficient and the problem was solved, closing this issue, feel free to reopen or open a new one if there are still unsolved issues.

Yes, that is because you are using a closure in your configuration file which is not allowed :)

This is a Laravel limitation (and a good one because serializing closures is a hack).

You can get around this limitation by doing the following:

<?php

namespace App\Exceptions;

use Sentry\Event;

class Sentry
{
    public static function before(Event $event): ?Event
    {
        // literally anything

        return $event;
    }
}

Which you can set in your configuration like:

<?php

return [

    'dsn' => env('SENTRY_LARAVEL_DSN', env('SENTRY_DSN')),

    'before_send' => [App\Exceptions\Sentry::class, 'before'],

];

This works because we allow PHP callables to be passed for all callbacks.

doing the following on which file?

doing the following on which file?

config/sentry.php

It's not explicitly documented as the config options are passed through directly to Sentry. So when you read something like https://docs.sentry.io/platforms/php/#tagging-events , it's basically the content of config/sentry.php passed internally to this init.

doing the following on which file?

config/sentry.php

It's not explicitly documented as the config options are passed through directly to Sentry. So when you read something like https://docs.sentry.io/platforms/php/#tagging-events , it's basically the content of config/sentry.php passed internally to this init.

i don't have that file in config folder

Seems to me you didn't follow the installation guide then, see e.g. https://sentry.io/for/laravel/

Especially the last step ("create the sentry configuration")

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smknstd picture smknstd  路  4Comments

borealsmith picture borealsmith  路  6Comments

Vladelis picture Vladelis  路  9Comments

Dalabad picture Dalabad  路  3Comments

AidasK picture AidasK  路  5Comments