api-monitor
v2.1.9 โข STABLE
Monitor and debug your API responses in real-time with redaction support.
Readme.md
# @sannuk792/api-response-monitor
> [!IMPORTANT]
> **Part of the [Professional Node.js Backend Toolkit](https://github.com/sannuk79/PROJECTS-AND-NPM-PACKAGES-)** โ Production-ready API monitoring with zero-config tracing.
<p align="center">
<strong>๐ Production-Ready API Monitoring & Response Tracking</strong>
</p>
<div align="center">
<img src="https://img.shields.io/npm/v/@sannuk792/api-response-monitor" alt="NPM Version">
<img src="https://img.shields.io/bundlephobia/minzip/@sannuk792/api-response-monitor" alt="Bundle Size">
<img src="https://img.shields.io/npm/dm/@sannuk792/api-response-monitor" alt="Downloads">
<img src="https://img.shields.io/badge/TypeScript-Supported-blue" alt="TypeScript">
<img src="https://img.shields.io/badge/Node.js-14%2B-green" alt="Node.js 14+">
</div>
---
## ๐ Core Highlights
> **"Debug APIs like a senior dev โ proactive, not reactive."**
> - **Zero-Config Tracing** โ Automatic request ID injection
> - **Proactive Alerts** โ Slow endpoint detection before users complain
> - **Negligible Overhead** โ High-performance design for scale
> - **Multi-Platform** โ Node.js, React Native, Browser support
---
## ๐ Architecture Overview
### **System Flow**
```mermaid
graph LR
C[Client] --> M[Middleware]
M --> E[Event Bus]
E --> D[Dashboard]
E --> S[Storage/Adapters]
E --> A[Alerting/Webhooks]
```
### **Request Lifecycle**
```mermaid
graph LR
A[Request] --> B[Generate RequestID]
B --> C[Intercept Response]
C --> D[Calculate Metrics]
D --> E[Async Logging/Storage]
E --> F[Dashboard Sync]
```
### **Workflow Details**
1. **Request Received**: `requestId` auto-generated or extracted from headers
2. **Response Intercepted**: Native `res.json`/`res.send` wrapped
3. **Metrics Calculated**: Precise latency via `process.hrtime`
4. **Event Emitted**: Sanitized, non-blocking event to emitter
5. **Async Processing**: Plugins run, logs written, storage updated
---
## โจ Key Features
### ๐ **Extensible Plugin Architecture**
Extend without modifying core code:
```javascript
const { slowQueryPlugin, tagPlugin } = require('@sannuk792/api-response-monitor');
plugins: [
slowQueryPlugin(500), // Warn on >500ms
tagPlugin({ env: 'prod' })
]
```
### ๐ฏ **Production-Ready Features**
- **Log Levels** โ Filter by `debug`, `info`, `warn`, `error`
- **Request ID / Trace ID** โ Automatic request tracking across services
- **Performance Mode** โ Minimal overhead for high-traffic apps
- **Slow Endpoint Detection** โ Real-time warnings for latency spikes
- **Alerting System** โ Error rate & latency threshold alerts with Webhooks
- **Storage Adapters** โ MongoDB, PostgreSQL, Elasticsearch support
### ๐ฑ **Multi-Platform Support**
| Platform | Status | Package |
|----------|--------|---------|
| **Node.js/Express** | โ
Full Support | Core |
| **React Native** | โ
Offline-First SDK | `/react-native` |
| **Browser (Fetch)** | โ
Interceptor | Core |
| **Browser (Axios)** | โ
Interceptor | Core |
| **Angular** | ๐ Coming Soon | - |
| **Python** | ๐ Coming Soon | - |
---
## ๐๏ธ Core Components
### **Architecture Modules**
```mermaid
graph TB
A[Express Middleware] --> B[Request Interceptor]
A --> C[Response Interceptor]
B --> D[Request ID Generator]
C --> E[Metrics Calculator]
E --> F[Event Emitter]
F --> G[Plugin System]
F --> H[Storage Adapters]
F --> I[Alerting System]
G --> J[Dashboard]
H --> K[Database]
I --> L[Webhooks/Slack]
```
### **Core Modules**
| Module | Purpose | Key Feature |
|--------|---------|-------------|
| **Middleware** | Request/Response interception | Auto-wrapping |
| **EventEmitter** | Async event distribution | Non-blocking |
| **MetricsCalculator** | Latency & status tracking | `process.hrtime` precision |
| **PluginSystem** | Extensible logic injection | Async execution |
| **StorageAdapter** | Persistent logging | MongoDB/Postgres/ES |
| **AlertingSystem** | Threshold-based alerts | Webhooks/Slack |
| **Dashboard** | Real-time analytics UI | Built-in |
---
## ๐ก๏ธ Security & Safety
### **Built-in Protections**
- โ
**Non-Blocking** โ All processing is async
- โ
**Sampling Support** โ Reduce overhead in high-traffic
- โ
**Sensitive Data Redaction** โ Auto-filter passwords, tokens
- โ
**Error Isolation** โ Monitoring failures never break requests
- โ
**Configurable Log Levels** โ Control verbosity
### **Fail-Safe Design**
```mermaid
graph TD
A[Request] --> B{Monitor Active?}
B -->|Yes| C[Normal Monitoring]
B -->|No| D[Skip Monitoring]
C --> E{Error in Monitor?}
D --> F[Request Continues]
E -->|Yes| G[Log Error Silently]
E -->|No| H[Send to Dashboard]
G --> F
H --> F
```
---
## ๐ฆ Package Info
- **Version**: 2.1.9
- **License**: MIT
- **Author**: sannuk792
- **Node.js**: >=14.0.0
- **TypeScript**: Supported
- **Dependencies**: 0 production dependencies
---
## ๐งช Testing
### **Test Coverage**
```bash
npm test
npm run test:smoke
```
---
## ๐ Version History
| Version | Features | Status |
|---------|----------|--------|
| **1.0.0 - 1.5.0** | Basic monitoring | โ
Stable |
| **1.5.1 - 2.0.0** | Plugin system | โ
Stable |
| **2.0.1 - 2.3.0** | React Native SDK | โ
Current |
---
## ๐ Links
- **GitHub**: [api-response-monitor](https://github.com/sannuk79/PROJECTS-AND-NPM-PACKAGES-)
- **NPM**: [@sannuk792/api-response-monitor](https://www.npmjs.com/package/@sannuk792/api-response-monitor)
- **Issues**: [Report a bug](https://github.com/sannuk79/PROJECTS-AND-NPM-PACKAGES-/issues)