Socket
Book a DemoInstallSign in
Socket

@loyalvalleycapital/monitor

Package Overview
Dependencies
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@loyalvalleycapital/monitor

A log lib for RN and web project

1.2.1
latest
npmnpm
Version published
Weekly downloads
2
Maintainers
2
Weekly downloads
 
Created
Source

埋点,错误上报 sdk

安装

如果通过一些其他工具配置了安装源,那么--registry参数可以忽略

# npm
npm install @loyalvalleycapital/monitor --registry=xxxxx
# yarn
yarn add @loyalvalleycapital/monitor --registry=xxxx

使用

目前打出 2 个版本的 js,一个包含UserAgent库的,一个不包含的(为了减少包体积,概况可以减少33kb),默认指向不包括的UserAgent。如果需要引入包含UserAgent的 js,需要配置下 webpack 别名:

{
	alias: {
		// ...other alias
		monitorsdk: 'monitorsdk/dist/monitorsdk-web.js',
	}
}
import monitor, { setCustomError } from ' @loyalvalleycapital/monitor'

monitor.trackEv(...)

setCustomError(err, {code: 'xxx', custom: {}})

用法跟之前相同,因为抽取成 npm 包的形式复用,所有有些参数必须通过外部传递进来。 以下几点需要注意:

  • 每个项目的全局Promise捕获,希望每个项目有不同的错误码,所以在初始的时候monitor.init(),传入一个projectErrCode参数:
monitor.init({
  projectErrCode: 'ERR020000',
  其他选项,
  // ...
})
  • 因为现在wrapperRequest这个 redux 中间件里把请求的错误都抛出了,所以在使用的时候,通过setCustomError把相关的一些错误信息配置到error对象上,方便全局统一捕获
import { setCustomError  } from "@loyalvalleycapital/monitor";
.catch(error => {
	next({
		type,
		payload: {
			error,
			loading: false,
			status: 'failure',
			params,
		},
	});
	if (errorCallback) errorCallback();
	// 这里
	setCustomError(error, {
		code: 'ERR02000002',
		custom: payload
	})
	return Promise.reject(error);
)

上面的错误码只是示例,具体的项目可以自定义,定义的时候可以在这里维护下

Keywords

log

FAQs

Package last updated on 07 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.