Sentry
SaaS服务 => https://sentry.io/ => 注册账号 => 新建项目
自建服务
docker --version
# Docker version 19.03.5, build 633a0ea
docker-compose --version
# docker-compose version 1.24.1, build 4667896b
git clone https://github.com/getsentry/onpremise.git
cd onpremise
./install.sh
docker-compose up -d
React
create-react-app --version
# 3.4.1
create-react-app sentry-demo
cd sentry-demo
yarn add @sentry/react
vim src/index.js
import React from 'react';
import ReactDOM from 'react-dom';
import * as Sentry from '@sentry/react';
import App from './App';
Sentry.init({ dsn: "https://4a12571fb8bd44f7a5789334e0d33d7b@o421050.ingest.sentry.io/5340234" });
ReactDOM.render(, document.getElementById('root'));
vim src/App.js
import React from 'react';
function App() {
const methodDoesNotExist = 123
return (
Break the world
);
}
export default App;
npm run start
浏览器访问http://localhost:3000/ => 点击"Break the world"按钮
image.png
Laravel
composer create-project laravel/laravel sentry-demo --prefer-dist "5.5.*"
cd sentry-demo
composer require sentry/sentry-laravel:1.8.0
vim app/Exceptions/Handler.php
public function report(Exception $exception)
{
if (app()->bound('sentry') && $this->shouldReport($exception)) {
app('sentry')->captureException($exception);
}
parent::report($exception);
}
php artisan vendor:publish --provider="Sentry\Laravel\ServiceProvider"
vim .env
SENTRY_LARAVEL_DSN=https://281e3f72732f4780915743e432a6fd2c@o421050.ingest.sentry.io/5341626
vim routes/web.php
Route::get('/debug-sentry', function () {
throw new Exception('My first Sentry error!');
});
php artisan serve
curl http://127.0.0.1:8000/debug-sentry
image.png
References