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)