sentry php使用,Sentry简介

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"按钮

f07407a1e046

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

f07407a1e046

image.png

References

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值