美文网首页
Sentry简介

Sentry简介

作者: 诺之林 | 来源:发表于2020-07-17 14:04 被阅读0次

Sentry

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(<App />, document.getElementById('root'));
vim src/App.js
import React from 'react';

function App() {
    const methodDoesNotExist = 123

    return (
        <button onClick={methodDoesNotExist}>
            Break the world
        </button>
    );
}

export default App;
npm run start
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

相关文章

网友评论

      本文标题:Sentry简介

      本文链接:https://www.haomeiwen.com/subject/nwephktx.html