-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
2,801 additions
and
7,279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"node": "current" | ||
} | ||
} | ||
"@babel/preset-env" | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
BSD 3-Clause License | ||
|
||
Copyright (c) 2018, alexayan | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
* Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# 小程序 Sentry SDK (Beta) | ||
|
||
## 特性 | ||
|
||
除了 Sentry 基础的特性,还提供以下小程序相关特性 | ||
|
||
- 记录客户端基本信息 | ||
- 记录页面 request 请求 | ||
- 记录应用生命周期(onAppLaunch, onAppShow, onAppHide) | ||
- 记录页面导航 | ||
- 记录小程序 api 调用 | ||
- 记录 console 日志 | ||
- 记录应用异常 | ||
- 记录 setTimeout, setInterval 内异常 | ||
- 支持小程序 LogManager | ||
|
||
|
||
## 相关链接 | ||
|
||
- [Sentry 快速入门](https://docs.sentry.io/quickstart/) | ||
- [Sentry 官方 API 文档](http://getsentry.github.io/sentry-javascript/) | ||
|
||
## 使用 | ||
|
||
### 安装 | ||
|
||
- `npm install sentry-mina --save` | ||
- `yarn add sentry-mina` | ||
- 将 `browser/sentry-mina.js` 拷贝到项目中 | ||
|
||
### 使用 | ||
|
||
``` | ||
import * as sentry from "sentry-mina/browser/sentry-mina.js"; | ||
// 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, | ||
request: true, | ||
navigation: true, | ||
api: true, | ||
lifecycle: true | ||
}) | ||
``` | ||
|
||
配置 | 类型 | 默认值 |描述 | ||
------------- | ------------- | ------------- | ------------- | ||
console | Boolean, Array | true |是否记录 console 日志,如果值为数组 ['log', 'info'],则只记录数组中所列的日志 | ||
request | Boolean | true | 是否记录页面 request 请求 | ||
navigation | Boolean | true | 是否记录页面导航信息 | ||
api | Boolean | true | 是否记录小程序 API 调用 | ||
lifecycle | Boolean | true | 是否记录小程序生命周期变化 | ||
|
||
#### 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](static/stack.png) | ||
![breadcrumbs](static/breadcrumbs.png) | ||
![meta](static/meta.png) | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.