UNPKG

@dudousxd/nestjs-telescope

Version:

Laravel Telescope-style observability console for NestJS — core: watchers, recorder, correlation, SQLite store, headless API.

67 lines 3.37 kB
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); } }; // packages/core/src/metrics/traces.service.ts import { Inject, Injectable, Optional } from '@nestjs/common'; import { TELESCOPE_STORAGE } from '../nest/telescope.options.js'; import { collectEntriesInWindow } from './collect-window.js'; import { summarizeTraces } from './traces.js'; import { buildWaterfall } from './waterfall.js'; const DEFAULT_LIMIT = 50; const MAX_LIMIT = 500; /** Lists recent distinct OTel traces by grouping stored entries over a window. * Reads the store on demand, content-less — mirrors TimeseriesService. */ let TracesService = class TracesService { storage; pageSize; scanCap; constructor(storage, options) { this.storage = storage; this.pageSize = options?.pageSize; this.scanCap = options?.scanCap; } async getTraces(query) { if (!Number.isFinite(query.windowMs) || query.windowMs <= 0) { throw new RangeError(`windowMs must be a positive, finite number (got ${query.windowMs}).`); } const limit = Math.min(MAX_LIMIT, Math.max(1, Math.floor(query.limit ?? DEFAULT_LIMIT))); const windowStart = new Date(Date.now() - query.windowMs); const baseQuery = { after: windowStart, // summarizeTraces only reads traceId/type/createdAt/durationMs, not content. omitContent: true, }; const { entries, scanned, truncated } = await collectEntriesInWindow(this.storage, baseQuery, { ...(this.pageSize !== undefined ? { pageSize: this.pageSize } : {}), ...(this.scanCap !== undefined ? { scanCap: this.scanCap } : {}), }); return { traces: summarizeTraces(entries, { limit }), scanned, truncated }; } /** * Build a nested span waterfall for ONE trace. Fetches the trace's entries WITH * content (labels need it) and reconstructs parent/child nesting from time- * interval containment — see {@link buildWaterfall}. Returns `null` when the * trace has no entries (e.g. unknown / pruned trace id). */ async getWaterfall(traceId) { const page = await this.storage.get({ traceId, limit: MAX_LIMIT }); return buildWaterfall(page.data); } }; TracesService = __decorate([ Injectable(), __param(0, Inject(TELESCOPE_STORAGE)), __param(1, Optional()), __metadata("design:paramtypes", [Object, Object]) ], TracesService); export { TracesService }; //# sourceMappingURL=traces.service.js.map