spinal-obs-node
Version:
WithSpinal cost-aware OpenTelemetry SDK for Node.js
234 lines (183 loc) ⢠6.39 kB
Markdown
This guide explains what you get when you install the Spinal Observability SDK and how to use it effectively.
```bash
npm install spinal-obs-node
```
When you install `spinal-obs-node`, you automatically receive:
- ā
**OpenTelemetry Integration** - Full OpenTelemetry SDK for Node.js
- ā
**HTTP Instrumentation** - Automatic HTTP request tracking
- ā
**Cost Tracking** - Built-in cost estimation for LLM APIs
- ā
**Privacy Protection** - Automatic data scrubbing and PII filtering
- ā
**Local Mode** - Offline-capable local storage and analysis
- ā
**`spinal` command** - Available globally via `npx spinal`
- ā
**Status checking** - `spinal status` for configuration overview
- ā
**Usage reports** - `spinal report` for cost and usage analysis
- ā
**Configuration** - `spinal init` for setup assistance
The following packages are automatically installed and managed:
```json
{
"@opentelemetry/api": "^1.9.0", // Core API
"@opentelemetry/instrumentation-http": "^0.203.0", // HTTP tracking
"@opentelemetry/instrumentation-undici": "^0.14.0", // HTTP client tracking
"@opentelemetry/resources": "^2.0.1", // Resource management
"@opentelemetry/sdk-trace-base": "^2.0.1", // Tracing SDK
"@opentelemetry/sdk-trace-node": "^2.0.1", // Node.js tracing
"@opentelemetry/semantic-conventions": "^1.36.0" // Standard attributes
}
```
```json
{
"commander": "^14.0.0", // CLI argument parsing
"conf": "^14.0.0", // Configuration management
"keytar": "^7.9.0", // Secure credential storage
"open": "^10.2.0", // Browser opening for auth
"undici": "^7.13.0" // HTTP client for cloud mode
}
```
- **Package Size**: 26.7 kB (compressed)
- **Unpacked Size**: 129.4 kB
- **Node.js Version**: Requires Node.js 18.0.0 or higher
- **TypeScript Support**: Built-in type definitions included
```typescript
import { configure, instrumentHTTP, instrumentOpenAI, tag, shutdown } from 'spinal-obs-node'
// Initialize
configure()
instrumentHTTP()
instrumentOpenAI()
// Add context
const t = tag({ aggregationId: 'user-flow', tenant: 'acme' })
// ... your code ...
t.dispose()
// Cleanup
await shutdown()
```
```bash
npx spinal status
npx spinal report
npx spinal init
```
```typescript
// Use SDK in your code
import { configure, instrumentHTTP, tag } from 'spinal-obs-node'
configure()
instrumentHTTP()
// Use CLI for analysis
// npx spinal report --since 24h
```
The following are **NOT** installed for end users (only for development):
```json
{
"devDependencies": {
"@eslint/js": "^9.33.0", // Linting (dev only)
"@types/node": "^24.2.1", // TypeScript types (dev only)
"@vitest/coverage-v8": "^2.1.9", // Testing (dev only)
"eslint": "^9.33.0", // Linting (dev only)
"tsup": "^8.5.0", // Building (dev only)
"typescript": "^5.9.2", // TypeScript (dev only)
"typescript-eslint": "^8.39.1", // TypeScript linting (dev only)
"vitest": "^2.1.9" // Testing (dev only)
}
}
```
```
spinal-obs-node/
āāā dist/
ā āāā index.js
ā āāā index.cjs
ā āāā cli/index.js
ā āāā cli/index.cjs
āāā docs/
āāā README.md
```
- ā
All dependencies are from trusted npm packages
- ā
No external scripts or binaries
- ā
All code is open source and auditable
- ā
API request metadata (URLs, methods, status codes)
- ā
Performance timing data
- ā
Cost estimation data
- ā
Custom contextual tags
### **What Gets Scrubbed**
- ā API keys and authentication tokens
- ā Request/response content
- ā User messages or prompts
- ā PII data (emails, names, etc.)
## š **Getting Started**
### **1. Install the Package**
```bash
npm install spinal-obs-node
```
### **2. Initialize in Your App**
```typescript
import { configure, instrumentHTTP, instrumentOpenAI } from 'spinal-obs-node'
// Initialize once at app startup
configure()
instrumentHTTP()
instrumentOpenAI()
```
```typescript
import { tag } from 'spinal-obs-node'
const t = tag({
aggregationId: 'user-chat-flow',
tenant: 'acme-corp'
})
// Your OpenAI API call here
const response = await openai.chat.completions.create({
model: 'gpt-4o-mini',
messages: [{ role: 'user', content: 'Hello!' }]
})
t.dispose()
```
```bash
echo ".spinal/" >> .gitignore
```
This prevents accidentally committing local telemetry data to version control.
```bash
npx spinal status
npx spinal report --since 24h
```
- ā
No API key required
- ā
Data stored locally
- ā
Works offline
- ā
Free forever
- š Requires API key
- āļø Data sent to Spinal cloud
- š Advanced analytics dashboard
- š¢ Team collaboration features
- [QUICKSTART.md](./QUICKSTART.md) - Get started in minutes
- [LOCAL_MODE.md](./LOCAL_MODE.md) - Local mode storage guide
- [TRACKING.md](./TRACKING.md) - What data gets tracked
- [README.md](../README.md) - Complete SDK documentation
- **Documentation**: Check the [README.md](../README.md)
- **Issues**: [GitHub Issues](https://github.com/withspinal/obs-node/issues)
- **Email**: founders@withspinal.com