0.1.8 • Published 3 years ago
sentry-miniprogram v0.1.8
Sentry Miniprogram
安装和使用
使用npm/yarn安装及使用微信开发工具构建包
# npm
npm install sentry-miniprogram -S
# yarn
yarn add sentry-miniprogram -S
使用
import Sentry from 'sentry-miniprogram'
Sentry.init({
dsn: '__DSN__'
})
Sentry.captureMessage('Hello, world!');
API
在追寻官方API规范中,完成了以下功能(若已有的方法实现有差异或期望实现未实现的功能欢迎提出或PR)
Sentry.init(options)
options.dsn: string
:: 项目DSNoptions.enabled?: boolean
:是否启用Sentry,禁用后所有方法可调用但不会有上报功能,默认启用options.environment?: string
: 环境,自定义字符串,默认production
options.maxBreadcrumbs?: number
:最大保存的breadcrumb
数量,超过指定数值后,先加入的会被丢弃,默认为20个options.getErrorStacktrace?: (err: Error) => Promise<Stacktrace>
:提供自定义获取错误对象的源码信息来上报更加丰富的错误信息,返回值Stacktrace
参考文档
Sentry.captureMessage(message: string, level: string = 'info'): void
Sentry.captureException(error: Error): void
Sentry.configureScope(callback: (scope): void)
scope.setUser(user): void
:scope.addBreadcrumb(breadcrumb | string): void
: 支持传递字符串和Breadcrumb
对象,如传递字符串则作为Breadcrumb
象的message
字段保存,其中timestamp
默认值为当前调用方法秒时间戳scope.clearBreadcrumbs(): void
scope.setTag(key: string, val: any): void
scope.removeTag(key: string): void
scope.setTags(tags: { [props: string]: any }): void
Sentry.(...scope)
:对于scope
的方法映射,如Sentry.setUser(user)