@lx-frontend/report

Sentry excepiton report.

Usage no npm install needed!

<script type="module">
  import lxFrontendReport from 'https://cdn.skypack.dev/@lx-frontend/report';
</script>

README

@lx-frontend/report

开发

1. 安装依赖

npm run bootstrap

2. 构建

npm run build

3. 发布

npm run publish

使用

1. 安装

npm install --save @lx-frontend/report

2. 初始化

使用:

import { init } from '@lx-frontend/report'

init({
  enable: process.env.RUN_ENV === 'production',
  platform: 'mp',
  dsn: 'https://2e7514ffe05d464caf4f4f447a7212f4@sentry.lixinio.com/20',
  release: '',
  environment: process.env.RUN_ENV
})

参数说明:

  • enable (boolean):是否开启 sentry 上报
  • platform (string):运行平台,传入 mp 或者 web,目前只支持 mp
  • dsn (string):sentry 密钥
  • release (string):项目版本
  • environment (string):运行环境

3. 上报 http 异常

使用:

import { reportHttpException,  } from '@lx-frontend/report'

const { config, data, header, statusCode } = res

const request = {
  url: config.url,
  method: config.method,
  header: config.header,
  body: config.body,
  timeout: config.timeout,
  custom: config.custom
}

const response = {
  status: statusCode,
  header,
  data
}

const tags = {
  user_id: 99
}

const extra = {
  test: 'hello'
}

reportHttpException({
  request,
  response,
  tags,
  extra
})

参数说明:

  • request (object)
    • url (string):请求链接
    • method (string):请求方法
    • header (object):请求头部
    • body (any):请求参数
    • timeout (number):请求超时时间(可选)
    • custom (object):自定义请求配置(可选)
  • response (object)
    • status (number):响应状态码
    • header (object):响应头部
    • data (any):响应数据
  • tags (object):自定义标签(可选)
  • extra (any):额外携带数据(可选)

4. 上报业务异常

使用:

import { reportBusinessException } from '@lx-frontend/report'

const extra = {
  test: 'hello'
}

reportBusinessException('上报业务异常', extra)

参数说明:

  • 参数一 (string):异常描述
  • 参数二 (any):额外携带数据(可选)

5. 上报 socket 异常

使用:

import { reportSocketException } from '@lx-frontend/report'

const extra = {
  test: 'hello'
}

reportSocketException('上报 socket 异常', extra)

参数说明:

  • 参数一 (string):异常描述
  • 参数二 (any):额外携带数据(可选)