Sentry 是一个流行的错误监控平台,帮助开发者分析,修复问题,优化代码的性能。可以进行错误捕获,问题追踪,并提供问题详情,适用于多个平台,多种语言。
官方说明文档
Vue
API 说明
::: tip
目前只有 Vue 技术栈文档;
源码链接:@shencom/plugins/Sentry
:::
Options
新增 Sentry 配置说明
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---|---|---|---|---|
| scid | 租户 ID | String |
必填 | - |
| isDev | 是否在开发环境 | boolean |
必填 | - |
| isPro | 是否在正式环境 | boolean |
必填 | - |
改写默认 Sentry 配置说明
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---|---|---|---|---|
| dsn | 项目唯一标识符 | String |
必填 | - |
| debug | 打开或关闭调试模式 | Boolean |
- | false |
| release | 版本号 | String |
- | |
| environment | 应用程序的当前环境 | String |
- | isPro? production: test |
| tracesSampleRate | 上报比例 | Number |
- | isPro? 1.0: 0.5 |
| maxBreadcrumbs | 溯源步数 | Number |
- | 30 |
| attachProps | 是否上传 Vue 组件的 Prop 数据。 | Boolean |
- | true |
| logErrors | 是否使用原始 Vue 的 logError | Boolean |
- | true |
| attachStacktrace | 将堆栈跟踪附加到纯捕获消息/日志集成 | Boolean |
- | true |
| ignoreErrors | 上报过滤 | Array<String \\| RegExp> |
- | - |
| BrowserTracingOption | 浏览器跟踪选项 | BrowserTracingOptions |
- | - |
Methods
| 方法名 | 说明 | 参数 |
|---|---|---|
install |
初始化 | ISentryOption |
setScid |
设置 Scid | String |
setUserInfo |
设置用户信息 | Dictionary |
setRequest |
设置请求信息 | ISentryRequestOption |
clearUserInfo |
清除用户信息 | - |
captureEvent |
手动上报事件 | 参考官方文档说明 |
captureException |
手动上报错误事件 | 参考官方文档说明 |
captureMessage |
手动上报消息事件 | 参考官方文档说明 |
withScope |
临时上报数据,上报完成自动删除 | 参考官方文档说明 |
context |
继承 Sentry 方法实例 | - |
Types
文件链接: sentry.d.ts
import * as Sentry from '@sentry/vue';import { Options, TracingOptions } from '@sentry/vue/dist/types';import type { BrowserTracingOptions } from '@sentry/tracing/dist/browser/browsertracing';declare type Dictionary = Record<string, any>;declare type SentryOption = Omit<Options, 'tracingOptions'> & {tracingOptions: Partial<TracingOptions>;};declare type SentryInitOption = Partial<SentryOption>;declare type ExtendsOption = Required<Pick<SentryInitOption, 'dsn' | 'release' | 'Vue'>>;interface ISentryOption extends SentryInitOption {Vue: ExtendsOption['Vue'];release: ExtendsOption['release'];dsn: ExtendsOption['dsn'];isDev: boolean;isPro: boolean;scid?: string;BrowserTracingOption?: Partial<BrowserTracingOptions>;}interface ISentryRequestOption {/** 错误信息 */message: string;/** 请求链接 */url: string;/** 请求方法 */method: string;/** 状态码 */status: number;/** 响应数据 */data: Dictionary;/** 请求参数 */body: Dictionary;/** 请求头 */header: Dictionary;}declare class ISentry {private static options;static install(opts: ISentryOption): void;/** 设置scid */static setScid(scid: string): void;/** 设置用户信息 */static setUserInfo(userInfo: Dictionary): void;/** 上报请求错误 */static setRequest(options: ISentryRequestOption): void;/** 清除用户信息 */static clearUserInfo(): void;private static ignoreErrors;static captureException: typeof Sentry.captureException;static captureEvent: typeof Sentry.captureEvent;static captureMessage: typeof Sentry.captureMessage;static withScope: typeof Sentry.withScope;static context: typeof Sentry;}export default ISentry;
