-
Notifications
You must be signed in to change notification settings - Fork 179
Add error types option #34
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
Conversation
This parser converts an error types expression from string to integer. e.g. E_ALL & ~E_DEPRECATED & ~E_NOTICE -> 24567
3c877e1
to
6c5ea28
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why all of this magic?
Changing the service definition from
arguments: ['%sentry.dsn%']
to
arguments: ['%sentry.dsn%', %sentry.options%]
would achieve exactly the same goal, plus give access to all of the RavenClient options, not just this one.
@@ -1,7 +1,7 @@ | |||
services: | |||
sentry.client: | |||
class: '%sentry.client%' | |||
arguments: ['%sentry.dsn%'] | |||
arguments: ['%sentry.dsn%', {'errro_types': '%sentry.error_types%'}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: error_types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To understand this commit, please check this pull request: getsentry/sentry-php#369
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 4 has errro_types
, should have error_types
. Nothing to do with that change.
@@ -0,0 +1,14 @@ | |||
<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test cases seems lacking. For configuration extension, SentrySymfonyClient
, no container test...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah they def are
@@ -1,7 +1,7 @@ | |||
services: | |||
sentry.client: | |||
class: '%sentry.client%' | |||
arguments: ['%sentry.dsn%'] | |||
arguments: ['%sentry.dsn%', {'errro_types': '%sentry.error_types%'}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 4 has errro_types
, should have error_types
. Nothing to do with that change.
|
||
```yaml | ||
sentry: | ||
error_types: E_ALL & ~E_DEPRECATED & ~E_NOTICE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it not be simpler to just pass array's RavenClient expect instead of transforming strings to constants, back to Sentry levels again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you're right - 'errro_types' was a typo. It's corrected now.
Of course it would be easier, but this is the established syntax to define error levels in php.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a way (legacy one, I might add) on how you define error reporting levels for PHP interpreter - nothing more. This configuration however is meant for Sentry, and Sentry has it's own error levels defined already - so it only makes sense, and is in a way expected behavior to follow Sentry convention.
As far as I know, otherwise, it's inconsistent - Symfony client uses one set of levels, Sentry uses another. What gives?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really know which Sentry error levels do you mean. The Raven_ErrorHandler exactly needs the error levels which i defined it in the configuration.
/**
* Register a handler which will intercept standard PHP errors and report them to the
* associated Sentry client.
*
* @param bool $call_existing Call any existing errors handlers after processing
* this instance.
* @return array
*/
public function registerErrorHandler($call_existing = true, $error_types = null)
{
if ($error_types !== null) {
$this->error_types = $error_types;
}
$this->old_error_handler = set_error_handler(array($this, 'handleError'), E_ALL);
$this->call_existing_error_handler = $call_existing;
return $this;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, terribly sorry, I was under impression RavenClient uses "error", "warning" kind of strings.
Apart from that - can we avoid at least part of the conversions? For example, instead of having the php.ini-like single variable string E_ALL && ~E_WARNING
, perhaps we can have array of levels we want and then just get the values via constant? Without all the preg_replace etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, consider that this code will be run every time there is an issue - so we probably want to keep the logic there to the absolute minimum. There aren't that many error types, and perhaps it should be inverse: e.g. list the types you don't want to receive. That would be consistent with exception filtering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That code is not rocket science. It's a simply preg_replace to secure the php eval function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course. However, consider that this code is used in projects of all sizes, and this code is executed on construct - which is both good (executed just once) and bad thing (executed always). It's not a big issue if you get few hundred thousand executions per day. It becomes an issue when you have this running couple of billion times a day (like for us) - especially if there is a better and much less costly way to do it. Converting a list of "exclude" rules to constants and passing them on to Raven is such a way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't make a mountain out of a mole hill. It's a simply string replace operation.
And furthermore the code gets only executed if you have defined error types in your configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Short update - I've built a small test case for you:
class SentrySymfonyClient extends \Raven_Client
{
public function __construct($dsn=null, $options=array())
{
$stopwatch = new Stopwatch();
$stopwatch->start('initialize');
if (true || array_key_exists('error_types', $options)) {
$stopwatch->start('parser');
$exParser = new ErrorTypesParser('E_ALL & ~E_DEPRECATED & ~E_NOTICE');
$options['error_types'] = $exParser->parse();
$parserEvent = $stopwatch->stop('parser');
}
$options['sdk'] = array(
'name' => 'sentry-symfony',
'version' => SentryBundle::VERSION,
);
parent::__construct($dsn, $options);
$initEvent = $stopwatch->stop('initialize');
echo $initEvent."\n";
echo $parserEvent."\n";
}
}
With following results. The complete init takes 2ms and the parser takes 0ms. That should be enough to prove a string replace function is not expensive.
According to my pull request: getsentry/sentry-php#369 With this error types options its possible to configure which error types should be reported.
In general I think this is good, and its far easier to configure than other mechanisms. |
According to my pull request: getsentry/sentry-php#369
With this error types options its possible to configure which error types should be
reported.