feat(#369): install @mosaicstack/telemetry-client in API
- Add .npmrc with scoped Gitea npm registry for @mosaicstack packages - Create MosaicTelemetryModule (global, lifecycle-aware) at apps/api/src/mosaic-telemetry/ - Create MosaicTelemetryService wrapping TelemetryClient with convenience methods: trackTaskCompletion, getPrediction, refreshPredictions, eventBuilder - Create mosaic-telemetry.config.ts for env var integration via NestJS ConfigService - Register MosaicTelemetryModule in AppModule - Add 32 unit tests covering module init, service methods, disabled mode, dry-run mode, and lifecycle management Refs #369 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
37
apps/api/src/mosaic-telemetry/mosaic-telemetry.module.ts
Normal file
37
apps/api/src/mosaic-telemetry/mosaic-telemetry.module.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { Module, Global } from "@nestjs/common";
|
||||
import { ConfigModule } from "@nestjs/config";
|
||||
import { MosaicTelemetryService } from "./mosaic-telemetry.service";
|
||||
|
||||
/**
|
||||
* Global module providing Mosaic Telemetry integration via @mosaicstack/telemetry-client.
|
||||
*
|
||||
* Tracks task completion events and provides crowd-sourced predictions for
|
||||
* token usage, cost estimation, and quality metrics.
|
||||
*
|
||||
* **This is separate from the OpenTelemetry (OTEL) TelemetryModule** which
|
||||
* handles distributed request tracing. This module is specifically for
|
||||
* Mosaic Stack's own telemetry aggregation service.
|
||||
*
|
||||
* Configuration via environment variables:
|
||||
* - MOSAIC_TELEMETRY_ENABLED (boolean, default: true)
|
||||
* - MOSAIC_TELEMETRY_SERVER_URL (string)
|
||||
* - MOSAIC_TELEMETRY_API_KEY (string, 64-char hex)
|
||||
* - MOSAIC_TELEMETRY_INSTANCE_ID (string, UUID)
|
||||
* - MOSAIC_TELEMETRY_DRY_RUN (boolean, default: false)
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // In any service (no need to import module — it's global):
|
||||
* @Injectable()
|
||||
* export class MyService {
|
||||
* constructor(private readonly telemetry: MosaicTelemetryService) {}
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
@Global()
|
||||
@Module({
|
||||
imports: [ConfigModule],
|
||||
providers: [MosaicTelemetryService],
|
||||
exports: [MosaicTelemetryService],
|
||||
})
|
||||
export class MosaicTelemetryModule {}
|
||||
Reference in New Issue
Block a user