Coder Social home page Coder Social logo

phptek / silverstripe-sentry Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 22.0 229 KB

Flexible Sentry compatible bug aggregation client for Silverstripe applications.

License: BSD 3-Clause "New" or "Revised" License

PHP 100.00%
sentry silverstripe exception-handling error-handling bug aggregation glitchtip

silverstripe-sentry's Introduction

Sentry.io integration for SilverStripe

CI Scrutinizer Code Quality License

Sentry and Glitchtip are error and exception aggregation services. Systems like these take your application's errors, aggregate them alongside configurable context and store them for triage and analysis.

Imagine this: You see errors and exceptions before your clients do. The error > report > debug > patch > deploy cycle is therefore the most efficient it can possibly be.

This module binds sentry.io, app.glitchtip.com and on-prem hosted Sentry/Glitchtip installations to the Monlog error logger in Silverstripe. If you've used systems like RayGun, Rollbar, AirBrake and BugSnag before, you'll know roughly what to expect.

Requirements

See composer.json

Setup:

composer require phptek/sentry

Notes:

  • Version 5.x is aimed at Silverstripe 5.
  • Versions 2.x, 3.x and 4.x should work with the same Silverstripe v4 setups. v3+ simply use newer versions of the Sentry PHP SDK and have additional bugfixes and features.
  • Version 3.x SentryClientAdaptor has been renamed to SentryAdaptor and SentryLogWriter was renamed to SentryLogger, so your existing configuration(s) may need to be updated accordingly.

Config

You can set your DSN as a first-class environment variable in .env or your CI config:

SENTRY_DSN="http://deacdf9dfedb24ccdce1b90017b39dca:[email protected]/44"

You can also set it in your project's YML config:

---
Name: my-project-config-sentry
After:
  - 'sentry-config'
---

# Send errors reported for all environment modes: `dev`, `test` and `live` envs

PhpTek\Sentry\Adaptor\SentryAdaptor:
  opts:
    # Example DSN only. Obviously you'll need to setup your own Sentry "Project"
    dsn: http://deacdf9dfedb24ccdce1b90017b39dca:[email protected]/44

Conditional Config

---
Name: my-project-config-sentry
After:
  - 'sentry-config'
---

# Send errors reported just in `test` and `live`, but not `dev` envs

---
Only:
  environment: test
---
PhpTek\Sentry\Adaptor\SentryAdaptor:
  opts:
    # Example DSN only. Obviously you'll need to setup your own Sentry "Project"
    dsn: http://deacdf9dfedb24ccdce1b90017b39dca:[email protected]/44
---
Except:
  environment: test
---
PhpTek\Sentry\Adaptor\SentryAdaptor:
  opts:
    # Example DSN only. Obviously you'll need to setup your own Sentry "Project"
    dsn: http://deacdf9dfedb24ccdce1b90017b39dca:[email protected]/44
---
Only:
  environment: dev
---
PhpTek\Sentry\Adaptor\SentryAdaptor:
  opts:
    dsn: null
---

Please review the usage docs for further configuration and customisation options.

Notes:

  • Silence Injector errors where test and live envs have http_proxy set but dev environments don't: Provide a value of null, which applies to all YML config where one env has a setting and another doesn't. For example:
...
    ---
    Only:
      environment: dev
    ---
    PhpTek\Sentry\Adaptor\SentryAdaptor:
      opts:
        dsn: null
        http_proxy: null
    ---
...
  • As per the examples above, ensure your project's config is set to come after the module's own config, thus:

    After: - 'sentry-config'

SilverStripe Framework v3

YML Config:

phptek\Sentry\Adaptor\SentryClientAdaptor:
  opts:
    # Example DSN only. Obviously you'll need to setup your own Sentry "Project"
    dsn: http://deacdf9dfedb24ccdce1b90017b39dca:[email protected]/44

mysite/_config.php:

SS_Log::add_writer(\phptek\Sentry\SentryLogWriter::factory(), SS_Log::ERR, '<=');

Usage

Sentry is normally setup once in your project's .env, YML config or even _config.php file. See the above examples and the usage docs for details and options.

Support Me

If you like what you see, support me! I accept Bitcoin:

Bitcoin
3KxmqFeVWoigjvXZoLGnoNzvEwnDq3dZ8Q

 

 

silverstripe-sentry's People

Contributors

dcentrica avatar elliot-sawyer avatar g-rath avatar halles avatar hjgreen avatar jcop007 avatar jonom avatar lekoala avatar phptek avatar scott1702 avatar tractorcow avatar zpetterd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

silverstripe-sentry's Issues

Sentry Tags are not consistently reported

Any additional environment data that the module wishes to send to Sentry e.g. Peak-Memory, IPAddress etc is no longer being sent and is not visible in the Sentry UI.

This is probably becuase of a change made in senry/sentry where extra (and perhaps other) data should no longer be accepted by Sentry for security reasons. See discussion here: getsentry/sentry-php#848

It could also be down to a Monolog issue, and we simple need to send a different $record key, in calls to captureMessage() or captureException()

Support minimal log level config property

Typically Sentry clients let you set a minimal log level, which means only events of that level or higher will be reported.

From what I can tell in exploring the code, this isn't support as a configuration option.
If it is, it isn't documented.

It'd be great to have this option, as currently we have no control over if things get reported to Sentry (such as PHP warnings).

Stacktrace is not reported when error is non-Exception

PHP 7.2 + Silverstripe 4.4 + phptek/sentry 3.0.1

When messages are sent to Sentry via captureMessage() a stacktrace does not show which of course can hamper debugging. Messages sent via captureException() seem to be A-OK.

Poasibly related to #26.

User data not sent

Data for the current logged in user doesn't seem to be being sent to Sentry:
image

Is this a bug or do I need to do something to enable this functionality?

Manual logging mis-labels reports

The resulting report in Sentry itself when. manually invoking $logger->info() is incorrectly labelled:

Scenario #1

// No `log_level` set in local `logging.yml`
$logger = Injector::inst()->createWithArgs(Logger::class, ['error-log'])
    ->pushHandler(SentryHandler::create());

$logger->info('THIS IS A TEST: INFO'); // Not reported
$logger->warn('THIS IS A TEST: WARN'); // OK
$logger->error('THIS IS A TEST: ERROR'); // OK

Scenario #2

// No `log_level` set in local `logging.yml`

$logger = Injector::inst()->get(LoggerInterface::class);

$logger->info('THIS IS A TEST: INFO'); // Not reported
$logger->warn('THIS IS A TEST: WARN'); // Not reported
$logger->error('THIS IS A TEST: ERROR'); // Not reported

Scenario #3

// `log_level` set in local `logging.yml` to “DEBUG”

$logger = Injector::inst()->createWithArgs(Logger::class, ['error-log'])
    ->pushHandler(SentryHandler::create());

$logger->info('THIS IS A TEST: INFO'); // OK (Reported as “error” though)
$logger->warn('THIS IS A TEST: WARN'); // OK
$logger->error('THIS IS A TEST: ERROR'); // OK

Scenario #4

// `log_level` set in local `logging.yml` to “INFO”

$logger = Injector::inst()->createWithArgs(Logger::class, ['error-log'])
    ->pushHandler(SentryHandler::create());

$logger->info('THIS IS A TEST: INFO'); // OK (Reported as “error” though)
$logger->warn('THIS IS A TEST: WARN'); // OK
$logger->error('THIS IS A TEST: ERROR'); // OK

Version 3.0.5 PHP7.4+ install issue

The Requirements section of the README gives us:

SilverStripe 4
PHP >=7.0
SilverStripe ^4.0

SilverStripe 3
PHP 5.4+, <=7.4
SilverStripe v3.1.0+, < 4.0

However, version 3.0.5 of this module seems to have implemented a blanket requirement for PHP 5.4+, <=7.4, thereby making the module uninstallable on PHP 7.4+.

I need to downgrade back to 3.0.4 to get this module installed for my PHP7.4 / SS4 project.

Inconsistent tags

User Story

As a Sentry user
I want to see a standard range of tags in all my Sentry-aware projects
So that I can see at-a-glance, what the environment was like at the time the error occurred

Notes

Depending on the project in which the package is installed; Some tags show up, and not others.

php 7 support

Is there a good reason why php7 is not allowed ? it would be great to allow it since SilverStripe 3.6 now accepts php7 as well

ss 4.1 support

Hello,

anything else I can do to help regarding the pull requests?

Add PSR-4 autoload directives

This would help when autoloading (e.g. with sspak).

silverstripe/sspak#76

I noticed some of the namespaces are a bit inconsistent, but I could get it working with these in my local composer.json

"psr-4": {
            "PhpTek\\Sentry\\": "vendor/phptek/sentry/src/",
            "PhpTek\\Sentry\\Monolog\\": "vendor/phptek/sentry/src/"
        },

Request to add tag for newest commit

Hi,

I'd like to request a new tag be created for the current version of silverstripe-sentry as there was a bug which was fixed since the last tag similar to https://discourse.getgrav.org/t/the-reserved-indicator-cannot-start-a-plain-scalar-you-need-to-quote-the-scalar-at-line-1-near-extends/9947 (their solution did not work for me so I had to refer to the actual commit hash to get the latest version).

I'm requesting this since my composer.json file ideally would not have a commit hash, and I'd much rather it had a version number instead.

Thanks.

Pass userland ini settings into config

As a developer, I need to know as much as I can about the host environment, so that I can debug issues effectively.

This feature would allow arbitrary project php ini settings to be passed into Sentry's "config" array, and have them and their values as per the environment, displayed as tags within Sentry's UI.

Should a setting be passed that is not user configurable or unavailable for a given PHP version "Unavailable" should be shown.

Upgrade to Sentry 3.x

Version 3 of this module is using sentry/sdk 2.x and to avoid constant reminders that clients should upgrade from within the Sentry UI itself, as well as avail ourselves of new features, we should upgrade to sentry/sdk 3.latest

Add "release" feature

The Raven Sentry package allows developers to display and send the current GIT sha to Sentry itself for tracking of the current "release". This should be added ASAP.

a few things

Hi,

I created two pull requests (#1 and #3) with the following changes:

  • Collect user data before sending the message (because session is not available if initialized into _config.php)
  • Use context provided by the message so that exceptions have a nice stack trace
  • Properly filter the backtrace with the namespaced function

SS3.7.x + PHP7

PHP7 is not supported for SilverStripe 3.7.x versions, despite the framework supporting php7.

This causes installation issues with composer, that should not be necessary

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


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



New release

Would it be possible to create a new release with the updates from @tractorcow regarding YML files?

Incompatible issue with latest version of Monolog (1.24.0)

After run a composer update and it shows the monolog bump up to 1.24.0, this lib stops working and PHP complains above message.

Fatal error: Access level to PhpTek\Sentry\Monolog\Handler\SentryRavenHandler::$logLevels must be protected (as in class Monolog\Handler\RavenHandler) or weaker in /var/www/.../vendor/phptek/sentry/src/Handler/SentryRavenHandler.php on line 23

It works find when lock the monolog version to 1.23.0.

getData() doesn't work

SentryAdaptor::getData() isn't called from anywhere other than tests. It should be used to augment a Sentry record with additional data e.g. when sending "manual" logs without Exceptions being thrown.

The module works A-OK without this, but if I recall, in 2.x getData() created additional Sentry "tags" along the top of its UI.

TODO: Review behaviour from 2.x and ensure this feature is needed and patch as required.

Sentry does not send exception to issues monitor

Hi, I am having an issue installing Sentry on SilverStripe 3. The exception is firing but Sentry isn't picking it up...spent more than a day trying to troubleshoot so far. I am using SilverStripe 3.6.7, PHP7.0.33 (must not change), phptek/sentry 1.1.2, and Composer version 1.10.13. The exception is happening on my local correctly but not appearing on the issues monitor.

Feature request: ability to init sentry via envs

Currently i use a botched setup to inst sentry envs
Config::inst()->set("PhpTek\Sentry\Adaptor\SentryClientAdaptor", "opts", array ("dsn" => "https://[email protected]/$projectID"));

prefer the ability to have silverstripe-sentry check for envs in the current environment if possible for the system to rely on

Feature: Add module version in use

Different teams have differing workflows and ways of deploying projects. It's not always straightforward to discern the version of the phptek/sentry module in use.

Let's add it as "ADDITIONAL DATA" to be displayed within Sentry itself.

Configure event filtering

Sometimes Sentry itself will become flooded with messages caused by the same underlying issue, which for - reasons - can take some time to resolve. Due to the way Sentry itself works, a slight change in the data payload and it thinks a particular error is completely new - even though as humans we can see it's almost exactly the same as any number of previous ones.

Therefore it would be useful to be able to add a one-line change to a file and have the Sentry SDK ignore messages that match these criteria, by hooking into the `before_send' event config option. See here: https://docs.sentry.io/error-reporting/configuration/filtering/?platform=php.

This could be done using YML as per the below, but it would require a commit+push+deployment to achieve. Instead, a suitable fix for this issue could take an uploaded file via a dedicated tab in the admin UI lavelled "Sentry" with an UploadField so that config could simply be uploaded to the F/S. Alternatively, a separate DataObject subclass could perform the same job - although we're moving away from Sentry itself being the sole arbiter of configuration here.

Either way, the config would use a regular expression to match for incoming data against a given field e.g. the "title":

PhpTek\Sentry\Log\SentryLogger:
  filter:
    title: "WARNING: E_WARNING: chdir(): Permission denied (errno 13"

The above config would instruct the module to return null which means the Sentry SDK will ignore the message.

If going with the upload-able config,

PHP 7.3 support

Is PHP 7.3 really not supported or is it legacy that is forgotten to be updated?

Causes 500 Error Page To Render Twice

Silverstripe Framework Version: 4.7.2
Silverstripe Sentry Version: 3.0.7

When using this package it causes my 500 error pages to render twice, in dev this is hardly noticeable, however in production, when the friendly error page is shown then it leads to some interesting results of the error-500 page displaying twice stacked above each other.

Nothing reported

I have my yml set up on a Silverstripe 3 website like so:

phptek\Sentry\Adaptor\SentryClientAdaptor:
  opts:
    # Example DSN only. Obviously you'll need to setup your own Sentry "Project"
    dsn: https://[email protected]
PhpTek\Sentry\Handler\SentryHandler:
  # One of the permitted severities: DEBUG|INFO|WARNING|ERROR|FATAL
  log_level: WARNING

However, it does not seem to report anything. Did I miss a step?

Exception HTML Parse Error: Replacing the data is deprecated since version 2.3 and will stop working from version 3.0. Set the second argument to `true` to merge the data instead.

Error happens when another error needs to be reported, due to feature deprecation in sentry client

[internal] in trigger_error
/vendor/sentry/sentry/src/State/Scope.php in Sentry\State\Scope::setUser at line 181
            $this->user->merge($data);
            return $this;
        }
        @trigger_error('Replacing the data is deprecated since version 2.3 and will stop working from version 3.0. Set the second argument to `true` to merge the data instead.', E_USER_DEPRECATED);
        $this->user->replaceData($data);
        return $this;
    }

I'm making a PR as we speak

Ref: https://sentry.io/share/issue/0e7e8f9e30894400bd4620f8f397c497/

DSN config confusion

At the moment devs can configure Sentry's DSN either by using YML config or .env using SENTRY_DSN. If devs need fine-grained control on how reporting works on an environment by environment basis (ala dev, test and live) this can only be done in YML. Unfortunately, if you also have, (or want or need) SENTRY_DSN in .env then this config trumps the YML leaving you unable to do this.

Solution: Given that .env will always trump the YML config system, simply add a new module-specific directive SENTRY_ENV which does the same thing. A quick solution would permit one of "live", "dev" or "test" as its value:

SENTRY_DSN=http://deacda9dfbdb24cccce11b90517b39dca:[email protected]/44
SENTRY_ENV=live

V2.2.1 does not work with SS3

Hi I'm trying to use this with Silverstripe 3 with version 2.2.1 but it keeps giving me Class 'phptek\\Sentry\\SentryLogWriter' not found in /MYPROJECT/mysite/_config.php error.
I am using silverstripe/framework v3.7.5, PHP 7.4, silverstripe-sentry v.2.2.1
This is my code

// yml file
PhpTek\Sentry\Adaptor\SentryClientAdaptor:
  opts:
    dsn: MY_DSN

//_config.php file
SS_Log::add_writer(\phptek\Sentry\SentryLogWriter::factory(), SS_Log::ERR, '<=');

The code in _config.php file is giving me the class not found error. I tried using SentryLogger as well but no luck. In composer.json, v2.2.1 supports silverstripe framework version 3 and up. Am I missing anything?
I can't use v1.1.2 as I'm using PHP 7.4

Any help will be appreciated!

Bug in Conditional Config Example

There should be 3 dashes above the "Only:environment: test" in the Conditional Config example on readme otherwise it doesn't work.

---
Name: my-project-config-sentry
After:
  - 'sentry-config'
---

--- 
Only:
  environment: test
---
PhpTek\Sentry\Adaptor\SentryAdaptor:
  opts:
    # Example DSN only. Obviously you'll need to setup your own Sentry "Project"
    dsn: http://deacdf9dfedb24ccdce1b90017b39dca:[email protected]/44
---
Except:
  environment: test
---
PhpTek\Sentry\Adaptor\SentryAdaptor:
  opts:
    # Example DSN only. Obviously you'll need to setup your own Sentry "Project"
    dsn: http://deacdf9dfedb24ccdce1b90017b39dca:[email protected]/44
---
Only:
  environment: dev
---
PhpTek\Sentry\Adaptor\SentryAdaptor:
  opts:
    dsn: null
---

Standardise data presented within Sentry itself

At the moment, if information is missing from an error/exception context such as the current GET request or some of the tags like "browser" (Which comes from the Raven SDK itself), then that data field/tag is simply omitted.

I'd prefer it for consistency if all available fields and tags were always shown, regardless of their value, null or otherwise.

Include GPS variables in reports

User Story

As a Sentry user, I would like to see all the GET, POST and REQUEST variables available at the time a bug ocurred, so I can better debug what happened.

Acceptance Criteria

  • I can always see GET, POST, REQUEST fields, regardless of their value (See #22 for context)
  • When POST or GET requests are available, I can see a bullet list as a key => value
  • When no such data is available, I can see "Unavailable"

v4: PHP Warning: array_merge(): Expected parameter 1 to be an array, null given in /path/to/vendor/phptek/sentry/src/Adaptor/SentryAdaptor.php on line 157

PHP Warning:  array_merge(): Expected parameter 1 to be an array, null given in /path/to/vendor/phptek/sentry/src/Adaptor/SentryAdaptor.php on line 157
PHP Fatal error:  Uncaught TypeError: Return value of PhpTek\Sentry\Adaptor\SentryAdaptor::get_opts() must be of the type array, null returned in /path/to/vendor/phptek/sentry/src/Adaptor/SentryAdaptor.php:171

I have SENTRY_DSN defined in my .env and also tried inserting via Injector, but getting the above error on v4. Rolling back to 3.0.10 resolves the issue.

Calling dump/die of $optsConfig shows that it returns null, presumably because private static opts; is not defined. This will cause array_merge to fail

Manual logging produces weird empty array in Sentry

Using the manual logging method described in usage.md ala $logger->error('This is an error'); if a 2nd param is not passed, you see "[] []" appended to message-titles in Sentry:

[2021-07-17 15:36:15] error-log.ERROR: This is an error [] []

These should not be shown if it's possible to remove them.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.