Useful nestjs libs using AsyncLocalStorage.
This monorepo provides useful libraries for NestJS applications, leveraging AsyncLocalStorage for advanced context management and instrumentation. It is designed to support a variety of production and advanced use cases, and will grow to include more libraries over time.
Comprehensive New Relic instrumentation for NestJS applications with advanced transaction management, distributed tracing, and event-driven monitoring.
Key Features:
- β Controller-based Transaction Management - Automatic transaction creation and context management
- β Message Queue Instrumentation - SQS, Kafka, and custom queue consumers
- β HTTP/2 Compatibility - Works with modern HTTP/2 applications
- β Background Job Tracing - Cron jobs, scheduled tasks, and async workers
- β Distributed Tracing - Cross-service transaction correlation
- β Event-Driven Monitoring - Real-time transaction lifecycle events
- β Async Context Preservation - Maintains transaction context across async operations
- β Custom Transaction Naming - Based on controller and handler names
Installation:
npm install newrelic-nestjs-instrumentation
# or
pnpm add newrelic-nestjs-instrumentationQuick Start:
import { Module } from '@nestjs/common';
import { NestJsNewrelicInstrumentationModule } from 'newrelic-nestjs-instrumentation';
@Module({
imports: [NestJsNewrelicInstrumentationModule],
})
export class AppModule {}This project uses a modern monorepo setup optimized for development efficiency and CI/CD automation.
- π¦ Package Manager: pnpm - Fast, disk space efficient package manager
- π Build System: Turbo - High-performance build system for JavaScript/TypeScript monorepos
- π§ͺ Testing: Jest - Comprehensive testing framework with coverage reporting
- π Code Quality: ESLint + Prettier - Linting and formatting
- π Commit Standards: Commitlint - Conventional commit message validation
- π Git Hooks: Husky - Pre-commit and pre-push validation
- π·οΈ Release Management: Automated semantic versioning and publishing
nestjs-context/
βββ .github/
β βββ workflows/ # GitHub Actions CI/CD pipelines
βββ libs/ # Package libraries (add your own!)
β βββ newrelic-nestjs-instrumentation/
β βββ otel-nestjs-instrumentation/
βββ scripts/ # Build and utility scripts
βββ .husky/ # Git hooks
βββ .jest/ # Jest configuration
βββ turbo.json # Turbo build configuration
βββ pnpm-workspace.yaml # pnpm workspace configuration
βββ commitlint.config.js # Commit message rules
βββ package.json # Root package configuration
- Node.js >= 22
- pnpm >= 10.12.4
- Git
-
Clone the repository
git clone https://github.com/codibre/nestjs-context.git cd nestjs-context -
Install dependencies
pnpm install
-
Run tests
pnpm test -
Build packages
pnpm build
# Build all packages
pnpm build
# Run all tests
pnpm test
# Run tests with coverage
pnpm test:cov
# Lint all packages
pnpm lint
# Auto-fix linting issues
pnpm lint:fix
# Format code
pnpm prettier:fix
# Validate commit messages
pnpm commit:validateFocus on your logic, not formatting while developing. The project has automated tools to handle code style:
# After writing your code, run this to fix all formatting/linting issues:
pnpm lint:fixThis command will automatically:
- β Fix ESLint rule violations
- β Format code with Prettier
- β Organize imports
- β Remove unused variables
- β Apply consistent code style
Pre-commit hooks will also run these fixes automatically when you commit, so you can stay in the flow of coding without interruption!
- Strict TypeScript configuration
- Comprehensive type definitions
- TSDoc documentation for all public APIs
- Unit Tests: All business logic and utilities
- Integration Tests: Real HTTP request testing with spies
- Coverage: Maintained above 80%
- Test Structure: Descriptive names, success/error scenarios
We use Conventional Commits:
# Examples
feat(newrelic): add support for HTTP/2 instrumentation
fix(events): resolve memory leak in event emitter
docs(readme): update installation instructions
test(guard): add integration tests for transaction contextCommit Types:
feat: New featuresfix: Bug fixesdocs: Documentation changestest: Test additions or modificationsrefactor: Code refactoringperf: Performance improvementschore: Build process or auxiliary tool changes
The monorepo uses intelligent change detection to automatically:
- Detect Changed Packages: Only builds and tests packages that have changes
- Semantic Versioning: Automatically bumps versions based on conventional commits
- Automated Publishing: Publishes to npm registry when changes are merged to main
- Release Notes: Generates changelogs from commit messages
# Automatically triggers on:
# - Pull requests (run tests)
# - Push to main (run tests + publish if needed)
# - Manual dispatch (force publish)Pipeline Steps:
- Setup: Node.js, pnpm, dependencies
- Build: Compile TypeScript, generate types
- Test: Unit tests, integration tests, coverage
- Lint: Code style and formatting checks
- Publish: Automatic npm publishing for changed packages
Releases are fully automated:
- Commit Changes: Using conventional commit format
- Create PR: CI runs all tests and checks
- Merge to Main: Automatic version bump and publishing
- Monitor: Check npm and GitHub releases
We welcome contributions! Here's how to get started:
# Fork on GitHub, then clone your fork
git clone https://github.com/your-username/nestjs-context.git
cd nestjs-contextgit checkout -b feat/your-feature-name# Install dependencies
pnpm install
# Make your changes
# Add tests for new functionality
# Update documentation
# Validate your changes
pnpm build
pnpm test
pnpm lint# Use conventional commit format
git add .
git commit -m "feat(scope): description of your changes"
git push origin feat/your-feature-name- Provide clear description of changes
- Link any related issues
- Ensure all CI checks pass
- Code follows style guidelines
- Tests pass locally
- New functionality has tests
- Documentation is updated
- Commit messages follow conventional format
- No breaking changes (or properly documented)
- Identify Use Case: What isn't covered by existing instrumentation?
- Design Solution: Integration with existing components vs. new components
- Implement with Tests: Comprehensive unit and integration tests
- Documentation: Update README, add examples, document APIs
- Reproduce Issue: Create test demonstrating the bug
- Fix Minimally: Smallest change to resolve the issue
- Test Thoroughly: Verify fix + full test suite + edge cases
-
Create Package Directory
mkdir libs/your-new-package cd libs/your-new-package -
Package Configuration
# Create package.json with proper workspace config # Add to pnpm-workspace.yaml # Configure turbo.json for build pipeline
-
Development Setup
# Add scripts in turbo.json # Configure Jest for testing # Set up TypeScript configuration
- Use
--runInBandfor consistent test execution - Mock external dependencies (New Relic, databases, etc.)
- Test both success and error scenarios
- Maintain high coverage (>80%)
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: Check package-specific READMEs in
libs/ - Issues: GitHub Issues
- Discussions: GitHub Discussions
- β Battle-tested in high-traffic production environments
- β Comprehensive testing with >90% coverage
- β Performance optimized with minimal overhead
- β Error resilient with graceful degradation
- β TypeScript first with complete type definitions
- β Easy integration with minimal configuration
- β Extensive documentation with real-world examples
- β Active maintenance with regular updates
- β Distributed tracing across microservices
- β Custom transaction naming for better monitoring
- β Event-driven architecture for real-time insights
- β Background job instrumentation for complete visibility
Built with β€οΈ by Codibre