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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Your configuration files are not serializable #266

Closed
carcinocron opened this issue Aug 23, 2019 · 6 comments
Closed

Your configuration files are not serializable #266

carcinocron opened this issue Aug 23, 2019 · 6 comments

Comments

@carcinocron
Copy link

carcinocron commented Aug 23, 2019

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

@stayallive
Copy link
Collaborator

stayallive commented Aug 25, 2019

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.

@stayallive
Copy link
Collaborator

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.

@atta1234
Copy link

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?

@mfn
Copy link

mfn commented Aug 19, 2020

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.

@atta1234
Copy link

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

@mfn
Copy link

mfn commented Aug 20, 2020

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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants