@autonomize/sdk-js
v1.0.10
Published
A lightweight, easy-to-use SDK for implementing OpenTelemetry in Node.js and Nest.js applications. This SDK provides unified instrumentation for traces, metrics, and logs with automatic context propagation.
Downloads
282
Keywords
Readme
OpenTelemetry SDK for Express.js
A lightweight, easy-to-use SDK for implementing OpenTelemetry in Node.js and Nest.js applications. This SDK provides unified instrumentation for traces, metrics, and logs with automatic context propagation.
Features
- 📊 Unified Metrics Collection - Track custom metrics with counters, histograms, and up/down counters
- 🔍 Distributed Tracing - Automatic trace context propagation across services
- 📝 Structured Logging - Logs automatically correlated with traces
- 🔌 Auto-Instrumentation - Built-in support for HTTP, Express, and NestJS
- 🎯 Zero Configuration - Sensible defaults with flexible customization options
Installation
# Using npm
npm install
# Using yarn
yarn add
# Using pnpm
pnpm install
Quick Start
import { TelemetrySDK } from 'autonomize/opentelemetry-sdk';
// Initialize the SDK
const telemetry = new TelemetrySDK({
serviceName: 'your-service-name',
environment: 'production',
otlpEndpoint: 'http://localhost:4318' // Your OpenTelemetry collector endpoint
});
// Start the SDK
await telemetry.start();
// Create and use metrics
const requestCounter = telemetry.createCounter({
name: 'http_requests_total',
description: 'Total number of HTTP requests'
});
// Add logs with trace context
telemetry.info('Application started', { version: '1.0.0' });
// Handle errors with automatic trace correlation
try {
// Your code
} catch (error) {
telemetry.error('Operation failed', error);
}
Configuration
interface TelemetryConfig {
serviceName: string; // Your service name
environment: string; // e.g., 'development', 'production'
version?: string; // Service version
otlpEndpoint?: string; // OpenTelemetry collector endpoint
metricIntervalMs?: number; // Metric export interval
}
Contributing
We welcome contributions! Here's how you can help:
Fork the Repository
git clone https://github.com/autonomize/opentelemetry-sdk.git cd opentelemetry-sdk
Install Dependencies
npm install
Create a Branch
git checkout -b feature/your-feature-name
Make Your Changes
- Write tests for new features
- Follow the existing code style
- Update documentation as needed
Run Tests
npm test
Submit a Pull Request
- Describe your changes
- Link any related issues
- Update the changelog
Development Guidelines
- Write clear commit messages
- Add TypeScript types for all new code
- Include unit tests for new features
- Update documentation and examples
- Follow semantic versioning
License
MIT License - see LICENSE for details
Related Projects
Changelog
[1.0.0] - 2024-01-01
- Initial release
- Basic metrics, traces, and logs support
- Express and NestJS integration