Giter Site home page Giter Site logo

sentry-mina's Introduction

小程序 Sentry SDK (Beta)

特性

除了 Sentry 基础的特性,还提供以下小程序相关特性

  • 记录客户端基本信息
  • 记录页面 request 请求
  • 记录应用生命周期(onAppLaunch, onAppShow, onAppHide)
  • 记录页面导航
  • 记录小程序 api 调用
  • 记录 console 日志
  • 记录应用框架异常和未捕获异常
  • 记录微信小程序 Unhandled Promise Rejection Error
  • 记录 setTimeout, setInterval 内异常
  • 支持小程序 LogManager
  • 支持小程序实时日志 getRealtimeLogManager

相关链接

使用

安装

  • npm i sentry-mina --save

小程序环境

默认环境为微信小程序,其他平台小程序可在初始化时配置特定平台环境对象

sentry.init({
  minaContext: wx
})

sentry.init({
  minaContext: {
    getSystemInfo: () => {},
    request: () => {},
    setStorage: () => {},
    getStorageSync: () => {},
    getLaunchOptionsSync: () => {},
    // ...
  }
})

微信开发工具配置

控制台报 regeneratorRuntime is not defined 错误,在开发工具上启用 增强编译 可解决 @NullYing

微信后台配置

开发中配置 sentry.io 的 url 地址。(sentry.io 未经过 icp 备案,需自己做转发)

Usage

import * as sentry from "sentry-mina";

// config Sentry
sentry.init({
  dsn: ''
})

// Set user information, as well as tags and further extras
sentry.configureScope(scope => {
  scope.setUser({ id: '4711' });
  scope.setTag('user_mode', 'admin');
  scope.setExtra('battery', 0.7);
  // scope.clear();
});

// Add a breadcrumb for future events
sentry.addBreadcrumb({
  message: 'My Breadcrumb',
  // ...
});

// Capture exceptions, messages or manual events
sentry.captureMessage('Hello, world!');
sentry.captureException(new Error('Good bye'));
sentry.captureEvent({
  message: 'Manual',
  stacktrace: [
    // ...
  ],
});

INTEGRATIONS

Breadcrumbs

new sentry.Integrations.Breadcrumbs({
  console: true,
  realtimeLog: ['info', 'warn', 'error'], // https://developers.weixin.qq.com/miniprogram/dev/framework/realtimelog/
  request: true,
  navigation: true,
  api: true,
  lifecycle: true,
  unhandleError: true
})
配置 类型 默认值 描述
console Boolean, Array true 是否记录 console 日志,如果值为数组 ['log', 'info'],则只记录数组中所列的日志
realtimeLog Boolean, Array true 是否记录实时日志,如果值为数组 ['log', 'info'],则只记录数组中所列的日志。将程序中通过 console 打的日志记录到小程序实时日志中, console.log 通过 realtimeLog.info 进行记录
request Boolean true 是否记录页面 request 请求
navigation Boolean true 是否记录页面导航信息
api Boolean true 是否记录小程序 API 调用
lifecycle Boolean true 是否记录小程序生命周期变化
unhandleError Boolean true 是否记录微信小程序 Unhandled Promise Rejection Error

TryCatch

捕获并记录 setTimeout, setInterval 内的异常

new sentry.Integrations.TryCatch()

LogManager

将 Sentry 事件数据记录到小程序 LogManager

new sentry.Integrations.LogManager({
  level: 0
})
配置 类型 默认值 描述
level Number 0 取值为0表示是否会把 App、Page 的生命周期函数和 wx 命名空间下的函数调用写入日志,取值为1则不会

GlobalHandlers

记录 app.onError 和 app.onPageNotFound 日志

new sentry.Integrations.GlobalHandlers()

TRANSPORT

目前小程序只支持通过 request 发送日志到服务器,由于小程序 request 有并发限制, sentry-mina 以队列的方式发送日志请求,避免过多占用请求资源。

sentry-mina 发送日志,支持失败重试,默认重试 2 次。可以通过以下方式

sentry.init({
  transportOptions: {
    retry: 2
  }
})

进行配置。

sentry-mina 会记录未发送的日志,当用户重新进入小程序,会继续发送。

PREVIEW

stack breadcrumbs meta

sentry-mina's People

Contributors

alexayan avatar dependabot[bot] avatar imtag avatar will- avatar zhangdubhe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sentry-mina's Issues

Uncaught错误获取

Uncaught (in promise) TypeError: a.split is not a function这种错误只能在try{}catch(){}里面获取吗?

对错误上报没有任何影响,只是会禁用一些插件

对错误上报没有任何影响,只是会禁用一些插件

默认配置是这个

export const defaultIntegrations = [
  new CoreIntegrations.Dedupe(),
  new CoreIntegrations.InboundFilters(),
  new CoreIntegrations.FunctionToString(),
  new GlobalHandlers(),
  new LogManager()
];

new CoreIntegrations.FunctionToString() 这个中间件在插件环境中会出错,只要不配置它就行

你的项目中可以配置,启用部分插件

Sentry.init({
  defaultIntegrations: [
     new Sentry.Integrations.Dedupe(),
    new Sentry.Integrations.InboundFilters(),
    new Sentry.Integrations.GlobalHandlers(),
    new Sentry.Integrations.LogManager()
 ]
});

Originally posted by @alexayan in #16 (comment)

这样会报错:
Sentry.Integrations.Dedupe is not a function
TypeError: Sentry.Integrations.Dedupe is not a function

onunhandledrejection: false不生效

配置如下:

      Sentry.init({
        environment: sentryEnv,
        dsn: '',
        defaultIntegrations: false, // 禁用所有默认的 Integrations
        integrations: [
          new Sentry.Integrations.TryCatch(),
          new Sentry.Integrations.LogManager({
            level: 0
          }),
          new Sentry.Integrations.Breadcrumbs({
            console: true,
            request: true,
            navigation: true,
            api: true,
            lifecycle: true
          }),
          new Sentry.Integrations.GlobalHandlers({
            onerror: true,
            onunhandledrejection: false // 关闭 Unhandled Promise Rejection Error
          })
        ]
      })

已经禁用了默认的 Integrations, Unhandled Promise Rejection Error还是会上报

使用方式

如果使用的话,能直接用npm下来的dist文件么,还是你内部有引用sentry的?

或者这块有更详细的说明?还是直接看sentry的api

sentry.captureException调用失效

如果把sentry.captureException放在wx.uploadFile接口调用失败的回调函数fail()函数体内,后台看不到有日志被记录,通过调试确定fail()函数体内被执行了。如果把sentry.captureException放在success或者complete函数体内,能够看到日志被记录。
另外真机调试时,fail()函数体被执行,能看到真机调试界面输出如下图信息,怎么直接把信息输出到后台呢?
image

期望结果:
把sentry.captureException放在fail()函数体内,后台能够看到日志信息。如何把图中错误信息直接输出到后台

sentry.captureMessage

在相同页面上captureMessage,message值为固定时,只能发出一次请求,以后请求发不出去

breadcrumbs.js有个this指针的问题,需要修复,给我开个权限,我提交代码

--- a/src/integrations/breadcrumbs.js
+++ b/src/integrations/breadcrumbs.js

+    const _this = this;

-            return originalRequest.apply(this.ctx, args);
+            return originalRequest.apply(_this.ctx, args);

-
-    fill(this.ctx, 'request', (originalRequest) => {
+    const _this = this; 
+    fill(_this.ctx, 'request', (originalRequest) => {

-            return originalRequest.call(this.ctx, requestOptions);
+            return originalRequest.call(_this.ctx, requestOptions);

 
-        return originalRequest.call(this.ctx, requestOptions);
+        return originalRequest.call(_this.ctx, requestOptions);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.