networkteam / sentry_client

TYPO3 Extension for exception logging with sentry, see http://www.getsentry.com
33 stars 36 forks source link

Allow setting additional Sentry configuration options #81

Closed Physikbuddha closed 10 months ago

Physikbuddha commented 1 year ago

Currently, this extension only allows configuring a handful of the available Sentry options. They are dsn, release, environment and in_app_include. Other options such as error_types, http_proxy, attach_stacktrace, and before_send are set automatically. However, there are a lot more configuration options available (see https://docs.sentry.io/platforms/php/configuration/options/), and I would like to make use of them, but I don't see any way how I can modify the $options array myself (https://github.com/networkteam/sentry_client/blob/master/Classes/Client.php).

Specific use case: I am not seeing the body of a POST request in the Sentry backend when additional files were uploaded with the request. This is because the default configuration value for max_request_body_size is medium (10 KB), and although the uploaded files are not passed to Sentry, the SDK is calculating the body size by using the PSR-17 request's Content-Length field (see https://github.com/getsentry/sentry-php/blob/1ad6831202b6d739bf820a6bea6735d32af610b2/src/Integration/RequestIntegration.php#L210).

There are two possible ways to solve this specific problem: You can either set the max_request_body_size value to always, or register a custom RequestFetcherInterface that modifies the value of the Content-Length field to match the "actual" body size before passing the request to the Sentry SDK.

Unfortunately, this extension doesn't allow configurating either of these options.

I think the best way to do this would be to allow setting additional options in the extension configuration, and then pass them to the Sentry SDK. My suggestion would be $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['sentry_client']['additionalConfiguration'] = [...] and merging this into the existing $options array. I was thinking about using a PSR-14 event for this, but since the code is called when an exception is thrown and TYPO3 is about to shut down, it might not be a good idea.

I could create a pull request for this myself, but wanted to ask for your opinion on this first.

christophlehmann commented 1 year ago

Thanks for the issue. The Upcoming major release provides a possibility to pass custom options via EXTCONF. EXTENSIONS is not good for it, because these setting types are very limited (no array, closures, ...).

christophlehmann commented 10 months ago

It's now possible to pass custom sentry options, see v5.0.0