phptek / silverstripe-sentry

Flexible Sentry compatible bug aggregation client for Silverstripe applications.
BSD 3-Clause "New" or "Revised" License
12 stars 22 forks source link

3.0.0-beta1 PhpTek\Sentry\Monolog\Handler\SentryRavenHandler not found #36

Closed phyzical closed 4 years ago

phyzical commented 4 years ago

Fatal error: Class 'PhpTek\Sentry\Monolog\Handler\SentryRavenHandler'  not found in vendor/phptek/sentry/src/Handler/SentryMonologHandler.php  on line 26
--

1 | 0.0008 | 413736 | {main}(  ) | .../index.php:0
2 | 0.0700 | 4135344 | SilverStripe\Control\HTTPApplication->handle(  ) | .../index.php:26
3 | 0.0714 | 4207608 | SilverStripe\Control\HTTPApplication->execute(  ) | .../HTTPApplication.php:118
4 | 0.0714 | 4208304 | SilverStripe\Control\HTTPApplication->callMiddleware(  ) | .../HTTPApplication.php:137
5 | 0.0714 | 4209000 | SilverStripe\Control\HTTPApplication->SilverStripe\Control\Middleware\{closure}(  ) | .../HTTPMiddlewareAware.php:65
6 | 0.0714 | 4209000 | SilverStripe\Core\Startup\ErrorControlChainMiddleware->process(  ) | .../HTTPMiddlewareAware.php:62
7 | 0.0714 | 4209000 | call_user_func:{vendor/silverstripe/framework/src/Core/Startup/ErrorControlChainMiddleware.php:67} (  ) | .../ErrorControlChainMiddleware.php:67
8 | 0.0714 | 4209000 | SilverStripe\Control\HTTPApplication->SilverStripe\Control\{closure}(  ) | .../ErrorControlChainMiddleware.php:67
9 | 0.0714 | 4209000 | SilverStripe\Core\CoreKernel->boot(  ) | .../HTTPApplication.php:135
10 | 0.0715 | 4209064 | SilverStripe\Core\CoreKernel->bootManifests(  ) | .../CoreKernel.php:194
11 | 0.8836 | 5434384 | SilverStripe\Core\Manifest\ModuleManifest->sort(  ) | .../CoreKernel.php:527
12 | 0.8841 | 5455480 | SilverStripe\Core\Config\Config_ForClass->uninherited(  ) | .../ModuleManifest.php:234
13 | 0.8841 | 5455480 | SilverStripe\Core\Config\Config_ForClass->get(  ) | .../Config_ForClass.php:129
14 | 0.8841 | 5455480 | SilverStripe\Config\Collections\CachedConfigCollection->get(  ) | .../Config_ForClass.php:96
15 | 0.8841 | 5455480 | SilverStripe\Config\Collections\CachedConfigCollection->getCollection(  ) | .../CachedConfigCollection.php:88
16 | 0.8841 | 5455480 | call_user_func:{vendor/silverstripe/config/src/Collections/CachedConfigCollection.php:139} (  ) | .../CachedConfigCollection.php:139
17 | 0.8841 | 5455480 | SilverStripe\Core\Config\CoreConfigFactory->SilverStripe\Core\Config\{closure}(  ) | .../CachedConfigCollection.php:139
18 | 0.8841 | 5455480 | SilverStripe\Core\Config\CoreConfigFactory->createCore(  ) | .../CoreConfigFactory.php:67
19 | 0.9106 | 5843208 | SilverStripe\Config\Collections\MemoryConfigCollection->transform(  ) | .../CoreConfigFactory.php:91
20 | 0.9106 | 5843208 | SilverStripe\Config\Transformer\PrivateStaticTransformer->transform(  ) | .../MemoryConfigCollection.php:73
21 | 1.1946 | 26183488 | class_exists (  ) | .../PrivateStaticTransformer.php:43
22 | 1.1946 | 26183568 | spl_autoload_call (  ) | .../PrivateStaticTransformer.php:43
23 | 1.1947 | 26183648 | SilverStripe\Core\Manifest\ClassLoader->loadClass(  ) | .../PrivateStaticTransformer.php:43
24 | 1.1949 | 26199760 | require_once( vendor/phptek/sentry/src/Handler/SentryMonologHandler.php' ) | .../ClassLoader.php:91
phptek commented 4 years ago

Notes: Reporter was using 3.0.0-beta1

phyzical commented 4 years ago

update 3.0.0-beta2 "runs" But notices are throwing

[Emergency] Uncaught InvalidArgumentException: The "notice" is not a valid enum value.
GET 

Line 77 in vendor/sentry/sentry/src/Severity.php
Source

68 
69     /**
70      * Constructor.
71      *
72      * @param string $value The value this instance represents
73      */
74     public function __construct(string $value = self::INFO)
75     {
76         if (!\in_array($value, self::ALLOWED_SEVERITIES, true)) {
77             throw new \InvalidArgumentException(sprintf('The "%s" is not a valid enum value.', $value));
78         }
79 
80         $this->value = $value;
81     }
82 
83     /**

Trace

    Sentry\Severity->__construct(notice)
    SentryHandler.php:73
    PhpTek\Sentry\Handler\SentryHandler->write(Array)
    AbstractProcessingHandler.php:39
    Monolog\Handler\AbstractProcessingHandler->handle(Array)
    Logger.php:344
    Monolog\Logger->addRecord(250, E_NOTICE: Undefined variable: $b, Array)
    Logger.php:609
    Monolog\Logger->log(250, E_NOTICE: Undefined variable: $b, Array)
    ErrorHandler.php:160
    Monolog\ErrorHandler->handleError(8, Undefined variable: $b, utilities-ss4/code/helpers/SentryHelper.php, 65, Array)
    call_user_func(Array, 8, Undefined variable: $b, utilities-ss4/code/helpers/SentryHelper.php, 65, Array)
    ErrorHandler.php:173
    Monolog\ErrorHandler->handleError(8, Undefined variable: $b, /utilities-ss4/code/helpers/SentryHelper.php, 65, Array)
    SentryHelper.php:65
    StrangeAnimals\Utilities\SentryHelper::testPHP()
    Page.php:364```
 public static function testPHP()
    {
        $a = ${'$b'};
    }
phptek commented 4 years ago

This is basically a scenario I would never come across as I always run with error_reporting E_ALL, meaning I attend-to these sorts of errors before they go to UAT or PROD and are subsequently reported to Sentry.

Not to say this isn't a legit issue - it is.

Something like the following should sort it:

    /**
     * Maps PHP's internal error-types into those suited to {@link Severity}.
     *
     * @param  string $level The incoming level.
     * @return string
     */
    private static function process_level(string $level) : string
    {
        // PHP to Sentry\Severity map
        $map = [
          'error' => 'ERROR',
          'warning' => 'WARNING',
          'parse' => 'ERROR',
          'notice' => 'INFO',
        ];

        $defaultLevel = $map['error']; // It's an "ERROR" until proven otherwise.
        $level = $level ?: $defaultLevel;

        if (!isset($map[$level])) {
            $level = $defaultLevel;
        }

        return strtolower($level);
    }
phyzical commented 4 years ago

Confirmed this as working atleast for my bug

via the above and $this->client->getSDK()->captureMessage($record['formatted'], new Severity(self::process_level($record['level_name'])));

phptek commented 4 years ago

@phyzical Please try with 3.0.0-beta3

phyzical commented 4 years ago

works for me!