upch-simulation-observability
v0.1.2
Published
Shared NestJS observability: pino JSON logging, prom-client /metrics, and /healthz for every UPCH service.
Maintainers
Readme
upch-simulation-observability
Shared NestJS observability for every UPCH service: structured pino JSON
logging, a prom-client /metrics endpoint, and a /healthz health check —
behind a single module import.
Install
npm install upch-simulation-observabilityPeer dependencies (provided by the host NestJS app):
npm install @nestjs/common @nestjs/core reflect-metadata rxjsUsage
1. Import the module
// app.module.ts
import { ObservabilityModule } from 'upch-simulation-observability';
@Module({
imports: [
ObservabilityModule.forRoot({ serviceName: 'auth-ms' }),
// ...
],
})
export class AppModule {}forRoot is global: true, registers the MetricsController (/metrics) and
HealthController (/healthz), and wires pino logging.
2. Wire it into bootstrap
// main.ts
import { setupObservability } from 'upch-simulation-observability';
const app = await NestFactory.create(AppModule);
await setupObservability(app, { serviceName: 'auth-ms' });- HTTP service (gateway / WS): call after
create, before the service's ownapp.listen(). LeavemetricsPortundefined —/metricsand/healthzride along on the app's own port (exclude them from any global API prefix). - TCP-only microservice: pass
metricsPort. This opens the single hybrid app's HTTP listener on that port for/metrics+/healthzonly (Prometheus cannot scrape a TCP transport).
await setupObservability(app, { serviceName: 'auth-ms', metricsPort: 9101 });Prisma health check (optional)
import { prismaHealthProvider } from 'upch-simulation-observability';Register prismaHealthProvider to surface DB connectivity in /healthz.
Exports
ObservabilityModule, setupObservability, MetricsInterceptor,
MetricsController, HealthController, buildPrismaHealthCheck,
prismaHealthProvider, getMetrics, PinoLogger, plus the DI tokens
OBSERVABILITY_SERVICE_NAME, OBSERVABILITY_METRICS,
OBSERVABILITY_HEALTH_CHECK and their types.
License
MIT
