diff --git a/README.md b/README.md index b7d4fe9..bef1a0e 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,7 @@ The constructor accepts two optional argument: * `$root_path` - if specified, the project root-path will be removed from visible filenames in stack-traces. * `$max_string_length` - specifies the maximum length at which reported PHP values will be truncated. - * `$blacklist` - specifies one or more filename patterns to blacklist from stack-traces. + * `$filters` - specifies one or more filename patterns to be filtered from stack-traces. In addition, the public `$error_levels` property lets you customize how PHP error-levels map to Sentry severity-levels. The default configuration matches that of the official 2.0 client. diff --git a/src/Extensions/ExceptionReporter.php b/src/Extensions/ExceptionReporter.php index 4ab08a9..9362a9b 100644 --- a/src/Extensions/ExceptionReporter.php +++ b/src/Extensions/ExceptionReporter.php @@ -41,9 +41,9 @@ class ExceptionReporter implements SentryClientExtension protected $max_string_length; /** - * @var string[] file-name patterns to blacklist from stack-traces + * @var string[] file-name patterns to filter from stack-traces */ - protected $blacklist; + protected $filters; /** * Severity of `ErrorException` mappings are identical to the official (2.0) client @@ -76,16 +76,16 @@ class ExceptionReporter implements SentryClientExtension /** * The optional `$root_path`, if given, will be stripped from filenames. * - * The optional `$blacklist` is an array of {@see \fnmatch()} patterns, which will be applied + * The optional `$filters` is an array of {@see \fnmatch()} patterns, which will be applied * to relative paths of source-file references in stack-traces. You can use this to filter * scripts that define/bootstrap sensitive values like passwords and hostnames, so that * these lines will never show up in a stack-trace. * * @param string|null $root_path absolute project root-path (e.g. Composer root path; optional) * @param int $max_string_length PHP values longer than this will be truncated - * @param string[] $blacklist Optional file-name patterns to blacklist from stack-traces + * @param string[] $filters Optional file-name patterns to filter from stack-traces */ - public function __construct(?string $root_path = null, $max_string_length = 200, array $blacklist = []) + public function __construct(?string $root_path = null, $max_string_length = 200, array $filters = []) { $this->root_path = $root_path ? rtrim($root_path, "/\\") . "/" @@ -93,7 +93,7 @@ public function __construct(?string $root_path = null, $max_string_length = 200, $this->max_string_length = $max_string_length; - $this->blacklist = $blacklist; + $this->filters = $filters; } public function apply(Event $event, Throwable $exception, ?ServerRequestInterface $request): void @@ -197,8 +197,8 @@ protected function createStackFrame(array $entry): StackFrame $frame->filename = substr($filename, strlen($this->root_path)); } - if ($this->isBlacklisted($filename)) { - $frame->context_line = "### BLACKLISTED ###"; + if ($this->isFiltered($filename)) { + $frame->context_line = "### FILTERED FILE ###"; } else { if ($filename !== self::NO_FILE) { $this->loadContext($frame, $filename, $lineno, 5); @@ -215,13 +215,13 @@ protected function createStackFrame(array $entry): StackFrame /** * @param string $filename absolute path to source-file * - * @return bool true, if the given file matches any defined blacklist pattern + * @return bool true, if the given file matches any defined filter pattern * - * @see $blacklist + * @see $filters */ - protected function isBlacklisted(string $filename): bool + protected function isFiltered(string $filename): bool { - foreach ($this->blacklist as $pattern) { + foreach ($this->filters as $pattern) { if (fnmatch($pattern, substr($filename, strlen($this->root_path)))) { return true; } diff --git a/test/test.fixtures.php b/test/test.fixtures.php index fe0a74b..1931f40 100644 --- a/test/test.fixtures.php +++ b/test/test.fixtures.php @@ -113,7 +113,7 @@ class MockSentryClient extends SentryClient */ public $time = 1538738714; - public function __construct(EventCapture $capture, ?array $extensions = null, ?array $blacklist = []) + public function __construct(EventCapture $capture, ?array $extensions = null, ?array $filters = []) { $this->logger = new BreadcrumbLogger(); @@ -122,7 +122,7 @@ public function __construct(EventCapture $capture, ?array $extensions = null, ?a $extensions ?: [ new EnvironmentReporter(), new RequestReporter(), - new ExceptionReporter(__DIR__, 200, $blacklist), + new ExceptionReporter(__DIR__, 200, $filters), new ClientSniffer(), new ClientIPDetector(), ] diff --git a/test/test.php b/test/test.php index d35068f..cd7830e 100644 --- a/test/test.php +++ b/test/test.php @@ -90,8 +90,8 @@ function () { } ); -function test_exception_capture($use_blacklist = false) { - return function () use ($use_blacklist) { +function test_exception_capture($use_filter = false) { + return function () use ($use_filter) { $dsn = new MockDSN(); $capture = new MockDirectEventCapture($dsn); @@ -99,7 +99,7 @@ function test_exception_capture($use_blacklist = false) { $client = new MockSentryClient( $capture, null, - $use_blacklist + $use_filter ? ["*.fixtures.php"] : [] ); @@ -181,16 +181,16 @@ function test_exception_capture($use_blacklist = false) { eq($inner_frames[2]["lineno"], 34); eq($inner_frames[3]["lineno"], 31, "can capture line-number of failed call-site"); - $BLACKLISTED = "### BLACKLISTED ###"; + $FILTERED = "### FILTERED FILE ###"; - if ($use_blacklist) { - ok(! isset($inner_frames[0]["pre_context"]), "can blacklist pre_context"); + if ($use_filter) { + ok(! isset($inner_frames[0]["pre_context"]), "filtering removes pre_context"); - eq($inner_frames[0]["context_line"], $BLACKLISTED, "can blacklist context_line"); + eq($inner_frames[0]["context_line"], $FILTERED, "filtering removes context_line"); - ok(! isset($inner_frames[0]["post_context"]), "can blacklist post_context"); + ok(! isset($inner_frames[0]["post_context"]), "filtering removes post_context"); - ok(! isset($inner_frames[0]["vars"]), "can blacklist arguments"); + ok(! isset($inner_frames[0]["vars"]), "filtering omits arguments"); } else { eq( $inner_frames[0]["pre_context"], @@ -242,7 +242,7 @@ function test_exception_capture($use_blacklist = false) { ); test( - "can capture Exception without vars and stack-traces from files matching a blacklist pattern", + "can capture Exception without vars and stack-traces from files matching a filter pattern", test_exception_capture(true) );