0.4.14 • Published 5 months ago
@sepveneto/report-core v0.4.14
@sepveneto/report-core
适用于web和uniapp的日志上报插件
浏览器通过外部脚本直接使用
<html>
<script>
const sdk = document.createElement('script')
sdk.src = 'https://remote/sdk/index.global.js'
sdk.onload = function () {
new BuryReport({
url: 'http://remote/record',
appid: 'appid',
collect: true,
report: true,
interval: 5,
network: {
enable: true,
},
})
}
</script>
</html>快速开始
小程序端需预留出大小约6KB的空间
npm i -D @sepveneto/report-core
yarn add -D @sepveneto/report-core
pnpm i -D @sepveneto/report-core// vite.config.ts
import Reporter from '@sepveneto/report-core/vite'
export default defineConfig({
plugins: [
Reporter({ /* options */ }),
],
})Example: playground/
module.exports = {
configureWebpack: {
plugins: [
require('@sepveneto/report-core/webpack').default({ /* options */ }),
]
}
}// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('@sepveneto/report-core/webpack').default({ /* options */ })
]
}// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('@sepveneto/report-core/webpack').default({ /* options */ }),
],
},
}选项
| 名称 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| url | string | ✅ | - | 日志上报接口 |
| appid | string | ✅ | - | 用来区分每一个应用的id |
| report | boolean | ❎ | process.env.NODE.ENV === 'production' | 是否发送上报请求。 |
| error | boolean | ❎ | true | 是否自动上报error类型的错误 |
| collect | boolean | ❎ | true | 是否自动上报应用的环境信息 |
| entry | boolean | ❎ | - | 默认是src/main.js和src/main.ts,对于uniapp构建的项目无效 |
| network | { enable: boolean, success: boolean, fail: boolean, responseLimit: number } | ❎ | { enable: false, success: true, fail: true, responseLimit: 100 } | 网络请求的上报配置,其中失败请求包括所有状态码非200的,以及超时和主动取消的, 默认对100KB返回内容进行限制 |
| interval | number | ❎ | 10 | 数据上报的周期,默认每隔10s上传一次 |
关于占用空间
使用的上报功能不同,需要的空间大小也不一样
| 功能 | 相关配置 | 预计占用大小 | 说明 |
|---|---|---|---|
| 基础上报(自定义上报) | report | 1KB | 前置设定,关闭后影响其它功能 |
| js错误上报 | error | 2KB | - |
| 环境收集 | collect | 1KB | - |
| 网络请求上报 | network.enable | 4KB | 成功请求和失败请求的上报对大小影响可以忽略不计 |
占用大小不包含基础上报功能, 压缩工具terser
方法
| 名称 | 参数 | 说明 |
|---|---|---|
| report | (type: string, data: any, immediate: boolean) => void | 主动上报数据,当immediate开启时,会立刻将本地缓存的数据上报一次(错误信息与环境信息必定会立即上报 |
说明
应用会在启动时自动收集当前所在的环境信息并进行上报。
同时会重写console.error,在执行该方法时同样会自动上报这个错误
除此之外可以通过手动导入
report来自定义上报的时机和内容
import { report } from '@sepveneto/report-core'
report('error', 'test content')关于如何区分设备
在应用第一次启动时会自动生成一个设备id并存储在本地缓存中,因此一旦用户换设备或者缓存丢失都会导致设备计算出现误差
0.4.9
5 months ago
0.4.8
6 months ago
0.3.9
11 months ago
0.3.10
10 months ago
0.4.10
5 months ago
0.4.13
5 months ago
0.4.14
5 months ago
0.4.11
5 months ago
0.4.12
5 months ago
0.4.5
6 months ago
0.4.4
6 months ago
0.4.7
6 months ago
0.3.8
11 months ago
0.4.6
6 months ago
0.4.1
6 months ago
0.4.0
6 months ago
0.4.3
6 months ago
0.4.2
6 months ago
0.3.0
1 year ago
0.3.6
1 year ago
0.3.5
1 year ago
0.3.7
1 year ago
0.3.2
1 year ago
0.3.1
1 year ago
0.3.4
1 year ago
0.3.3
1 year ago
0.2.9
1 year ago
0.2.8
2 years ago
0.2.7
2 years ago
0.2.6
2 years ago
0.2.1
2 years ago
0.2.3
2 years ago
0.2.2
2 years ago
0.2.5
2 years ago
0.2.4
2 years ago
0.2.0
2 years ago
0.2.0-beta.1
2 years ago
0.2.0-beta.0
2 years ago
0.1.5
2 years ago
0.1.4
2 years ago
0.1.3
2 years ago
0.1.2
2 years ago
0.1.1
2 years ago
0.1.0
2 years ago