Skip to content

sunnyghodeswar/crashless-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Crashless Examples

A comprehensive examples repository demonstrating all Crashless features, from minimal one-liner setup to production-ready configurations with advanced telemetry and tracing capabilities.


Table of Contents


Installation

npm install

Quick Start

Run any example using the provided npm scripts:

# Simplest setup with auto-configuration
npm run example:one-liner

# Minimal error handling without telemetry
npm run example:basic

# Production-ready configuration
npm run example:production

# Production with secure dashboard
npm run example:production-dashboard

# Comprehensive feature demonstration
npm run example:full

Examples Overview

Example File Port Key Features
One-Liner Setup example-one-liner.js 3010 Auto-configured, zero-config dashboard
Basic example-basic.js 3001 Error handling only, lightweight
Production example-production.js 3002 Message masking, dashboard disabled
Production Dashboard example-production-dashboard.js 3000 Secure dashboard with IP whitelist
Built-in Engine example-builtin-engine.js 3003 Built-in telemetry with Prometheus export
Prometheus Engine example-prometheus-engine.js 3004 Prometheus metrics endpoint
OpenTelemetry Engine example-otel-engine.js 3005 OTLP-compatible metrics export
Custom Exporters example-exporters.js 3006 Multiple custom exporters (Sentry, Datadog)
Full-Featured example-full-featured.js 3007 Complete feature showcase
Automatic Tracing example-automatic-tracing.js 3000 Zero-instrumentation tracing
Tracing Demo tracing-demo.js 3008 Advanced distributed tracing
Dashboard Security example-dashboard-security.js 3011 Authentication and authorization

Example Details

1. One-Liner Setup

Purpose: Simplest possible implementation with automatic configuration.

npm run example:one-liner

Features:

  • Automatic async error handling
  • Built-in dashboard at http://localhost:3010/_crashless
  • Metrics collection
  • Request tracking
  • Zero configuration required

Port: 3010


2. Basic Example

Purpose: Minimal setup focusing solely on error handling without telemetry overhead.

npm run example:basic

Features:

  • Error handling only
  • No dashboard
  • No metrics collection
  • Lightweight configuration

Port: 3001


3. Production Example

Purpose: Production-ready configuration with security-focused defaults.

npm run example:production

Features:

  • Message masking for sensitive data
  • Stack traces hidden from responses
  • Dashboard disabled
  • Metrics export available at /metrics.json

Port: 3002


4. Production Dashboard

Purpose: Production deployment with secure dashboard access.

npm run example:production-dashboard

With Security Configuration:

NODE_ENV=production \
DASHBOARD_ALLOWED_IPS="127.0.0.1" \
DASHBOARD_SECRET="your-secret-token" \
npm run example:production-dashboard

Features:

  • Dashboard enabled in production environment
  • IP whitelist authentication
  • Token-based authentication
  • Production-safe defaults

Port: 3000


5. Built-in Engine

Purpose: Demonstrates built-in telemetry engine with dashboard and metrics export.

npm run example:builtin

Features:

  • Built-in metrics engine
  • Interactive dashboard
  • Prometheus export format
  • JSON metrics endpoint

Port: 3003


6. Prometheus Engine

Purpose: Integration with Prometheus monitoring systems.

npm run example:prometheus

Features:

  • Prometheus-compatible metrics endpoint
  • Dashboard enabled
  • JSON metrics export
  • Ready for Prometheus scraping

Port: 3004

Prometheus Configuration Example:

scrape_configs:
  - job_name: 'crashless'
    static_configs:
      - targets: ['localhost:3004']
    metrics_path: '/metrics'

7. OpenTelemetry Engine

Purpose: Integration with OpenTelemetry Protocol (OTLP) compatible systems.

npm run example:otel

Features:

  • OpenTelemetry metrics export
  • Dashboard enabled
  • JSON metrics endpoint
  • OTLP-compatible format

Port: 3005


8. Custom Exporters

Purpose: Demonstrates custom telemetry exporter implementation.

npm run example:exporters

Features:

  • Custom exporter registration
  • Multiple exporters (Sentry, Datadog, custom logger)
  • Telemetry callbacks
  • Structured logging

Port: 3006


9. Full-Featured Example

Purpose: Comprehensive demonstration of all available features.

npm run example:full

Features:

  • All error types demonstration
  • Custom errors with contextual details
  • Authentication simulation
  • Input validation
  • Multiple route configurations
  • Custom exporters
  • Telemetry callbacks

Port: 3007


10. Automatic Tracing

Purpose: Zero-instrumentation distributed tracing.

npm run example:automatic-tracing

Features:

  • Automatic HTTP request tracing
  • Automatic fetch() tracing
  • Automatic fs.readFile() tracing
  • Dashboard with traces visualization

Port: 3000


11. Tracing Demo

Purpose: Advanced distributed tracing with complex async operations.

npm run example:tracing

Features:

  • Complex async operation tracing
  • Multiple fetch() call tracking
  • Nested operation visualization
  • Error tracing
  • OTLP export

Port: 3008


12. Dashboard Security

Purpose: Comprehensive dashboard security configuration examples.

# Default configuration (localhost allowed)
npm run example:security

# IP whitelist configuration
npm run example:security:ip

# Token authentication
npm run example:security:token

# Production mode with security
npm run example:security:prod

Features:

  • Environment variable-based IP whitelist
  • Token authentication
  • Custom authentication functions
  • Production mode security handling

Port: 3011


Dashboard Screenshots

System Overview — Live Metrics Dashboard

System Overview

Real-time overview of your API's health metrics including total requests, error rate, latency, and uptime. The System tab provides instant visibility without requiring external setup, with automatic updates every few seconds.


Route-Level Performance Insights

Route-Level Performance

Detailed analysis of every endpoint's performance metrics including latency percentiles, status code distribution, and throughput. Quickly identify slow routes or failing APIs at a glance.


Error Analytics — Instant Failure Insights

Error Analytics

Real-time exception tracking with frequency charts and categorized breakdowns. Identify which routes fail most frequently and when error spikes occur.


Live Error Stream — Stack Traces as They Happen

Live Error Stream

Monitor new errors in real-time with complete stack traces and timestamps. Ideal for debugging during active traffic or load testing scenarios.


Light Mode Dashboard — Alternative Theme

Light Mode Dashboard

The dashboard automatically adapts to light mode preferences while maintaining clean, fast, and information-dense visualization.


Distributed Tracing — Waterfall View

Distributed Tracing

Comprehensive request lifecycle visualization with waterfall traces, including nested database calls, fetch operations, and external API calls. Precisely identify where time is spent from request initiation to completion.


Configuration Reference

All examples use standard npm install crashless installation and include:

  • Proper ES module imports: import crashless from 'crashless'
  • Automatic simulation capabilities
  • Detailed console logging
  • Dashboard and metrics endpoints
  • Production-ready configurations

Use Case Guide

Development and Quick Start

npm run example:one-liner

Access dashboard at http://localhost:3010/_crashless


Production Deployment (Dashboard Disabled)

npm run example:production

Metrics available at http://localhost:3002/metrics.json


Production Deployment (Secure Dashboard)

NODE_ENV=production \
DASHBOARD_ALLOWED_IPS="127.0.0.1" \
DASHBOARD_SECRET="your-secret-token" \
npm run example:production-dashboard

Secure dashboard at http://localhost:3000/_crashless (authentication required)


Prometheus Integration

npm run example:prometheus

Configure Prometheus to scrape from http://localhost:3004/metrics


OpenTelemetry Integration

npm run example:otel

OTLP metrics available at http://localhost:3005/metrics/otel


Custom Exporter Implementation

npm run example:exporters

Monitor console output for custom exporter data


Distributed Tracing

npm run example:tracing

Access traces at http://localhost:3008/traces.json


Resources


Notes

  • All examples include automatic simulation capabilities
  • Each example runs on a dedicated port to prevent conflicts
  • Examples are production-ready and can be adapted for specific use cases
  • Comprehensive logging is included in all examples
  • Examples run independently and do not require external dependencies beyond Crashless

Author

Sunny Ghodeswar


Built with ❤️ for the Node.js community

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors