npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

bl-monitor-sdk

v1.1.24

Published

前端监控 + 日志采集合并 SDK

Readme

bl-monitor-sdk

版本更新指令

npm run release # 等于 npm version patch → build → publish 自动 +0.0.1 npm run release minor # 等于 npm version minor → build → publish 自动 +0.1.0 npm run release major # 等于 npm version major → build → publish 自动 +1.0.0

是的,完全正确!这是一个完整的项目监控 SDK

项目整体架构

从文件结构和代码分析来看,这是一个功能完整的监控 SDK:

1. SDK 定位

  • 项目级监控解决方案:不是简单的日志工具,而是完整的监控系统
  • 跨平台支持:Web、微信小程序、uni-app 等多端兼容
  • 生产级工具:具备采样、去重、批量上报等企业级功能

2. 核心功能模块

bl-monitor-sdk/
├── src/
│   ├── index.js          # SDK 入口,统一初始化管理
│   ├── core.js           # 核心收集类,负责数据上报
│   └── plugins/          # 插件化监控功能
│       ├── error.js      # 错误监控
│       ├── performance.js # 性能监控  
│       ├── network.js    # 网络监控
│       └── log.js        # 日志记录
├── dist/                 # 构建产物
└── package.json          # 包配置

3. 监控能力覆盖

  • 自动错误监控(无需手动调用):
    • ✅ 全局运行时错误(window.onerror)
    • ✅ Promise未捕获异常(unhandledrejection)
    • ✅ 资源加载失败(图片、脚本、样式等)
    • ✅ console.error 自动捕获和上报
    • ✅ console.warn 自动捕获和上报
    • ✅ 网络请求失败(fetch错误)
    • ✅ Vue框架错误(Vue 2/3)
    • ✅ 小程序全局错误和Promise异常
  • 性能监控:页面加载时间、TTFB、DOM 解析时间
  • 网络监控:API 请求监控(network.js)
  • 日志记录:结构化日志记录和上报
  • 用户行为:通过日志可以追踪用户操作

4. 企业级特性

  • 采样控制:避免数据量过大
  • 去重机制:防止重复上报
  • 批量上报:优化网络请求
  • 重试机制:提高上报成功率
  • 多端兼容:一套 SDK 支持多个平台

5. 使用场景

这个 SDK 适用于:

  • Web 应用:React、Vue、Angular 等前端项目
  • 小程序: ✅ 微信小程序 (wx) ✅ 支付宝小程序 (my) ✅ 抖音小程序 (tt)
  • 混合应用:uni-app、Taro 等跨端框架
  • 企业级项目:需要完整监控体系的大型项目

6. 部署方式

dist/ 目录可以看出,支持多种模块格式:

  • ES Module (bl-monitor-sdk.es.js)
  • CommonJS (bl-monitor-sdk.cjs.js)
  • UMD (bl-monitor-sdk.umd.js)

7. 典型使用流程

Web项目

// 1. 安装和引入
import { initMonitor, getLogger } from 'bl-monitor-sdk';

// 2. 初始化监控
const { logger } = initMonitor({
  endpoint: 'https://your-monitor-api.com',
  framework: 'web',  // 明确指定平台
  enableError: true,
  enablePerformance: true,
  enableNetwork: false,
  sampleRate: 0.1,  // 生产建议0.1-0.3;开发测试建议1.0,便于调试
  batchSize: 1,     // 1=立即上报, >1=批量上报
  maxRetries: 3,
  retryDelay: 1000,
  // 性能指标阈值配置(单位:毫秒),只有超过阈值才上报
  performanceThresholds: {
    ttfb: 500,        // TTFB阈值,默认500ms
    fcp: 1000,        // FCP阈值,默认1000ms
    domLoad: 2000,    // DOM加载阈值,默认2000ms
    load: 3000,       // 页面加载阈值,默认3000ms
    fsp: 2000,        // 首屏渲染阈值,默认2000ms
    launchTime: 3000  // 小程序启动时间阈值,默认3000ms
  }
});

// 3. 之后所有错误会自动上报,无需手动调用!
// ✅ 运行时错误自动捕获(window.onerror)
// ✅ Promise异常自动捕获(unhandledrejection)
// ✅ console.error 自动上报
// ✅ console.warn 自动上报
// ✅ 资源加载失败自动上报
// ✅ 网络请求失败自动上报
// ✅ Vue框架错误自动捕获

// 4. 也可以手动记录业务日志(可选)
logger.info('用户操作', { userId: 123, action: 'login' });
logger.error('业务错误', { orderId: 456, reason: 'payment_failed' });

UniApp项目(重要:避免平台混淆)

import { initMonitor } from 'bl-monitor-sdk';

// UniApp打包的微信H5、小程序等,必须明确指定framework
const { logger } = initMonitor({
  endpoint: 'https://your-monitor-api.com',
  framework: 'uniapp',  // 重要!避免与微信平台混淆
  enableError: true,
  enablePerformance: true,
  enableNetwork: false,
  sampleRate: 0.1,  // 生产建议0.1-0.3;开发测试建议1.0,便于调试
  batchSize: 1,     // 1=立即上报, >1=批量上报
  maxRetries: 3,
  retryDelay: 1000,
  // 性能指标阈值配置(单位:毫秒),只有超过阈值才上报
  performanceThresholds: {
    ttfb: 500,        // TTFB阈值,默认500ms
    fcp: 1000,        // FCP阈值,默认1000ms
    domLoad: 2000,    // DOM加载阈值,默认2000ms
    load: 3000,       // 页面加载阈值,默认3000ms
    fsp: 2000,        // 首屏渲染阈值,默认2000ms
    launchTime: 3000  // 小程序启动时间阈值,默认3000ms
  }
});

logger.info('页面加载', { page: 'home' });

8. Framework 配置说明

为什么需要配置 framework?

在UniApp打包的微信H5项目中,会同时存在 uniwx 对象,导致平台检测混淆。通过明确指定 framework 参数,可以确保SDK使用正确的平台和请求方法。

支持的 framework 值:

  • 'uniapp' - UniApp框架(包括打包的各平台)
  • 'wechat-miniprogram' - 微信小程序
  • 'alipay-miniprogram' - 支付宝小程序
  • 'douyin-miniprogram' - 抖音小程序
  • 'web' - Web浏览器

配置建议:

  • UniApp项目:必须设置 framework: 'uniapp'
  • 原生小程序:明确指定对应的小程序类型
  • Web项目:可选,建议设置 framework: 'web'

所以这确实是一个完整的项目监控 SDK,类似于 Sentry、阿里云 ARMS、腾讯云 RUM 等专业监控工具,但更轻量化和定制化。