@dudousxd/nestjs-telescope
Version:
Laravel Telescope-style observability console for NestJS — core: watchers, recorder, correlation, SQLite store, headless API.
86 lines • 4.41 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
var TelescopeWatcherRegistrar_1;
// packages/core/src/nest/telescope-watcher-registrar.service.ts
import { Inject, Injectable, Logger } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import { EntryType } from '../entry/entry.js';
import { ExtensionRegistry } from '../extension/registry.js';
import { TELESCOPE_CONFIG, TELESCOPE_EXTENSIONS, TELESCOPE_OPTIONS, } from './telescope.options.js';
import { TelescopeService } from './telescope.service.js';
import { createWatcherContext } from './watcher-context.factory.js';
let TelescopeWatcherRegistrar = TelescopeWatcherRegistrar_1 = class TelescopeWatcherRegistrar {
options;
config;
service;
extensions;
moduleRef;
logger = new Logger(TelescopeWatcherRegistrar_1.name);
constructor(options, config, service, extensions, moduleRef) {
this.options = options;
this.config = config;
this.service = service;
this.extensions = extensions;
this.moduleRef = moduleRef;
}
async onApplicationBootstrap() {
if (!this.config.enabled)
return;
const watchers = [...(this.options.watchers ?? []), ...this.extensions.watchers()];
const ctx = createWatcherContext(this.service, this.config, this.moduleRef);
const registered = [];
for (const watcher of watchers) {
try {
await watcher.register(ctx);
// Only report a watcher as active once it has actually wired up — a
// failed register() must not show as "watching" in /meta.
registered.push(watcher.type);
}
catch (error) {
this.logger.error(`Telescope watcher "${watcher.type}" failed to register: ${error.message}`);
}
}
// Client-error ingestion isn't a "watcher" (no register() call), but the
// dashboard's watcher-driven nav keys the "Client errors" tab off the meta
// list — so surface its type only when the public endpoint is enabled.
const clientErrorTypes = this.options.clientErrors?.enabled === true ? [EntryType.ClientException] : [];
const extensionTypes = this.extensions.entryTypes().map((e) => e.id);
// De-dupe: an extension that ships a watcher whose `type` equals its declared entry-type id
// (e.g. durable/agent/diagnostic) lands in BOTH `registered` and `extensionTypes`. The meta
// list is a set of watched types for the dashboard nav, so a repeat would render a duplicate
// tab (and read as double-recording in the boot log). Set preserves first-seen order.
const types = [
...new Set([
EntryType.Request,
EntryType.Exception,
...registered,
...clientErrorTypes,
...extensionTypes,
]),
];
this.service.setWatchers(types);
this.logger.log(`Telescope watching: ${types.join(', ')}`);
}
};
TelescopeWatcherRegistrar = TelescopeWatcherRegistrar_1 = __decorate([
Injectable(),
__param(0, Inject(TELESCOPE_OPTIONS)),
__param(1, Inject(TELESCOPE_CONFIG)),
__param(2, Inject(TelescopeService)),
__param(3, Inject(TELESCOPE_EXTENSIONS)),
__metadata("design:paramtypes", [Object, Object, TelescopeService,
ExtensionRegistry,
ModuleRef])
], TelescopeWatcherRegistrar);
export { TelescopeWatcherRegistrar };
//# sourceMappingURL=telescope-watcher-registrar.service.js.map