mini-sentry-sdk weekly downloads statistics
By yourname · npm · Webpack plugins
Lightweight monitoring SDK for web applications with automatic sourcemap upload
mini-sentry-sdk has 96 recorded weekly downloads on npm, an increase of 586% over the past 30 days, ranking #2635 of 3,247 tracked listings.
About mini-sentry-sdk
Mini-Sentry SDK 使用说明文档
📋 目录
🚀 快速开始
安装
npm install mini-sentry-sdk
# 或
yarn add mini-sentry-sdk
基础使用
import { Monitor } from 'mini-sentry-sdk';
// 创建监控实例
const monitor = new Monitor({
projectId: 'your-project-id',
apiUrl: 'https://your-api-server.com/api'
});
// 初始化监控
monitor.init();
📦 安装配置
1. 项目依赖
确保项目满足以下要求:
- Node.js >= 14.0.0
- 现代浏览器支持 (支持 ES2019)
- React >= 16.8.0 (如果使用 React 功能)
2. 安装方式
NPM/Yarn 安装 (推荐)
npm install mini-sentry-sdk
CDN 引入
<script src="https://unpkg.com/mini-sentry-sdk/dist/index.min.js"></script>
ES Module
import { Monitor, ErrorBoundary } from 'mini-sentry-sdk';
CommonJS
const { Monitor, ErrorBoundary } = require('mini-sentry-sdk');
🎯 基础用法
1. 创建监控实例
import { Monitor } from 'mini-sentry-sdk';
const monitor = new Monitor({
projectId: 'PROJ-123456', // 必需:项目ID
apiUrl: 'https://api.example.com', // 必需:上报接口地址
debug: false, // 可选:调试模式
sampleRate: 1, // 可选:采样率 (0-1)
maxBreadcrumbs: 10, // 可选:面包屑数量限制
defaultTags: { // 可选:默认标签
version: '1.0.0',
environment: 'production'
},
enabledModules: { // 可选:启用的模块
error: true,
performance: true,
behavior: true
}
});
// 初始化
await monitor.init();
2. 手动错误上报
// 捕获错误
try {
throw new Error('Something went wrong');
} catch (error) {
monitor.captureError(error, {
userId: '12345',
action: 'button_click'
});
}
// 追踪事件
monitor.trackEvent('user', 'Login Success', {
loginMethod: 'email'
});
// 追踪性能指标
monitor.trackMetric('api_response_time', 1200, {
endpoint: '/api/users'
});
// 追踪业务事件
monitor.trackBusiness('purchase', {
orderId: 'ORDER-001',
amount: 99.99
});
🔧 功能详解
错误监控
自动捕获的错误类型:
- JavaScript 运行时错误
- Promise 未处理的拒绝
- 资源加载错误
- HTTP 请求错误
- React 组件错误(配合 ErrorBoundary)
错误信息包含:
- 错误堆栈信息
- 用户行为轨迹(面包屑)
- 设备和浏览器信息
- 当前页面 URL
- 自定义标签
性能监控
监控指标:
- TTFB: 首字节时间
- FCP: 首次内容绘制
- LCP: 最大内容绘制
- DOM Ready: DOM 准备时间
- Load Complete: 页面完全加载时间
- Long Tasks: 长任务检测 (>50ms)
使用示例:
// 性能数据会自动收集,也可以手动获取状态
const vitalsStatus = monitor.getVitalsStatus();
console.log('性能指标状态:', vitalsStatus);
// 调试 LCP 问题
monitor.debugLcpSituation();
用户行为追踪
自动追踪的行为:
- 页面访问和路由变化
- 用户点击事件
- 表单提交
- 滚动行为
- 页面可见性变化
- 页面停留时间
自定义行为追踪:
// 添加自定义面包屑
monitor.addBreadcrumb(
'user', // 类别
'Button clicked', // 消息
'info', // 级别
{ buttonId: 'submit' } // 数据
);
网络监控
自动拦截:
- Fetch API 请求
- XMLHttpRequest 请求
- 请求失败和超时
- HTTP 状态码异常
🗺️ SourceMap 配置
1. Webpack 配置
步骤 1:配置 webpack.config.js
const MiniSentryWebpackPlugin = require('mini-sentry-sdk/webpack-plugin');
module.exports = {
// 生产环境必须开启 sourcemap
devtool: 'source-map',
plugins: [
new MiniSentryWebpackPlugin({
projectId: 'PROJ-123456',
apiUrl: 'https://your-api.com/sourcemap',
apiKey: 'your-api-key',
enabled: true, // 是否启用
uploadInDev: false, // 开发环境是否上传
include: ['**/*.map'], // 包含的文件
exclude: ['node_modules/**'], // 排除的文件
deleteAfterUpload: true, // 上传后删除本地文件
debug: false, // 调试模式
timeout: 30000, // 上传超时时间
retries: 3 // 重试次数
})
]
};
步骤 2:构建项目
npm run build
构建时插件会自动:
- 收集生成的 .map 文件
- 上传到指定的 API 地址
- 删除本地 sourcemap 文件(可配置)
2. 手动上传 SourceMap
import { SourceMapUploader } from 'mini-sentry-sdk';
const uploader = new SourceMapUploader({
apiUrl: 'https://your-api.com/sourcemap',
apiKey: 'your-api-key',
debug: true
});
// 上传文件
const result = await uploader.upload({
projectId: 'PROJ-123456',
timestamp: Date.now(),
files: [
{
filename: 'main.abc123.js.map',
content: sourceMapContent,
size: sourceMapContent.length,
jsFilename: 'main.abc123.js'
}
]
});
3. SourceMap 最佳实践
文件命名规范:
- JS 文件:
main.abc123.js(包含 hash) - SourceMap 文件:
main.abc123.js.map
生产环境安全:
// webpack.config.js
module.exports = {
devtool: process.env.NODE_ENV === 'production' ? 'hidden-source-map' : 'eval-source-map'
};
⚛️ React 集成
1. ErrorBoundary 使用
import React from 'react';
import { ErrorBoundary, Monitor } from 'mini-sentry-sdk';
// 创建监控实例
const monitor = new Monitor({
projectId: 'PROJ-123456',
apiUrl: 'https://your-api.com'
});
monitor.init();
function App() {
return (
<ErrorBoundary
projectId="PROJ-123456"
onError={(errorInfo) => {
// 可选:自定义错误处理
console.log('捕获到 React 错误:', errorInfo);
}}
tags={{
component: 'App',
version: '1.0.0'
}}
fallback={
<div>
<h2>页面出现错误</h2>
<p>我们已经记录了这个问题,请刷新页面重试。</p>
</div>
}
>
<YourApp />
</ErrorBoundary>
);
}
2. Hook 集成
import { useEffect } from 'react';
import { Monitor } from 'mini-sentry-sdk';
const monitor = new Monitor({
projectId: 'PROJ-123456',
apiUrl: 'https://your-api.com'
});
export function useMonitoring() {
useEffect(() => {
monitor.init();
return () => {
monitor.destroy();
};
}, []);
return {
captureError: monitor.captureError.bind(monitor),
trackEvent: monitor.trackEvent.bind(monitor),
trackMetric: monitor.trackMetric.bind(monitor)
};
}
// 使用
function MyComponent() {
const { captureError, trackEvent } = useMonitoring();…
Description from the npm listing.
- monitoring
- error-tracking
- performance
- analytics
- sourcemap
- webpack-plugin
- sentry
README badge
Show your rank in a README or on your website. The badge updates automatically.
Charts
Images: 30d · 1y · all time · 1600×900 dark
Adoption over time
7/30/90-day growth
Ranking history
Listing placement
Listing placement
Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.
Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.
Recent observations
Full history (170)Similar npm Webpack plugins plugins
All 20 mini-sentry-sdk alternativesData source
Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.
Listing: https://www.npmjs.com/package/mini-sentry-sdk. First seen Oct 16, 2026; last successful collection Oct 22, 2026. See the methodology.