Sentry 是一个实时事件日志记录和汇集的平台。其专注于错误监控以及提取一切事后处理所需信息而不依赖于麻烦的用户反馈。

Sentry是一个日志平台, 它分为客户端和服务端,客户端(目前客户端有Python, PHP,C#, Ruby等多种语言)就嵌入在你的应用程序中间,程序出现异常就向服务端发送消息,服务端将消息记录到数据库中并提供一个web节目方便查看。Sentry由python编写,源码开放,性能卓越,易于扩展,目前著名的用户有Disqus, Path, mozilla, Pinterest等。

通过docker安装

官方提供了 On-Premise 安装方式

git clone https://github.com/getsentry/onpremise
cd onpremise

然后创建volume,持久化存储

docker volume create --name=sentry-data && docker volume create --name=sentry-postgres

创建环境变量配置文件:

cp -n .env.example .env - create env config file

docker-compose build镜像,这一步会拉取官方镜像和redis等依赖,耐心等待 :

docker-compose build - Build and tag the Docker services

创建secret-key,执行后得到一个key,添加到.env中的SENTRY_SECRET_KEY

docker-compose run --rm web config generate-secret-key

创建DB和初始化用户,等待创建数据库和

docker-compose run --rm web upgrade
Created internal Sentry project (slug=internal, id=1) Would you like to create a user account now? [Y/n]: y
Email:
Password:
Repeat for confirmation:
Should this user be a superuser? [y/N]: y
User created: jqpeng@iflytek.com
Added to organization: sentry
Running migrations for sentry.nodestore:
- Migrating forwards to 0001_initial.

最后-d启动,启动成功后可以访问http://server-ip:9000

docker-compose up -d

访问:

创建项目并集成

先创建一个project,支持多种语言,我们创建一个java的

DSN(Client Keys)

DSN格式为:

DSN="https://public:private@host:port/project_id"

可以在项目的setting-Client Keys(DSN)里查看。

然后根据格式拼成DSN即可。

java项目集成

有多种集成方式:

基本集成方式

添加maven引用:

	<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry</artifactId>
<version>1.7.16</version>
</dependency>

然后在全局异常处理里集成:

 String dsn = "http://<SENTRY_PUBLIC_KEY>:<SENTRY_PRIVATE_KEY>@host:port/<PROJECT_ID>";
Sentry.init(dsn);

在有异常的地方:

      try {
unsafeMethod();
} catch (Exception e) {
// This sends an exception event to Sentry using the statically stored instance
// that was created in the ``main`` method.
Sentry.capture(e);
}

logback集成

logback配置:

<configuration>

  <appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender> <appender name="Sentry" class="io.sentry.logback.SentryAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>WARN</level>
</filter>
</appender> <root level="DEBUG">
<appender-ref ref="Console" />
<appender-ref ref="Sentry"/>
</root> </configuration>

spring-boot集成

先添加引用:

		<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-spring</artifactId>
<version>1.7.16</version>
</dependency>

在Application里集成:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.HandlerExceptionResolver; @Controller
@EnableAutoConfiguration
@SpringBootApplication
public class Application {
/*
Register a HandlerExceptionResolver that sends all exceptions to Sentry
and then defers all handling to the other HandlerExceptionResolvers.
You should only register this is you are not using a logging integration,
otherwise you may double report exceptions.
*/
@Bean
public HandlerExceptionResolver sentryExceptionResolver() {
return new io.sentry.spring.SentryExceptionResolver();
} /*
Register a ServletContextInitializer that installs the SentryServletRequestListener
so that Sentry events contain HTTP request information.
This should only be necessary in Spring Boot applications. "Classic" Spring
should automatically load the `io.sentry.servlet.SentryServletContainerInitializer`.
*/
@Bean
public ServletContextInitializer sentryServletContextInitializer() {
return new io.sentry.spring.SentryServletContextInitializer();
} @RequestMapping("/")
@ResponseBody
String home() {
int x = 1 / 0; return "Hello World!";
} public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

前端项目集成

前端集成更简单,引用sentry的js,然后init即可

<script src="https://browser.sentry-cdn.com/5.1.0/bundle.min.js" crossorigin="anonymous"></script>
Sentry.init({ dsn: 'dsn' });

作者:Jadepeng

出处:jqpeng的技术记事本--http://www.cnblogs.com/xiaoqi

您的支持是对博主最大的鼓励,感谢您的认真阅读。

本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

多语言业务错误日志收集监控工具Sentry 安装与使用的更多相关文章

  1. asp.Net Core免费开源分布式异常日志收集框架Exceptionless安装配置以及简单使用图文教程

    最近在学习张善友老师的NanoFabric 框架的时了解到Exceptionless : https://exceptionless.com/ !因此学习了一下这个开源框架!下面对Exceptionl ...

  2. C#实现多级子目录Zip压缩解压实例 NET4.6下的UTC时间转换 [译]ASP.NET Core Web API 中使用Oracle数据库和Dapper看这篇就够了 asp.Net Core免费开源分布式异常日志收集框架Exceptionless安装配置以及简单使用图文教程 asp.net core异步进行新增操作并且需要判断某些字段是否重复的三种解决方案 .NET Core开发日志

    C#实现多级子目录Zip压缩解压实例 参考 https://blog.csdn.net/lki_suidongdong/article/details/20942977 重点: 实现多级子目录的压缩, ...

  3. 【转】asp.Net Core免费开源分布式异常日志收集框架Exceptionless安装配置以及简单使用图文教程

    最近在学习张善友老师的NanoFabric 框架的时了解到Exceptionless : https://exceptionless.com/ !因此学习了一下这个开源框架!下面对Exceptionl ...

  4. 错误日志收集sentry的安装与简单使用

    通过官方文档https://docs.sentry.io/可以得知,安装服务有两种方式,一种是使用Python,这种方式个人感觉比较麻烦.于是选择了第二种方式:使用docker. 我是在Windows ...

  5. 前端监控系统(二)JS错误日志收集篇

    前端监控系统 目前已经上线,欢迎使用! 服务器搭建好了,可以着手开发了. 其实前端需要分析的数据有很多,包括,PVUV, 接口请求统计,耗时统计,JS错误统计,用户使用设备统计,用户地域分布,页面用户 ...

  6. 前端js错误日志收集

    今天一个客户说他们的一个同事用OPPO R11的手机访问不了我们的项目,打开后一片空白,虽然后面发现你的手机网络断了,但是想起来毕竟手机端没有调试的工具可以查看抛出的错误信息,方便我们追踪问题,后端的 ...

  7. 运维开发实践——基于Sentry搭建错误日志监控系统

    错误日志监控也可称为业务逻辑监控, 旨在对业务系统运行过程中产生的错误日志进行收集归纳和监控告警.似乎有那么点曾相识?没错... 就是提到的“APM应用性能监控”.但它又与APM不同,APM系统主要注 ...

  8. Net Core免费开源分布式异常日志收集框架Exceptionless

    asp.Net Core免费开源分布式异常日志收集框架Exceptionless安装配置以及简单使用图文教程 https://www.cnblogs.com/yilezhu/p/9193723.htm ...

  9. 基于sentry的前端错误监控日志系统(部署sentry服务器/前端项目部署)-让前端最快的定位到生产问题

    背景 在这越来越发达的网络时代,web应用也是越来越复杂,尤其是前端的开发,也是越来越受重视. 所以在我们前端开发完成后,会有一些列的web应用的上线验证,如自测.QA测试.code review 等 ...

随机推荐

  1. CPP-基础:C++中为什么需要一个头文件,一个cpp文件

    把文件分成头文件和源文件完全是为了方便扩展和组织程序 这么说吧 我们可能会自定义很多函数 而这些函数分别会在不同的地方被调用 甚至有些时候我们需要把一堆函数打包起来一起调用 比如#include &q ...

  2. ES6新增Map、Set和iterable

    Map需要一个二维数组 var test_map = new Map(["mians",99],["regink",88]) test_map.get(&quo ...

  3. 解决IIS7多域名绑定同一物理目录,设置不同的默认文档的问题

    IIS7多域名绑定同一物理目录,设置不同的默认文档是没办法设置的,因为在一个物理目录下只有一个web.config,并且IIS7把默认文档设置写在这里,导致所有域名的默认文档设置共享.解决方法:1.进 ...

  4. Bootstrap 响应式表格

    响应式表格 通过把任意的 .table 包在 .table-responsive class 内,您可以让表格水平滚动以适应小型设备(小于 768px).当在大于 768px 宽的大型设备上查看时,您 ...

  5. javascript基础知识 (八) BOM学习笔记

    一.什么是BOM      BOM(Browser Object Model)即浏览器对象模型.      BOM提供了独立于内容 而与浏览器窗口进行交互的对象:      由于BOM主要用于管理窗口 ...

  6. mysql:破解MySQL密码的一种方法

    1, 修改mysql配置文件/etc/my.cnf 12 [mysqld]skip_grant_tables 2, 重启mysql后直接用root用户登录(不用输入密码) 1 $ mysql -uro ...

  7. Python_编程题集_001_词法解析

    1.词法解析: 我的是名字是ths,今年18岁 语法分析后得到结果如下: 数字:18 中文:我的名字是 今年 岁 拼音:ths 符号:,. 请编写程序实现该词法分析功能 string模块解: impo ...

  8. Lex与Yacc学习(七)之环境配置另一种方式

    必备工具 flex-2.5.4a-1.exe   和  bison-2.4.1-setup.exe   以及 cygwin2.738 的安装文件,下载地址 http://download.csdn.n ...

  9. PAT Basic 1063

    1063 计算谱半径 在数学中,矩阵的“谱半径”是指其特征值的模集合的上确界.换言之,对于给定的 n 个复数空间的特征值 { a​1​​+b​1​​i,⋯,a​n​​+b​n​​i },它们的模为实部 ...

  10. 【ORACLE】调整序列的当前种子值

    [ORACLE]调整序列的当前种子值 --必须用SYS用户执行脚本:或具有SYSDBA角色登录: CREATE OR replace ); v_step ):;--步进 tsql ); BEGIN E ...