# @lsner/raven-baidu

> Sentry SDK for BaiduLite

Latest version **0.0.12-0** (published 2020-09-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install @lsner/raven-baidu
pnpm add @lsner/raven-baidu
yarn add @lsner/raven-baidu
bun add @lsner/raven-baidu
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.12-0 |
| Published | 2020-09-15 |
| First published | 2019-07-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 25.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | lsner |
| Maintainers | lsner |

## Links

- npm: https://www.npmjs.com/package/@lsner/raven-baidu
- npm.io page: https://npm.io/package/@lsner/raven-baidu

## Recent versions

- 0.0.12-0 (latest) — 2020-09-15
- 0.0.11 — 2020-09-14
- 0.0.10 — 2020-09-14
- 0.0.9 — 2020-09-11
- 0.0.8 — 2020-09-11
- 0.0.7 — 2020-04-17
- 0.0.6 — 2020-04-10
- 0.0.5 — 2020-04-09
- 0.0.4 — 2020-04-09
- 0.0.3 — 2020-02-20
- 0.0.2 — 2019-07-15
- 0.0.1 — 2019-07-15

## README

# Raven-weapp

为方便百度小程序接入 sentry，由 raven 改写而来的百度小程序版本。

#### 支持微信、百度、头条、qq、支付宝小程序

#### 引入文件

由于目前小程序不支持从 node_modules 中引入文件，因此以 npm 方式安装的话只能手动将 raven-weapp/dist 目录下需要的文件拷贝到其他文件中，在 app.js 中引入，例如：

```
var Raven = require('./utils/raven-weapp/build/raven')
```

或以 Bower 安装 raven-weapp 并引入：

```
var Raven = require('./bower_components/raven-weapp/build/raven')
```

#### 初始化 Raven

```
Raven.config('https://xxx@crash.youzan.com/x', options).install()
```

在 app 的 onLaunch 中初始化(?)，options 为可选配置对象，目前支持：

```
options = {
    release: '当前小程序版本'，
    environment: '指定为production才会上报',
    allowDuplicates: true, // 允许相同错误重复上报
    sampleRate: 0.5 // 采样率
}
```

#### 收集信息

收集的信息将在上报时被一起带上

##### 基本信息

初始化后 raven 会默认收集以下信息：

```
{
    SDKversion: '小程序基础库版本',
    BDversion: '百度版本',
    device: '设备型号',
    network: '网络类型',
    system: '系统信息',
}
```

可以通过[Raven.setUserContext(context)](https://docs.sentry.io/learn/context/#capturing-the-user)或者[Raven.setExtraContext(context)](https://docs.sentry.io/learn/context/#extra-context)添加更多信息（kdtId 和 userId 等）

##### 用户行为

###### console

console 的行为默认将被自动收集

###### ajax

wx.request 不可扩展，因此只能手动收集请求的行为：例如在经过封装的请求函数的成功回调内添加：

```
Raven.captureBreadcrumb({
  category: 'ajax',
  data: {
    method: 'get',
    url: 'weapp.showcase.page/1.0.0/get',
    status_code: 200
  }
```

###### dom

ui 操作的记录暂不支持

###### location

页面变化的记录暂不支持

#### 信息上报

分为 message 和 exception 的上报

##### message

使用[Raven.captureMessage(msg, option)](https://docs.sentry.io/clients/javascript/usage/#capturing-messages)上报需要上报的信息比如 ajax 的报错等

##### exception

所有 uncaught exception 都会被小程序捕获封装成 msg 传递到 app 的 onError 中，在 onError 中上报这些信息：

```
onError(msg) {
    Raven.captureException(msg, {
      level: 'error'
    })
  }
```

---
_Source: https://npm.io/package/@lsner/raven-baidu · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
