@gravito/spectrum 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +111 -0
- package/package.json +73 -0
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# @gravito/spectrum
|
|
2
|
+
|
|
3
|
+
> **Your telescope into the Gravito universe — real-time insights, zero configuration.**
|
|
4
|
+
|
|
5
|
+
`@gravito/spectrum` is a powerful, zero-config debug dashboard designed specifically for the Gravito ecosystem. It acts as a telescope for your application, capturing HTTP requests, database queries, logs, and exceptions in real-time.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## ✨ Features
|
|
10
|
+
|
|
11
|
+
- **⚡️ Real-time Updates**: Powered by Server-Sent Events (SSE), observe requests as they happen without refreshing.
|
|
12
|
+
- **🔍 Deep Inspection**: View detailed request/response headers, bodies, and execution time.
|
|
13
|
+
- **🗄️ Database Profiling**: Automatically captures `@gravito/atlas` SQL queries with bindings and duration.
|
|
14
|
+
- **↺ Request Replay**: One-click replay of any captured request to quickly reproduce bugs or test fixes.
|
|
15
|
+
- **📊 Live Statistics**: Monitor error rates, average latency, and throughput in real-time.
|
|
16
|
+
- **💾 Persistence**: Support for File-based storage to keep debug data across server restarts.
|
|
17
|
+
- **🛡️ Security Gates**: Configurable authorization logic to secure the dashboard in sensitive environments.
|
|
18
|
+
|
|
19
|
+
## 📦 Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
bun add @gravito/spectrum
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 🚀 Quick Start
|
|
26
|
+
|
|
27
|
+
Simply register the `SpectrumOrbit` in your application entry point:
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { PlanetCore } from 'gravito-core'
|
|
31
|
+
import { SpectrumOrbit } from '@gravito/spectrum'
|
|
32
|
+
|
|
33
|
+
const core = new PlanetCore()
|
|
34
|
+
|
|
35
|
+
// Initialize Spectrum (Development only recommended)
|
|
36
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
37
|
+
await core.orbit(new SpectrumOrbit())
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
await core.liftoff()
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Visit **http://localhost:3000/gravito/spectrum** to see your dashboard.
|
|
44
|
+
|
|
45
|
+
## ⚙️ Configuration
|
|
46
|
+
|
|
47
|
+
You can customize Spectrum by passing a configuration object.
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
await core.orbit(new SpectrumOrbit({
|
|
51
|
+
// Change the dashboard path
|
|
52
|
+
path: '/_debug',
|
|
53
|
+
|
|
54
|
+
// Storage Strategy (Memory or File)
|
|
55
|
+
storage: new MemoryStorage(),
|
|
56
|
+
|
|
57
|
+
// Sample Rate (0.0 to 1.0)
|
|
58
|
+
// Useful for high-traffic environments to prevent flooding
|
|
59
|
+
sampleRate: 1.0,
|
|
60
|
+
|
|
61
|
+
// Security Gate (Authorization)
|
|
62
|
+
gate: async (c) => {
|
|
63
|
+
// Return true to allow access
|
|
64
|
+
return c.req.ip === '127.0.0.1'
|
|
65
|
+
}
|
|
66
|
+
}))
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## 🛡️ Production Safety
|
|
70
|
+
|
|
71
|
+
Spectrum is designed primarily for **local development**. If you enable it in production, you **MUST** follow these rules:
|
|
72
|
+
|
|
73
|
+
1. **Configure a Gate**: Never leave the dashboard open to the public.
|
|
74
|
+
2. **Enable Persistence**: Use `FileStorage` so data isn't lost on restart, or stick to `MemoryStorage` to avoid filling up disk space.
|
|
75
|
+
3. **Set Sample Rate**: Set `sampleRate: 0.1` (10%) or lower to avoid performance impact on high-traffic sites.
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
if (process.env.NODE_ENV === 'production') {
|
|
79
|
+
await core.orbit(new SpectrumOrbit({
|
|
80
|
+
storage: new FileStorage({ directory: './storage/spectrum' }),
|
|
81
|
+
sampleRate: 0.05, // Capture only 5% of requests
|
|
82
|
+
gate: async (c) => c.req.header('x-admin-token') === process.env.ADMIN_TOKEN
|
|
83
|
+
}))
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## 🔌 Integrations
|
|
88
|
+
|
|
89
|
+
### Database (Atlas)
|
|
90
|
+
|
|
91
|
+
If `@gravito/atlas` is installed and loaded in your application, Spectrum automatically detects it and begins capturing all database queries. No extra configuration is needed.
|
|
92
|
+
|
|
93
|
+
### Logs (Logger)
|
|
94
|
+
|
|
95
|
+
Spectrum automatically wraps the core logger. Any call to `core.logger.info()`, `debug()`, `warn()`, or `error()` is captured and displayed in the dashboard alongside the request context.
|
|
96
|
+
|
|
97
|
+
## ❓ Spectrum vs Monitor
|
|
98
|
+
|
|
99
|
+
| Feature | `@gravito/spectrum` | `@gravito/monitor` |
|
|
100
|
+
|---------|---------------------|--------------------|
|
|
101
|
+
| **Goal** | **Local Debugging** | **Cluster Observability** |
|
|
102
|
+
| **Interface** | Built-in UI Dashboard | JSON / Prometheus / OTLP |
|
|
103
|
+
| **Scope** | Single Node (Stateful) | Distributed (Stateless) |
|
|
104
|
+
| **Data Retention** | Short-term (Recent 100) | Long-term (TSDB) |
|
|
105
|
+
| **Best For** | Developers fixing bugs | DevOps monitoring uptime |
|
|
106
|
+
|
|
107
|
+
If you are running in Kubernetes or Serverless and need aggregated logs from multiple instances, use **@gravito/monitor** with an external backend like Grafana or Datadog.
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gravito/spectrum",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "Debug Dashboard and Observability UI for Gravito framework.",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/index.cjs",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/index.d.cts",
|
|
20
|
+
"default": "./dist/index.cjs"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "bun run build.ts",
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
|
+
"test": "bun test",
|
|
32
|
+
"test:coverage": "bun test --coverage --coverage-threshold=80",
|
|
33
|
+
"test:ci": "bun test --coverage --coverage-threshold=80"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"gravito-core": "1.0.0-beta.6",
|
|
37
|
+
"@gravito/photon": "1.0.0-beta.1"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/bun": "latest",
|
|
41
|
+
"@opentelemetry/api": "^1.9.0",
|
|
42
|
+
"@opentelemetry/sdk-node": "^0.57.0",
|
|
43
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.57.0",
|
|
44
|
+
"@opentelemetry/resources": "^1.29.0",
|
|
45
|
+
"@opentelemetry/semantic-conventions": "^1.28.0",
|
|
46
|
+
"gravito-core": "1.0.0-beta.6",
|
|
47
|
+
"tsup": "^8.2.4",
|
|
48
|
+
"typescript": "^5.9.3"
|
|
49
|
+
},
|
|
50
|
+
"optionalDependencies": {
|
|
51
|
+
"@opentelemetry/api": "^1.9.0",
|
|
52
|
+
"@opentelemetry/sdk-node": "^0.57.0",
|
|
53
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.57.0",
|
|
54
|
+
"@opentelemetry/resources": "^1.29.0",
|
|
55
|
+
"@opentelemetry/semantic-conventions": "^1.28.0"
|
|
56
|
+
},
|
|
57
|
+
"keywords": [
|
|
58
|
+
"gravito",
|
|
59
|
+
"observability",
|
|
60
|
+
"health-check",
|
|
61
|
+
"metrics",
|
|
62
|
+
"tracing",
|
|
63
|
+
"opentelemetry",
|
|
64
|
+
"prometheus"
|
|
65
|
+
],
|
|
66
|
+
"author": "Gravito Team",
|
|
67
|
+
"license": "MIT",
|
|
68
|
+
"repository": {
|
|
69
|
+
"type": "git",
|
|
70
|
+
"url": "https://github.com/gravito-framework/gravito.git",
|
|
71
|
+
"directory": "packages/monitor"
|
|
72
|
+
}
|
|
73
|
+
}
|