W

wizinsight

A lightweight performance monitoring & health tracking library for hyperwiz with Discord alerts, GDPR compliance, and smart request optimization.

$npm install wizinsight
Get Started

Powerful Features

Everything you need to monitor your APIs and get instant alerts when things go wrong.

📊

Request Metrics

Track performance of individual API requests with detailed timing and error information.

🏥

Health Monitoring

Monitor multiple API endpoints with automatic alerts and status tracking.

🔔

Discord Integration

Get instant notifications when APIs go down with customizable Discord webhooks.

Zero Configuration

Works out of the box with sensible defaults. No complex setup required.

🛡️

TypeScript Support

Full type safety and IntelliSense support for the best developer experience.

🚀

Lightweight

Minimal overhead with smart request optimization and efficient monitoring.

🚀 Quick Start

Get up and running with wizinsight in less than 2 minutes.

Basic Usage

typescript
import { createClient } from 'hyperwiz'
import { initMetricsInterceptor } from 'wizinsight'

// Create your hyperwiz client
const client = createClient('https://api.example.com')

// Enable automatic metrics tracking
initMetricsInterceptor(client)

// All requests are now automatically tracked!
const users = await client.get('/users')

📈 Request Metrics

Track the performance of your API requests with detailed timing and error information.

What You Get Automatically

Request method and URL
⏱️Response time (duration)
📊HTTP status code
📦Request/response sizes
Basic Monitoring
typescript
import { createClient } from 'hyperwiz'
import { initMetricsInterceptor } from 'wizinsight'

const client = createClient('https://api.example.com')
initMetricsInterceptor(client)

// Console output:
// ✅ GET /users - 245ms - 200 OK
// ✅ POST /users - 180ms - 201 Created
// ❌ GET /invalid - 1200ms - 404 Not Found

Custom Logging

typescript
initMetricsInterceptor(client, {
  onRequestEnd: (metrics) => {
    console.log(`🚀 ${metrics.method} ${metrics.url} took ${metrics.duration}ms`)
  },
  
  onRequestError: (metrics) => {
    console.error(`💥 ${metrics.method} ${metrics.url} failed: ${metrics.errorMessage}`)
  }
})

Performance Alerts

typescript
initMetricsInterceptor(client, {
  onRequestEnd: (metrics) => {
    // Alert on slow requests
    if (metrics.duration > 1000) {
      console.warn(`🐌 Slow request: ${metrics.method} ${metrics.url} took ${metrics.duration}ms`)
    }
    
    // Alert on errors
    if (metrics.status >= 400) {
      console.error(`❌ Error: ${metrics.method} ${metrics.url} returned ${metrics.status}`)
    }
  }
})

❤️ Health Monitoring

Monitor the health of multiple API endpoints with automatic alerts and status tracking.

🤔 Why Health Monitoring?

Discover the key benefits that make health monitoring essential for modern applications

🔍

Proactive Monitoring

Catch issues before users do with intelligent monitoring that detects problems early

📢

Instant Alerts

Get notified immediately when APIs go down with real-time Discord notifications

📊

Status Tracking

Keep track of API health over time with detailed metrics and historical data

🛡️

Prevent Downtime

Identify and fix issues quickly before they impact your users and business

💡Health monitoring is the foundation of reliable applications

Basic Health Monitoring

typescript
import { initHealthMonitor, getHealthStatus } from 'wizinsight'

// Simple health monitoring
initHealthMonitor({
  targets: [
    { name: 'User API', url: 'https://api.example.com/users' },
    { name: 'Auth API', url: 'https://auth.example.com/health' },
    { name: 'Database', url: 'https://db.example.com/ping' }
  ]
})

// Check current health status
const health = getHealthStatus()
console.log(health)

Health Monitoring with Discord Alerts

typescript
initHealthMonitor({
  targets: [
    { name: 'Production API', url: 'https://api.production.com/health' },
    { name: 'Staging API', url: 'https://api.staging.com/health' }
  ],
  interval: 30000, // Check every 30 seconds
  discordWebhook: 'https://discord.com/api/webhooks/your-webhook-url',
  alertCooldown: 600000 // 10 minutes between alerts
})

Discord Alert Example:

🚨 Health Check Failed: Production API
API endpoint is not responding as expected

🔗 URL: https://api.production.com/health
📊 Status: 503
⏱️ Response Time: 245ms
🎯 Expected: 200
❌ Error: Expected 200, got 503

📝 Real-World Examples

See how to use wizinsight in production environments with real API testing examples.

Complete Production Setup

typescript
// In your main application file
import { createClient } from 'hyperwiz'
import { initMetricsInterceptor, initHealthMonitor } from 'wizinsight'

// Set up API client with metrics
const client = createClient('https://api.yourcompany.com')
initMetricsInterceptor(client, {
  onRequestEnd: (metrics) => {
    if (metrics.duration > 1000) {
      console.warn(`Slow API call: ${metrics.url}`)
    }
  }
})

// Set up comprehensive health monitoring
initHealthMonitor({
  targets: [
    // Basic health check
    { name: 'Main API', url: 'https://api.yourcompany.com/health' },
    
    // Test login
    {
      name: 'Login Service',
      url: 'https://api.yourcompany.com/login',
      method: 'POST',
      body: { username: 'healthuser', password: 'healthpass' },
      expectedStatus: 200
    },
    
    // Test registration
    {
      name: 'Registration',
      url: 'https://api.yourcompany.com/register',
      method: 'POST',
      body: { 
        email: 'health@test.com', 
        password: 'testpass',
        name: 'Health Test User'
      },
      expectedStatus: 201
    },
    
    // Test protected endpoint
    {
      name: 'User Profile',
      url: 'https://api.yourcompany.com/user/profile',
      method: 'GET',
      headers: { 'Authorization': 'Bearer your-token-here' },
      expectedStatus: 200
    }
  ],
  interval: 30000,
  discordWebhook: process.env.DISCORD_WEBHOOK_URL
})

Advanced Health Check Examples

GraphQL Health Check

typescript
{
  name: 'GraphQL API',
  url: 'https://api.example.com/graphql',
  method: 'POST',
  body: { query: '{ __typename }' },
  expectedStatus: 200
}

Authentication Test

typescript
{
  name: 'Auth API',
  url: 'https://api.example.com/auth/verify',
  method: 'POST',
  body: { token: 'test-token' },
  headers: { 'Authorization': 'Bearer test-token' },
  expectedStatus: 200
}

File Upload Test

typescript
{
  name: 'File Upload',
  url: 'https://api.example.com/upload',
  method: 'POST',
  body: 'test-data',
  headers: { 'Content-Type': 'text/plain' },
  expectedStatus: 201
}

Timeout Configuration

typescript
{
  name: 'Slow API',
  url: 'https://api.example.com/slow',
  timeout: 5000,
  expectedStatus: 200
}

⚙️ Configuration Options

Comprehensive configuration options for all features.

Metrics Interceptor Options

OptionDescriptionDefault
onRequestStartCalled when request starts-
onRequestEndCalled when request completes-
onRequestErrorCalled when request fails-
collectRequestSizeTrack request payload sizefalse
collectResponseSizeTrack response payload sizefalse

Health Monitor Options

OptionDescriptionDefault
targetsArray of API endpoints to monitorRequired
intervalHealth check interval in milliseconds60000
discordWebhookDiscord webhook URL for alerts-
alertCooldownTime between alerts in milliseconds900000

Ready to Monitor Your APIs?

Start tracking your API performance and health in under 2 minutes.

$npm install wizinsight
View on npm