Skip to content

Commit 22b5718

Browse files
committedMar 30, 2023
Switch Sentry implementation to sentry-laravel
Summary: A native Laravel package is maintained by Sentry. Reference: https://docs.sentry.io/platforms/php/guides/laravel/ Ref T1791 Test Plan: Tested in production Reviewers: DorianWinty, dereckson Reviewed By: dereckson Maniphest Tasks: T1791 Differential Revision: https://devcentral.nasqueron.org/D2935
1 parent 0b2e7fc commit 22b5718

File tree

11 files changed

+253
-116
lines changed

11 files changed

+253
-116
lines changed
 

‎app/Exceptions/Handler.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Nasqueron\Notifications\Exceptions;
44

5-
use Nasqueron\Notifications\Facades\Raven;
6-
75
use Illuminate\Auth\Access\AuthorizationException;
86
use Illuminate\Database\Eloquent\ModelNotFoundException;
97
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
@@ -58,7 +56,7 @@ public function report(Exception|\Throwable $e) : void {
5856
* Determines if the error handler should report to Sentry
5957
*/
6058
protected function shouldReportToSentry () : bool {
61-
return Raven::isConfigured() && Config::get('app.env') !== 'testing';
59+
return app()->bound('sentry') && Config::get('app.env') !== 'testing';
6260
}
6361

6462
/**
@@ -67,7 +65,7 @@ protected function shouldReportToSentry () : bool {
6765
* @param Exception $e The exception to report
6866
*/
6967
protected function reportToSentry (Exception $e) : void {
70-
Raven::captureException($e);
68+
app('sentry')->captureException($e);
7169
}
7270

7371
}

‎app/Facades/Raven.php

-26
This file was deleted.

‎app/Providers/SentryServiceProvider.php

-26
This file was deleted.

‎composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"keruald/broker": "^0.5.0",
1919
"keruald/mailgun": "^0.1.0",
2020
"netresearch/jsonmapper": "^1.1.1",
21-
"sentry/sentry": "^0.13.0"
21+
"sentry/sentry-laravel": "^3.2"
2222
},
2323
"require-dev": {
2424
"laravel/browser-kit-testing": "^v6.3.0",

‎config/app.php

-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@
193193
Nasqueron\Notifications\Providers\PhabricatorProjectsMapServiceProvider::class,
194194
Nasqueron\Notifications\Providers\ReportServiceProvider::class,
195195
Nasqueron\Notifications\Providers\RouteServiceProvider::class,
196-
Nasqueron\Notifications\Providers\SentryServiceProvider::class,
197196
Nasqueron\Notifications\Providers\ServicesServiceProvider::class
198197

199198
],
@@ -255,7 +254,6 @@
255254
'Mailgun' => Nasqueron\Notifications\Facades\Mailgun::class,
256255
'PhabricatorAPI' => Nasqueron\Notifications\Facades\PhabricatorAPI::class,
257256
'ProjectsMap' => Nasqueron\Notifications\Facades\ProjectsMap::class,
258-
'Raven' => Nasqueron\Notifications\Facades\Raven::class,
259257
'Report' => Nasqueron\Notifications\Facades\Report::class,
260258
'Services' => Nasqueron\Notifications\Facades\Services::class,
261259

‎config/logging.php

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
3+
use Monolog\Handler\NullHandler;
4+
use Monolog\Handler\StreamHandler;
5+
use Monolog\Handler\SyslogUdpHandler;
6+
7+
return [
8+
9+
/*
10+
|--------------------------------------------------------------------------
11+
| Default Log Channel
12+
|--------------------------------------------------------------------------
13+
|
14+
| This option defines the default log channel that gets used when writing
15+
| messages to the logs. The name specified in this option should match
16+
| one of the channels defined in the "channels" configuration array.
17+
|
18+
*/
19+
20+
'default' => env('LOG_CHANNEL', 'stack'),
21+
22+
/*
23+
|--------------------------------------------------------------------------
24+
| Deprecations Log Channel
25+
|--------------------------------------------------------------------------
26+
|
27+
| This option controls the log channel that should be used to log warnings
28+
| regarding deprecated PHP and library features. This allows you to get
29+
| your application ready for upcoming major versions of dependencies.
30+
|
31+
*/
32+
33+
'deprecations' => [
34+
'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'),
35+
'trace' => false,
36+
],
37+
38+
/*
39+
|--------------------------------------------------------------------------
40+
| Log Channels
41+
|--------------------------------------------------------------------------
42+
|
43+
| Here you may configure the log channels for your application. Out of
44+
| the box, Laravel uses the Monolog PHP logging library. This gives
45+
| you a variety of powerful log handlers / formatters to utilize.
46+
|
47+
| Available Drivers: "single", "daily", "slack", "syslog",
48+
| "errorlog", "monolog",
49+
| "custom", "stack"
50+
|
51+
*/
52+
53+
'channels' => [
54+
'stack' => [
55+
'driver' => 'stack',
56+
'channels' => ['single'],
57+
'ignore_exceptions' => false,
58+
],
59+
60+
'single' => [
61+
'driver' => 'single',
62+
'path' => storage_path('logs/laravel.log'),
63+
'level' => env('LOG_LEVEL', 'debug'),
64+
],
65+
66+
'daily' => [
67+
'driver' => 'daily',
68+
'path' => storage_path('logs/laravel.log'),
69+
'level' => env('LOG_LEVEL', 'debug'),
70+
'days' => 14,
71+
],
72+
73+
'slack' => [
74+
'driver' => 'slack',
75+
'url' => env('LOG_SLACK_WEBHOOK_URL'),
76+
'username' => 'Laravel Log',
77+
'emoji' => ':boom:',
78+
'level' => env('LOG_LEVEL', 'critical'),
79+
],
80+
81+
'papertrail' => [
82+
'driver' => 'monolog',
83+
'level' => env('LOG_LEVEL', 'debug'),
84+
'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class),
85+
'handler_with' => [
86+
'host' => env('PAPERTRAIL_URL'),
87+
'port' => env('PAPERTRAIL_PORT'),
88+
'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'),
89+
],
90+
],
91+
92+
'stderr' => [
93+
'driver' => 'monolog',
94+
'level' => env('LOG_LEVEL', 'debug'),
95+
'handler' => StreamHandler::class,
96+
'formatter' => env('LOG_STDERR_FORMATTER'),
97+
'with' => [
98+
'stream' => 'php://stderr',
99+
],
100+
],
101+
102+
'syslog' => [
103+
'driver' => 'syslog',
104+
'level' => env('LOG_LEVEL', 'debug'),
105+
],
106+
107+
'errorlog' => [
108+
'driver' => 'errorlog',
109+
'level' => env('LOG_LEVEL', 'debug'),
110+
],
111+
112+
'null' => [
113+
'driver' => 'monolog',
114+
'handler' => NullHandler::class,
115+
],
116+
117+
'emergency' => [
118+
'path' => storage_path('logs/laravel.log'),
119+
],
120+
],
121+
122+
];

‎config/sentry.php

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Sentry DSN
8+
|--------------------------------------------------------------------------
9+
|
10+
| This option controls the DSN to reach Sentry Relay server.
11+
|
12+
*/
13+
14+
'dsn' => env('SENTRY_DSN'),
15+
16+
/*
17+
|--------------------------------------------------------------------------
18+
| Sentry release version
19+
|--------------------------------------------------------------------------
20+
|
21+
| This option controls the release version of the application.
22+
|
23+
| Example with dynamic git hash:
24+
| trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD'))
25+
|
26+
*/
27+
28+
'release' => env('SENTRY_RELEASE'),
29+
30+
/*
31+
|--------------------------------------------------------------------------
32+
| Sentry environment
33+
|--------------------------------------------------------------------------
34+
|
35+
| This option controls the release version of the application.
36+
|
37+
| When left empty or `null` the Laravel environment will be used.
38+
|
39+
*/
40+
41+
'environment' => env('SENTRY_ENVIRONMENT'),
42+
43+
/*
44+
|--------------------------------------------------------------------------
45+
| Sentry breadcrumbs
46+
|
47+
| Determines the scope of w hat's capturd in breadcrumbs.
48+
|--------------------------------------------------------------------------
49+
|
50+
*/
51+
52+
'breadcrumbs' => [
53+
'logs' => true,
54+
'sql_queries' => true,
55+
'sql_bindings' => true,
56+
'queue_info' => true,
57+
'command_info' => true,
58+
],
59+
60+
/*
61+
|--------------------------------------------------------------------------
62+
| Sentry tracing
63+
|
64+
| This option controls what's traced or captured as spans.
65+
|
66+
| See https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#traces-sample-rate
67+
| for the sample rate.
68+
|--------------------------------------------------------------------------
69+
|
70+
*/
71+
72+
'tracing' => [
73+
// Trace queue jobs as their own transactions
74+
'queue_job_transactions' => env('SENTRY_TRACE_QUEUE_ENABLED', false),
75+
76+
// Capture queue jobs as spans when executed on the sync driver
77+
'queue_jobs' => true,
78+
79+
// Capture SQL queries as spans
80+
'sql_queries' => true,
81+
82+
// Try to find out where the SQL query originated from and add it to the query spans
83+
'sql_origin' => true,
84+
85+
// Capture views as spans
86+
'views' => true,
87+
88+
// Capture HTTP client requests as spans
89+
'http_client_requests' => true,
90+
91+
// Indicates if the tracing integrations supplied by Sentry should be loaded
92+
'default_integrations' => true,
93+
94+
// Indicates that requests without a matching route should be traced
95+
'missing_routes' => false,
96+
],
97+
98+
'traces_sample_rate' => env('SENTRY_TRACES_SAMPLE_RATE') === null ? null : (float)env('SENTRY_TRACES_SAMPLE_RATE'),
99+
100+
/*
101+
|--------------------------------------------------------------------------
102+
| Sentry PII
103+
|
104+
| This option controls if Personal Identifiable Information (PII) should
105+
| be sent to the Relay or scrubbed here.
106+
|
107+
| If set at true, PII can still be removed in Relay or Sentry itself.
108+
|
109+
| See https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#send-default-pii
110+
|--------------------------------------------------------------------------
111+
|
112+
*/
113+
114+
'send_default_pii' => env('SENTRY_SEND_DEFAULT_PII', false),
115+
116+
];

‎config/services.php

-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@
3535
'secret' => env('STRIPE_SECRET'),
3636
],
3737

38-
'sentry' => [
39-
'dsn' => env('SENTRY_DSN'),
40-
],
41-
4238
'dockerhub' => [
4339
'tokens' => env('DOCKERHUB_TOKENS', 'DockerHubTokens.json')
4440
],

‎tests/Exceptions/HandlerTest.php

+12-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Nasqueron\Notifications\Exceptions\Handler;
66
use Nasqueron\Notifications\Tests\TestCase;
77

8+
use Sentry\State\HubInterface;
9+
810
use Illuminate\Auth\Access\AuthorizationException;
911
use Illuminate\Support\Facades\Config;
1012
use Mockery;
@@ -17,36 +19,36 @@ class HandlerTest extends TestCase {
1719
private $handler;
1820

1921
/**
20-
* Raven_Client
22+
* Sentry client
2123
*/
22-
private $ravenClientMock;
24+
private HubInterface $sentryClientMock;
2325

2426
public function setUp (): void {
2527
parent::setUp();
2628

2729
$this->handler = new Handler($this->app);
2830

29-
$this->mockRavenClient();
31+
$this->mockSentryClient();
3032
}
3133

32-
protected function mockRavenClient () {
34+
protected function mockSentryClient () {
3335
// Inject into our container a mock of Raven_Client
34-
$this->ravenClientMock = Mockery::mock('Raven_Client');
35-
$this->app->instance('raven', $this->ravenClientMock);
36+
$this->sentryClientMock = Mockery::mock(HubInterface::class);
37+
$this->app->instance('sentry', $this->sentryClientMock);
3638

3739
// Environment shouldn't be 'testing' and DSN should be defined,
38-
// so Handler::report will call Raven to report to Sentry
40+
// so Handler::report will call Sentry to report to Sentry
3941
Config::set('app.env', 'testing-raven');
4042
Config::set('services.sentry.dsn', 'mock');
4143
}
4244

43-
public function testRavenReport () {
44-
$this->ravenClientMock->shouldReceive('captureException')->once();
45+
public function tesSentryReport () {
46+
$this->sentryClientMock->shouldReceive('captureException')->once();
4547
$this->handler->report(new \Exception);
4648
}
4749

4850
public function testExceptionInDontReportArray () {
49-
$this->ravenClientMock->shouldReceive('captureException')->never();
51+
$this->sentryClientMock->shouldReceive('captureException')->never();
5052
$this->handler->report(new AuthorizationException);
5153
}
5254
}

‎tests/Facades/RavenTest.php

-29
This file was deleted.

‎tests/Providers/SentryServiceProviderTest.php

-14
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.