1.0.0 • Published 9 months ago
@andeanwide/nestjs-rollbar v1.0.0
NestJS Rollbar Integration
A NestJS module that provides seamless integration with Rollbar for error tracking and logging.
Installation
npm install @andeanwide/nestjs-rollbar rollbarFeatures
- Global error tracking with Rollbar
- Async configuration support
- TypeScript support
- Environment-aware configuration
- Context tracking for better error tracing
Usage
Basic Setup
import { Module } from '@nestjs/common';
import { RollbarModule } from '@andeanwide/nestjs-rollbar';
@Module({
imports: [
RollbarModule.register({
accessToken: 'your-rollbar-access-token',
environment: 'production', // or 'development'
}),
],
})
export class AppModule {}Async Configuration
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { RollbarModule } from '@andeanwide/nestjs-rollbar';
@Module({
imports: [
RollbarModule.registerAsync({
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
accessToken: configService.get('ROLLBAR_ACCESS_TOKEN'),
environment: configService.get('NODE_ENV'),
}),
}),
],
})
export class AppModule {}Using the RollbarService
import { Injectable } from '@nestjs/common';
import { RollbarService } from '@andeanwide/nestjs-rollbar';
@Injectable()
export class YourService {
constructor(private readonly rollbar: RollbarService) {}
async doSomething() {
try {
// Your code here
} catch (error) {
this.rollbar.error(error);
}
// Log information
this.rollbar.log('Operation completed successfully');
// Log info level messages
this.rollbar.info('User logged in', { userId: '123' });
}
}Configuration Options
The module accepts all standard Rollbar configuration options plus:
accessToken(required): Your Rollbar project access tokenenvironment(optional): The environment name ('development' or 'production')
For a complete list of Rollbar configuration options, see the Rollbar documentation.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License
1.0.0
9 months ago