nativeScript-sentry.io
此插件使用 sentry-android 和 sentry-cocoa 捕获原生错误/堆栈跟踪并将它们发送到 Sentry 服务器。
npm i --save nativescript-sentry.io
- 版本:1.0.4
- GitHub: https://github.com/labidiaymen/nativescript-sentry.io
- NPM: https://npmjs.net.cn/package/nativescript-sentry.io
- 下载
- 昨天: 5
- 上周: 7
- 上个月: 59
Sentry.io for nativescript
此插件使用 sentry-android 和 sentry-cocoa 捕获原生错误/堆栈跟踪并将它们发送到 Sentry 服务器。
注意:如果您有一个 原生异常 且应用退出,则插件会保存日志并在 下次应用启动 时发送,这是原生插件实现的方式,也是预期行为。
安装
tns plugin add nativescript-sentry.io
用法
无 Angular
import { Sentry } from 'nativescript-sentry.io';
const dsn = 'https://<key>:<secret>@host/<project>';
Sentry.init(dsn);
有 Angular
import { SentryModule } from 'nativescript-sentry.io/angular';
NgModule({
...
imports: [
SentryModule.forRoot({dsn: 'https://<key>:<secret>@host/<project>'})
],
注意:此插件添加了自定义 ErrorHandler 并自动提供它。
API
初始化 Sentry
Sentry.init(dsn: string, options: SentryOptions)
捕获异常
Sentry.captureException(exception: Error, options: SentryOptions)
示例
try {
throw 'try catch Exception example'
} catch(error) {
Sentry.captureException(error, {});
}
捕获消息
Sentry.captureMessage(message: string, options: SentryOptions)
捕获面包屑
Sentry.captureBreadcrumb(breadcrumb: SentryBreadcrumb)
设置当前用户
Sentry.setContextUser(user: SentryUser)
上下文标签
Sentry.setContextTags(tags: any)
上下文额外信息
Sentry.setContextExtra(extra: any)
清除上下文
`Sentry.clearContext()``