stayallive / wp-sentry

A (unofficial) WordPress plugin reporting PHP and JavaScript errors to Sentry.
https://wordpress.org/plugins/wp-sentry-integration/
MIT License
300 stars 48 forks source link

Add a filter for PhpTracker default options #181

Closed Kilbourne closed 4 months ago

Kilbourne commented 4 months ago

Hi, could you pleasea add that filter? i need to customize on first instantiation ( namely filter integrations setting)

stayallive commented 4 months ago

I'm assuming with "filter integrations setting" you mean before_send?

See: https://github.com/stayallive/wp-sentry?tab=readme-ov-file#wp_sentry_before_send

Otherwise please let me know what specifically you want to do (maybe provide a code example) so I can better help you!

Kilbourne commented 4 months ago

The filter i wanted add was

public function get_default_options(): array {
        [...]
    return apply_filters( 'wp_sentry_default_options', $options, $this);
}

And then modify the integrations key But now I checked and I can use WP_SENTRY_CLIENTBUILDER_CALLBACK

function wp_sentry_clientbuilder_callback($clientBuilder){ 
       $options = $clientBuilder->getOptions();
       $integrations = $options->getIntegrations();
       [...]
       $options->setIntegrations($integrations);
}
define( 'WP_SENTRY_CLIENTBUILDER_CALLBACK', 'wp_sentry_clientbuilder_callback');

Not sure if you want add that filter anyway ( it could be useful)

stayallive commented 4 months ago

If this works for you I think this is enough 👍

I am wondering though what integrations you are removing or adding!

Kilbourne commented 4 months ago

I'm using Roots Acorn ( although with a custom ErrorHandler), so I filter the default error/exception/shutdown handlers and add LogIntegration feature from Laravel package. ( I don't like too much the callable constant and I would have prefered to use a filter, but suppose it is necessary for who is loading the library before add_filter is available)

stayallive commented 4 months ago

Yeah it's tricky, but there is a solution even if it's not pretty 😉