Skip to content

platform-logging

Sentry integration for centralized error tracking and analytics. Provides structured error reporting with context enrichment.

Package: @breadstone/archipel-platform-logging

Quick Start

typescript
import { Module } from '@nestjs/common';
import { LoggerModule } from '@breadstone/archipel-platform-logging';

@Module({
  imports: [LoggerModule],
})
export class AppModule {}

AnalyticsService

Central service for error and event reporting to Sentry.

typescript
import { AnalyticsService } from '@breadstone/archipel-platform-logging';

@Injectable()
export class PaymentService {
  constructor(private readonly _analytics: AnalyticsService) {}

  public async processPayment(orderId: string): Promise<void> {
    try {
      // ... payment logic
    } catch (error) {
      this._analytics.captureException(error, {
        tags: { module: 'payments', orderId },
      });
      throw error;
    }
  }
}

Environment Variables

VariableDescriptionRequired
SENTRY_DSNSentry Data Source NameYes
SENTRY_ENVIRONMENTEnvironment label (e.g. 'production', 'staging')No
SENTRY_TRACES_SAMPLE_RATESampling rate for performance traces (0.0–1.0)No

Real-World Example: Global Error Filter

typescript
import { Catch, type ExceptionFilter, type ArgumentsHost } from '@nestjs/common';
import { AnalyticsService } from '@breadstone/archipel-platform-logging';

@Catch()
export class GlobalExceptionFilter implements ExceptionFilter {
  constructor(private readonly _analytics: AnalyticsService) {}

  public catch(exception: unknown, host: ArgumentsHost): void {
    this._analytics.captureException(exception);

    const ctx = host.switchToHttp();
    const response = ctx.getResponse();
    response.status(500).json({ error: 'Internal Server Error' });
  }
}

Exports Summary

ExportTypeDescription
LoggerModuleNestJS ModuleGlobal Sentry integration
AnalyticsServiceServiceError capture and event tracking

Released under the MIT License.