Skip to content
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

ENH: Provide a way to conditionally disable the raygun handler. #65

Merged
merged 1 commit into from Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 42 additions & 0 deletions README.md
Expand Up @@ -113,6 +113,48 @@ SilverStripe\Core\Injector\Injector:
- [ pushHandler, [ '%$SilverStripe\Raygun\RaygunHandler.custom'] ]
```

#### Disable handler

The RaygunHandler is enabled by default when the `SS_RAYGUN_APP_KEY` environment variable is set. There may be some situations where you need that variable to be set but you don't want the handler enabled by default (e.g. you may not want the handler enabled in dev or test environments except when triggering some test exception via a `BuildTask`).

```yml
---
Only:
environment: 'dev'
---
SilverStripe\Raygun\RaygunHandler:
enabled: false
```

Then in your `BuildTask` you can enable that handler as required.

```php
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\BuildTask;
use SilverStripe\Raygun\RaygunHandler;

class TriggerTestExtensionTask extends BuildTask
{
protected $title = 'Trigger Test Exception';

protected $description = 'Throws an exception. Useful for checking raygun integration is working as expected.';

/**
* Throw a test exception that is directed through raygun.
*
* @param HTTPRequest $request
*/
public function run($request)
{
$env = Director::get_environment_type();
Config::modify()->set(RaygunHandler::class, 'enabled', true);
throw new \Exception("Test exception thrown from '$env' environment.");
}
}
```

#### Proxy

If you need to forward outgoing requests through a proxy (such as for sites hosted in CWP), you can set the proxy host and optional port via yaml config:
Expand Down
6 changes: 6 additions & 0 deletions src/RaygunHandler.php
Expand Up @@ -19,9 +19,15 @@ class RaygunHandler extends MonologRaygunHandler
private static $user_include_fullname = false;

private static $user_include_email = false;

private static $enabled = true;

protected function write(array $record)
{
if (!(bool)$this->config()->get('enabled')) {
return;
}

$disableTracking = Config::inst()->get(
RaygunClient::class,
'disable_user_tracking'
Expand Down