@yhy2001/sentry-plugin
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

Sentry Plugin

这是一个为 JavaScript 应用集成 Sentry 错误跟踪系统的插件。它提供了简单的 API 来配置和使用 Sentry,支持链式调用和 Sentry 自带的所有方法。

安装

使用 npm 安装:

npm install @yhy2001/sentry-plugin

或者使用 yarn:

yarn add @yhy2001/sentry-plugin

快速开始

首先,您需要在 Sentry 上创建一个项目并获取您的 DSN。然后,在您的应用中初始化 Sentry Plugin:

import { SentryPlugin, VueIntegration } from '@yhy2001/sentry-plugin';
SentryPlugin.init({
  dsn: 'YOUR_SENTRY_DSN',
  // 其他 Sentry 配置
}, new VueIntegration());

配置

您可以通过 init 方法传入配置对象来配置 Sentry。以下是一些常用的配置项:

  • dsn: 您的 Sentry DSN。
  • environment: 设置应用的环境,如 'production' 或 'development'。
  • release: 指定应用的版本。

完整的配置选项请参考 Sentry 官方文档

使用

设置用户信息

SentryPlugin.setUser({
  id: 'user_id',
  email: 'user@example.com',
  // 其他用户信息
});

添加标签

SentryPlugin.setTags({
  key: 'value',
  // 其他标签
});

添加额外信息

SentryPlugin.setExtras({
  key: 'value',
  // 其他额外信息
});

记录面包屑

SentryPlugin.addBreadcrumb({
  message: 'User clicked the button',
  // 其他面包屑信息
});

手动记录错误

SentryPlugin.captureException(new Error('This is an error'));

手动发送消息

SentryPlugin.captureMessage('Something happened', 'info');

错误级别

SentryPlugin.warn('This is an warn');
SentryPlugin.info('This is an info', {
  tags: {
    "tagOne": 'tag'
  },
  user: {
    id: 1
  }
});
SentryPlugin.error('This is an error');

链式调用

Sentry Plugin 支持链式调用,您可以轻松地在一行代码中设置多个配置:

SentryPlugin
  .setUser({ id: 'user_id' })
  .setTags({ key: 'value' })
  .addBreadcrumb({ message: 'Breadcrumb' })
  .captureMessage('Something happened');

调用 Sentry 原生方法

如果您需要调用 Sentry 的其他方法,可以使用 callSentryMethod

SentryPlugin.callSentryMethod('showReportDialog');

贡献

欢迎通过 Pull Requests 或 Issues 来贡献您的代码或反馈。

许可证

MIT


Package Sidebar

Install

npm i @yhy2001/sentry-plugin

Weekly Downloads

7

Version

1.0.6

License

ISC

Unpacked Size

889 kB

Total Files

13

Last publish

Collaborators

  • yhy2001