@snapback/infrastructure
v0.1.2
Published
Production-grade observability toolkit - structured logging, distributed tracing, and performance monitoring for TypeScript applications
Readme
@snapback/infrastructure
Production-grade observability toolkit for TypeScript applications
Part of SnapBack - structured logging, distributed tracing, and performance monitoring to help you understand what's happening in your code safety systems.
What is SnapBack?
SnapBack is a code safety platform that prevents breaking changes in your codebase through snapshots, file protection, and risk analysis. This infrastructure package provides the observability tools needed to monitor and debug these safety systems in production.
What's This Package?
Production-ready logging and telemetry infrastructure for TypeScript applications. Built for high-performance observability without vendor lock-in.
- 📊 Structured Logging - JSON-formatted logs with context
- 🔍 Distributed Tracing - Track operations across services
- ⚡ Performance Monitoring - Built-in metrics collection
- 🔌 Pluggable Backends - Send data anywhere (Datadog, New Relic, etc.)
Use this when:
- Building production TypeScript services
- Need structured logging without dependencies
- Want distributed tracing support
- Require vendor-agnostic observability
Installation
npm install @snapback/infrastructureQuick Start
Structured Logging
import { Logger } from '@snapback/infrastructure';
const logger = new Logger({
service: 'my-app',
environment: 'production'
});
logger.info('User signed in', {
userId: '123',
email: '[email protected]'
});
logger.error('Payment failed', {
userId: '123',
amount: 99.99,
error: err.message
});Features
Structured Logging
JSON-formatted logs with automatic context propagation.
import { Logger } from '@snapback/infrastructure';
const logger = new Logger({
service: 'api',
version: '1.0.0'
});
// Automatic context
logger.info('API request', {
method: 'POST',
path: '/api/users',
duration: 45
});
// Output:
// {
// "level": "info",
// "message": "API request",
// "service": "api",
// "version": "1.0.0",
// "method": "POST",
// "path": "/api/users",
// "duration": 45,
// "timestamp": "2025-01-04T12:00:00.000Z"
// }Distributed Tracing
Track operations across service boundaries.
import { Tracer } from '@snapback/infrastructure';
const tracer = new Tracer();
// Start a trace
const span = tracer.startSpan('process-payment');
span.setAttribute('amount', 99.99);
span.setAttribute('currency', 'USD');
try {
await processPayment();
span.setStatus('success');
} catch (error) {
span.setStatus('error');
span.recordException(error);
} finally {
span.end();
}Performance Monitoring
Built-in metrics for performance tracking.
import { metrics } from '@snapback/infrastructure';
// Record metrics
metrics.increment('api.requests');
metrics.histogram('api.duration', 45);
metrics.gauge('active.connections', 150);Integration Examples
With Express
import express from 'express';
import { Logger, requestLogger } from '@snapback/infrastructure';
const app = express();
const logger = new Logger({ service: 'api' });
// Add request logging
app.use(requestLogger(logger));
app.get('/users', (req, res) => {
logger.info('Fetching users', { count: users.length });
res.json(users);
});With Datadog
import { Logger } from '@snapback/infrastructure';
const logger = new Logger({
service: 'api',
backends: [{
type: 'datadog',
apiKey: process.env.DATADOG_API_KEY
}]
});Configuration
import { Logger } from '@snapback/infrastructure';
const logger = new Logger({
service: 'my-app',
environment: process.env.NODE_ENV,
level: 'info', // Minimum log level
pretty: false, // Pretty print (dev only)
version: '1.0.0',
backends: [
{ type: 'console' }, // Log to console
{ type: 'file', path: './logs/app.log' }
]
});SnapBack Ecosystem
Part of the complete code safety platform:
| Package | Purpose | Documentation | |---------|---------|---------------| | @snapback/contracts | TypeScript types | Docs | | @snapback/sdk | Complete SDK | Docs | | @snapback/infrastructure | Observability (you are here) | Docs | | @snapback/events | Event bus | Docs | | @snapback/config | Configuration | Docs |
Resources
- 🌐 Website: snapback.dev
- 📖 Documentation: docs.snapback.dev
- 🐛 Report Issues: GitHub Issues
- 💬 Get Help: [email protected]
Contributing
See our Contributing Guide.
License
Apache-2.0 © SnapBack
Commercial use allowed • See LICENSE
snapback.dev • Documentation • @snapbackdev
Made with ❤️ for developers who ship with confidence
