Skip to content

Commit fd624a1

Browse files
committed
Add Sentry driver to replace Raven
Because RavenHandler was removed from Monolog since version 2.0
1 parent 0b9001a commit fd624a1

File tree

9 files changed

+90
-3
lines changed

9 files changed

+90
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Currently supported notification channels via [Monolog](https://github.com/Selda
1717
- [Flowdock](https://www.flowdock.com/)
1818
- [Plivo](https://www.plivo.com/) an SMS messaging service.
1919
- [Twilio](https://www.twilio.com/) an SMS messaging service.
20+
- [Sentry](https://getsentry.com) via [Sentry SDK for PHP](https://github.com/getsentry/sentry-php)
2021
- [Mailgun](https://mailgun.com)
2122

2223
## Version Compatibility
@@ -70,6 +71,7 @@ Laravel Notify also exposes extra Facades. To use them you will need to add them
7071
"Slack" => Tylercd100\Notify\Facades\Slack::class,
7172
"Plivo" => Tylercd100\Notify\Facades\Plivo::class,
7273
"Twilio" => Tylercd100\Notify\Facades\Twilio::class,
74+
"Sentry" => Tylercd100\Notify\Facades\Sentry::class,
7375
"Mailgun" => Tylercd100\Notify\Facades\Mailgun::class,
7476
```
7577
And then use them like this

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"orchestra/testbench": "^4.0|^5.0|^6.0"
4646
},
4747
"suggest": {
48-
"sentry/sentry": "Required to use the Raven driver for Sentry (~1.7)."
48+
"sentry/sentry": "Required to use the Sentry driver (~3.0)."
4949
},
5050
"extra": {
5151
"providers": [

config/notify.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@
5252
'token' => env('FLOWDOCK_APP_TOKEN'),
5353
],
5454

55+
/**
56+
* Sentry settings
57+
*/
58+
'sentry'=>[
59+
'dsn' => env('SENTRY_DSN'),
60+
'level' => 'info',
61+
],
62+
5563
/**
5664
* Fleephook settings
5765
*/

src/Drivers/Sentry.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Tylercd100\Notify\Drivers;
4+
5+
use Tylercd100\Notify;
6+
7+
class Sentry extends Base
8+
{
9+
/**
10+
* Returns a list of driver names to load
11+
* @return array An array of drivers to use
12+
*/
13+
protected function getDrivers()
14+
{
15+
return ['sentry'];
16+
}
17+
}

src/Facades/Sentry.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Tylercd100\Notify\Facades;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
7+
/**
8+
* @see \Illuminate\Filesystem\Filesystem
9+
*/
10+
class Sentry extends Facade
11+
{
12+
/**
13+
* Get the registered name of the component.
14+
*
15+
* @return string
16+
*/
17+
protected static function getFacadeAccessor()
18+
{
19+
return 'notify-sentry';
20+
}
21+
}

src/Factories/MonologHandlerFactory.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static function create($name, array $config = [], $title = null){
2121
$handler = call_user_func([MonologHandlerFactory::class,$name], $config, $title);
2222

2323
// Keep newline characters
24-
$format = ['fleephook', 'mail', 'mailgun', 'pushover', 'slack'];
24+
$format = ['fleephook', 'mail', 'mailgun', 'pushover', 'slack', 'sentry'];
2525

2626
if(in_array($name, $format)) {
2727
$handler->setFormatter(new LineFormatter(null, null, true));
@@ -200,6 +200,28 @@ protected static function twilio(array $config = [], $title = null){
200200
$c['host'],
201201
$c['version'],
202202
$c['limit']);
203+
/**
204+
* Returns a SentryHandler
205+
* @param array $config An array of config values to use
206+
* @param string $title The title/subject to use
207+
* @return \Sentry\Monolog\Handler
208+
*/
209+
protected static function sentry(array $config = [], $title = null)
210+
{
211+
$defaults = [
212+
'dsn' => null,
213+
'level' => Logger::ERROR,
214+
'bubble' => true,
215+
];
216+
217+
$c = array_merge($defaults, $config);
218+
$client = \Sentry\ClientBuilder::create(Arr::only($c, 'dsn'))->getClient();
219+
220+
return new \Sentry\Monolog\Handler(
221+
new \Sentry\State\Hub($client),
222+
$c['level'],
223+
$c['bubble']
224+
);
203225
}
204226

205227
/**

src/Providers/NotifyServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Tylercd100\Notify\Drivers\Plivo;
1212
use Tylercd100\Notify\Drivers\Pushover;
1313
use Tylercd100\Notify\Drivers\Slack;
14+
use Tylercd100\Notify\Drivers\Sentry;
1415
use Tylercd100\Notify\Drivers\Twilio;
1516

1617
class NotifyServiceProvider extends ServiceProvider
@@ -26,6 +27,7 @@ public function register() {
2627
'notify-mailgun' => Mailgun::class,
2728
'notify-plivo' => Plivo::class,
2829
'notify-pushover' => Pushover::class,
30+
'notify-sentry' => Sentry::class,
2931
'notify-slack' => Slack::class,
3032
'notify-twilio' => Twilio::class,
3133
];

tests/FacadeTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Tylercd100\Notify\Drivers\Pushover;
1010
use Tylercd100\Notify\Drivers\Flowdock;
1111
use Tylercd100\Notify\Drivers\FleepHook;
12+
use Tylercd100\Notify\Drivers\Sentry;
1213
use Tylercd100\Notify\Drivers\Slack;
1314
use Tylercd100\Notify\Drivers\Twilio;
1415
use Tylercd100\Notify\Facades\Mailgun as MailgunFacade;
@@ -18,6 +19,7 @@
1819
use Tylercd100\Notify\Facades\Pushover as PushoverFacade;
1920
use Tylercd100\Notify\Facades\Slack as SlackFacade;
2021
use Tylercd100\Notify\Facades\Twilio as TwilioFacade;
22+
use Tylercd100\Notify\Facades\Sentry as SentryFacade;
2123
use Tylercd100\Notify\Facades\Flowdock as FlowdockFacade;
2224
use Tylercd100\Notify\Facades\FleepHook as FleepHookFacade;
2325

@@ -48,6 +50,11 @@ public function testTwilioFacade(){
4850
$this->assertInstanceOf(Twilio::class,$obj);
4951
}
5052

53+
public function testSentryFacade(){
54+
$obj = SentryFacade::getFacadeRoot();
55+
$this->assertInstanceOf(Sentry::class,$obj);
56+
}
57+
5158
public function testMailgunFacade(){
5259
$obj = MailgunFacade::getFacadeRoot();
5360
$this->assertInstanceOf(Mailgun::class,$obj);
@@ -73,5 +80,4 @@ public function testMailFacadeWithNoSmtp(){
7380
$obj = MailFacade::getFacadeRoot();
7481
$this->assertInstanceOf(Mail::class,$obj);
7582
}
76-
7783
}

tests/TestCase.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ protected function getEnvironmentSetUp($app)
6363
'mailgun',
6464
'plivo',
6565
'pushover',
66+
'sentry',
6667
'slack',
6768
'twilio',
6869
],
@@ -97,6 +98,14 @@ protected function getEnvironmentSetUp($app)
9798
'sound' => "Sound",
9899
],
99100

101+
/**
102+
* Sentry settings
103+
*/
104+
'sentry'=>[
105+
'dsn' => null,
106+
'level' => 'error',
107+
],
108+
100109
/**
101110
* Slack settings
102111
*/

0 commit comments

Comments
 (0)