Skip to content

Commit

Permalink
Merge pull request #11 from edbizarro/feature-rollbar
Browse files Browse the repository at this point in the history
Feat: Rollbar Reporter
  • Loading branch information
esbenp authored Apr 17, 2017
2 parents eda2d19 + 91d359f commit 9e07819
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,24 @@ To send Exceptions to Bugsnag add the following reporter configuration in `confi
]
```

### [Rollbar](https://rollbar.com)

To send Exceptions to Rollbar add the following reporter configuration in `config/optimus.heimdal.php`.

```
'reporters' => [
'rollbar' => [
'class' => \Optimus\Heimdal\Reporters\RollbarReporter::class,
'config' => [
'access_token' => '',
'environment' => 'production'
]
]
]
```

The complete list of config options can be found in [here](https://github.com/rollbar/rollbar-php#configuration-reference)

## Standards

This package is compliant with [PSR-1], [PSR-2] and [PSR-4]. If you notice compliance oversights,
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
},
"suggest": {
"asm89/stack-cors": "Needed to add CORS headers if add_cors_headers configuration is true",
"sentry/sentry": "Needed to report exceptions to Sentry.io"
"sentry/sentry": "Needed to report exceptions to Sentry.io",
"rollbar/rollbar": "Needed to report exceptions to Rollbar.com"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
7 changes: 7 additions & 0 deletions src/Provider/LaravelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\ServiceProvider as BaseProvider;
use Optimus\Heimdal\Reporters\BugsnagReporter;
use Optimus\Heimdal\Reporters\RollbarReporter;
use Optimus\Heimdal\Reporters\SentryReporter;

class LaravelServiceProvider extends BaseProvider {
Expand Down Expand Up @@ -42,5 +43,11 @@ private function bindReporters()
return new SentryReporter($config);
};
});

$this->app->bind(RollbarReporter::class, function ($app) {
return function (array $config) {
return new RollbarReporter($config);
};
});
}
}
35 changes: 35 additions & 0 deletions src/Reporters/RollbarReporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Optimus\Heimdal\Reporters;

use Exception;
use Rollbar;
use InvalidArgumentException;

class RollbarReporter implements ReporterInterface
{
/**
* RollbarReporter constructor.
* @param array $config
* @throws \InvalidArgumentException
*/
public function __construct(array $config)
{
if (!class_exists(Rollbar::class)) {
throw new InvalidArgumentException('Rollbar client is not installed. Use composer require rollbar/rollbar');
}

Rollbar::init($config);
}

/**
* Report exception
*
* @param Exception $exception
* @return string|void
*/
public function report(Exception $exception)
{
return Rollbar::report_exception($exception);
}
}

0 comments on commit 9e07819

Please sign in to comment.