@dudousxd/nestjs-durable-telescope 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA4C;AAC5C,gEAA8C;AAC9C,2DAAyC;AACzC,gEAA8C"}
1
+ {"version":3,"sources":["../src/durable-telescope.watcher.ts","../src/durable-telescope.extension.ts","../src/durable-dashboard.spec-data.ts","../src/durable-data-providers.ts"],"sourcesContent":["import { type EngineEvent, WorkflowEngine } from '@dudousxd/nestjs-durable-core';\nimport type { Watcher, WatcherContext } from '@dudousxd/nestjs-telescope';\nimport { type Span, SpanStatusCode, context, trace } from '@opentelemetry/api';\n\n/**\n * A Telescope watcher that turns durable-workflow lifecycle events into Telescope entries, so\n * runs and steps (including remote/Python steps) show up alongside the app's requests, queries\n * and jobs in the Telescope UI — under the **Workflows** tab.\n *\n * It also **trace-groups** a run: a root span is opened per run and every entry is recorded inside\n * that span's OTel context (step entries inside a child `step …` span). Telescope's trace-context\n * provider stamps each entry with the active span, so a whole workflow shows up as a single trace\n * on the Traces page — run → steps — with each entry carrying the run's `traceId`. When the host has\n * no OTel SDK the spans are no-ops and entries simply carry no trace (the prior behaviour).\n *\n * Add it to `TelescopeModule.forRoot({ watchers: [new DurableTelescopeWatcher()] })`. It resolves\n * the engine from the (global) durable providers and subscribes to its events.\n */\nexport class DurableTelescopeWatcher implements Watcher {\n readonly type = 'durable';\n /** Open root span per run, so step entries nest under it and share its traceId. */\n private readonly roots = new Map<string, Span>();\n\n register(ctx: WatcherContext): void {\n const engine = ctx.moduleRef.get(WorkflowEngine, { strict: false });\n const tracer = trace.getTracer('@dudousxd/nestjs-durable-telescope');\n\n engine.subscribe((event) => {\n const record = () =>\n ctx.record({\n type: this.type,\n content: {\n event: event.type,\n workflow: event.workflow,\n runId: event.runId,\n seq: event.seq,\n name: event.name,\n kind: event.kind,\n output: event.output,\n error: event.error,\n durationMs: event.durationMs,\n },\n tags: this.tags(event),\n });\n\n // Open the run's root span on first sight; later events nest under it.\n if (event.type === 'run.started') {\n this.roots.set(\n event.runId,\n tracer.startSpan(`workflow ${event.workflow ?? '?'}`, {\n attributes: { 'durable.run_id': event.runId, 'durable.workflow': event.workflow },\n }),\n );\n }\n const root = this.roots.get(event.runId);\n const base = root ? trace.setSpan(context.active(), root) : context.active();\n\n // A step/signal/sleep event → give it its own child span so it's a distinct node in the\n // trace; run-level events record directly on the root. Either way the active span at record\n // time carries the run's traceId, so all entries group into one trace.\n if (event.name != null && event.seq != null) {\n const step = tracer.startSpan(\n `step ${event.name}`,\n {\n attributes: {\n 'durable.run_id': event.runId,\n 'durable.step.seq': event.seq,\n 'durable.step.kind': event.kind,\n },\n },\n base,\n );\n context.with(trace.setSpan(base, step), record);\n step.end();\n } else {\n context.with(base, record);\n }\n\n // Close the run's root span when it leaves the running state.\n if (event.type === 'run.completed' || event.type === 'run.suspended') {\n root?.end();\n this.roots.delete(event.runId);\n } else if (event.type === 'run.failed') {\n const message = event.error?.message;\n root?.setStatus(\n message !== undefined\n ? { code: SpanStatusCode.ERROR, message }\n : { code: SpanStatusCode.ERROR },\n );\n root?.end();\n this.roots.delete(event.runId);\n }\n });\n }\n\n private tags(event: EngineEvent): string[] {\n const tags = ['durable', event.type, `run:${event.runId}`];\n if (event.workflow) tags.push(`workflow:${event.workflow}`);\n if (event.kind) tags.push(`kind:${event.kind}`);\n if (event.type === 'run.failed') tags.push('failed');\n return tags;\n }\n}\n","import { defineTelescopeExtension } from '@dudousxd/nestjs-telescope';\nimport { durableDashboard } from './durable-dashboard.spec-data';\nimport {\n durableDurationProvider,\n durableRecentFailuresProvider,\n durableRunsOverTimeProvider,\n durableStateBreakdownProvider,\n durableStateProvider,\n durableSuccessRateProvider,\n durableThroughputProvider,\n durableTimeseriesProvider,\n durableWorkerHealthProvider,\n} from './durable-data-providers';\nimport { DurableTelescopeWatcher } from './durable-telescope.watcher';\n\n/** The first-class Telescope extension for nestjs-durable: watcher + Workflows dashboard. */\nexport function durableTelescopeExtension(\n opts: { runHref?: string; recentFailuresWindowMs?: number } = {},\n) {\n return defineTelescopeExtension({\n name: 'durable',\n watchers: () => [new DurableTelescopeWatcher()],\n entryTypes: () => [{ id: 'durable', label: 'Workflows', dot: 'bg-amber-400' }],\n dashboards: () => [durableDashboard(opts)],\n dataProviders: () => [\n durableStateProvider(),\n durableTimeseriesProvider(),\n durableRecentFailuresProvider(),\n durableWorkerHealthProvider(),\n durableDurationProvider(),\n durableRunsOverTimeProvider(),\n durableSuccessRateProvider(),\n durableThroughputProvider(),\n durableStateBreakdownProvider(),\n ],\n });\n}\n","import type { DashboardSpec } from '@dudousxd/nestjs-telescope';\n\n/**\n * The \"Workflows\" health dashboard — golden-signals sections layout.\n *\n * `runHref` is a URL template for deep-linking a run out to the durable dashboard\n * (e.g. '/durable/runs/{runId}'). `recentFailuresWindowMs` bounds the \"Stuck runs\"\n * table (default 24h) so a healthy system shows an empty table instead of\n * days-old failures; pass `0` to show all.\n */\nexport function durableDashboard(\n opts: { runHref?: string; recentFailuresWindowMs?: number } = {},\n): DashboardSpec {\n const runHref = opts.runHref ?? '/durable/runs/{runId}';\n const windowMs = opts.recentFailuresWindowMs ?? 24 * 60 * 60 * 1000;\n return {\n id: 'durable.workflows',\n label: 'Workflows',\n panels: [],\n sections: [\n {\n title: 'Health',\n cols: 4,\n panels: [\n {\n kind: 'gauge',\n title: 'Success rate',\n data: { provider: 'durable.successRate' },\n max: 1,\n format: 'percent',\n thresholds: { warn: 0.98, bad: 0.95, direction: 'down-bad' },\n },\n {\n kind: 'stat',\n title: 'Duration p95',\n data: { provider: 'durable.duration', query: { metric: 'p95' } },\n format: 'duration',\n spark: false,\n thresholds: { warn: 2000, bad: 5000, direction: 'up-bad' },\n },\n {\n kind: 'stat',\n title: 'Backlog',\n data: { provider: 'durable.state', query: { status: 'pending' } },\n spark: false,\n thresholds: { warn: 50, bad: 200, direction: 'up-bad' },\n },\n {\n kind: 'stat',\n title: 'Throughput',\n data: { provider: 'durable.throughput' },\n format: 'rate',\n spark: true,\n },\n ],\n },\n {\n title: 'Needs attention',\n cols: 3,\n panels: [\n {\n kind: 'topN',\n title: 'Top failing workflows',\n data: { provider: 'durable.timeseries', query: { metric: 'topFailures' } },\n limit: 8,\n },\n {\n kind: 'table',\n title: 'Stuck runs',\n data: { provider: 'durable.recentFailures', query: { windowMs } },\n columns: [\n { key: 'updatedAt', label: 'Updated' },\n { key: 'workflow', label: 'Workflow' },\n { key: 'runId', label: 'Run', link: { href: runHref } },\n { key: 'error', label: 'Error' },\n ],\n },\n {\n kind: 'table',\n title: 'Starved worker groups',\n data: { provider: 'durable.workerHealth' },\n columns: [\n { key: 'group', label: 'Group' },\n { key: 'queued', label: 'Queued' },\n { key: 'liveWorkers', label: 'Workers' },\n { key: 'status', label: 'Status' },\n ],\n },\n ],\n },\n {\n title: 'Trends',\n cols: 3,\n panels: [\n {\n kind: 'timeseries',\n title: 'Runs over time',\n data: { provider: 'durable.runsOverTime' },\n series: ['done', 'failed'],\n style: 'stacked',\n },\n {\n kind: 'distribution',\n title: 'Duration distribution',\n data: { provider: 'durable.duration' },\n markers: ['p50', 'p95', 'p99'],\n format: 'duration',\n },\n {\n kind: 'breakdown',\n title: 'Runs by state',\n data: { provider: 'durable.stateBreakdown' },\n style: 'donut',\n },\n ],\n },\n ],\n };\n}\n","import { STATE_STORE_CANONICAL, WorkflowEngine } from '@dudousxd/nestjs-durable-core';\nimport type { RunStatus, StateStore } from '@dudousxd/nestjs-durable-core';\nimport type { DataProvider, ExtensionContext } from '@dudousxd/nestjs-telescope';\nimport { TELESCOPE_STORAGE } from '@dudousxd/nestjs-telescope';\n\n// ─── Shared helpers ───────────────────────────────────────────────────────────\n\n/** Compute the p-th percentile of a SORTED array. */\nfunction percentile(sorted: number[], p: number): number {\n if (sorted.length === 0) return 0;\n const idx = Math.min(sorted.length - 1, Math.ceil((p / 100) * sorted.length) - 1);\n return sorted[Math.max(0, idx)] ?? 0;\n}\n\ntype StorageEntry = { content?: unknown; createdAt?: Date };\n\n/** Fetch the durable entry page from TELESCOPE_STORAGE. */\nasync function fetchEntries(ctx: ExtensionContext): Promise<StorageEntry[]> {\n const storage = ctx.moduleRef.get(TELESCOPE_STORAGE, { strict: false }) as {\n get(q: { type?: string; limit?: number }): Promise<{ data: StorageEntry[] }>;\n };\n const page = await storage.get({ type: 'durable', limit: 5_000 });\n return page.data;\n}\n\n/**\n * Split entries into current/previous equal-length windows.\n * current: (now - windowMs, now]\n * previous: (now - 2*windowMs, now - windowMs]\n */\nfunction splitWindows(\n entries: StorageEntry[],\n windowMs: number,\n now: number,\n): { current: StorageEntry[]; previous: StorageEntry[] } {\n const start = now - windowMs;\n const prevStart = start - windowMs;\n return {\n current: entries.filter((e) => {\n const t = e.createdAt ? +new Date(e.createdAt) : 0;\n return t > start && t <= now;\n }),\n previous: entries.filter((e) => {\n const t = e.createdAt ? +new Date(e.createdAt) : 0;\n return t > prevStart && t <= start;\n }),\n };\n}\n\n/** Compute success rate (completed / total) for a list of entries, returns 1 when no data. */\nfunction successRateOf(entries: StorageEntry[]): number {\n let completed = 0;\n let failed = 0;\n for (const e of entries) {\n const c = (e.content ?? {}) as { event?: string };\n if (c.event === 'run.completed') completed += 1;\n else if (c.event === 'run.failed') failed += 1;\n }\n const total = completed + failed;\n return total === 0 ? 1 : completed / total;\n}\n\nconst STATE_CAP = 10_000;\n\n// ─── Existing providers ───────────────────────────────────────────────────────\n\n/** Source C: current-state gauge from the durable store. query.status selects which (default 'dead'). */\nexport function durableStateProvider(): DataProvider {\n return {\n name: 'durable.state',\n async resolve(query, ctx: ExtensionContext) {\n const store = ctx.moduleRef.get(STATE_STORE_CANONICAL, { strict: false }) as StateStore;\n const status = (query?.status as RunStatus) ?? 'dead';\n const runs = await store.listRuns({ status, limit: STATE_CAP });\n return { value: runs.length };\n },\n };\n}\n\n/**\n * Source A: rollups from captured `durable` entries in Telescope's own storage.\n * Reads recent run.* lifecycle entries and aggregates. Bounded by Telescope's prune\n * window (by design — this is the \"history\" series, not the source of truth).\n */\nexport function durableTimeseriesProvider(): DataProvider {\n return {\n name: 'durable.timeseries',\n async resolve(query, ctx: ExtensionContext) {\n // TELESCOPE_STORAGE.get(query) → { data: Entry[]; nextCursor }. Entry = { content, createdAt, ... }.\n const storage = ctx.moduleRef.get(TELESCOPE_STORAGE, { strict: false }) as {\n get(q: { type?: string; limit?: number }): Promise<{\n data: Array<{ content?: unknown; createdAt?: Date }>;\n }>;\n };\n const limit = Math.min(5_000, Math.max(100, Number(query?.limit ?? 2_000)));\n const page = await storage.get({ type: 'durable', limit });\n\n let completed = 0;\n let failed = 0;\n const failByWorkflow = new Map<string, number>();\n for (const e of page.data) {\n const c = (e.content ?? {}) as { event?: string; workflow?: string };\n if (c.event === 'run.completed') completed += 1;\n else if (c.event === 'run.failed') {\n failed += 1;\n const wf = c.workflow ?? 'unknown';\n failByWorkflow.set(wf, (failByWorkflow.get(wf) ?? 0) + 1);\n }\n }\n const total = completed + failed;\n const metric = (query?.metric as string) ?? 'successRate';\n if (metric === 'successRate') return { value: total === 0 ? 1 : completed / total };\n if (metric === 'failed') return { value: failed };\n if (metric === 'total') return { value: total };\n if (metric === 'topFailures') {\n const items = [...failByWorkflow.entries()]\n .map(([label, value]) => ({ label, value }))\n .sort((a, b) => b.value - a.value);\n return { items };\n }\n return { value: total };\n },\n };\n}\n\n/**\n * Source C: recent failed + dead runs as table rows (newest first), time-bounded.\n * Only failures updated within `query.windowMs` (default 24h) are returned, so a\n * healthy system shows an EMPTY table instead of surfacing days-old failures as if\n * they were a live incident. `windowMs: 0` disables the window (return all). Each\n * row carries a compact `updatedAt` stamp so recency is visible in the table.\n */\nexport function durableRecentFailuresProvider(): DataProvider {\n return {\n name: 'durable.recentFailures',\n async resolve(query, ctx: ExtensionContext) {\n const store = ctx.moduleRef.get(STATE_STORE_CANONICAL, { strict: false }) as StateStore;\n const limit = Math.min(200, Math.max(10, Number(query?.limit ?? 50)));\n const windowMs = query?.windowMs === undefined ? 24 * 60 * 60 * 1000 : Number(query.windowMs);\n const cutoff = windowMs > 0 ? Date.now() - windowMs : 0;\n const [failed, dead] = await Promise.all([\n store.listRuns({ status: 'failed', limit }),\n store.listRuns({ status: 'dead', limit }),\n ]);\n const rows = [...failed, ...dead]\n .filter((r) => +new Date(r.updatedAt) >= cutoff)\n .sort((a, b) => +new Date(b.updatedAt) - +new Date(a.updatedAt))\n .slice(0, limit)\n .map((r) => ({\n // Compact UTC stamp (\"YYYY-MM-DD HH:mm Z\"); the generic table renderer\n // prints column values as-is, so we format here.\n updatedAt: `${new Date(r.updatedAt).toISOString().replace('T', ' ').slice(0, 16)}Z`,\n workflow: r.workflow,\n runId: r.id,\n error: r.error?.message ?? '',\n }));\n return { rows };\n },\n };\n}\n\n/**\n * Source D: per-group worker health from the engine (`WorkflowEngine.workerHealth()` — queue depth\n * vs. live worker heartbeats). `query.metric: 'starvedCount'` returns the number of groups with work\n * queued and zero live workers (the \"alive but not consuming\" alert state) as a stat; otherwise a\n * table, starved groups sorted first. Empty when the transport can't report health (in-process).\n */\nexport function durableWorkerHealthProvider(): DataProvider {\n return {\n name: 'durable.workerHealth',\n async resolve(query, ctx: ExtensionContext) {\n const engine = ctx.moduleRef.get(WorkflowEngine, { strict: false }) as WorkflowEngine;\n const health = await engine.workerHealth();\n const isStarved = (g: { depth: number; liveWorkers: unknown[] }) =>\n g.depth > 0 && g.liveWorkers.length === 0;\n if ((query?.metric as string) === 'starvedCount') {\n return { value: health.filter(isStarved).length };\n }\n const rows = health\n .slice()\n // Starved groups first, then deepest backlog — the rows that need attention rise to the top.\n .sort((a, b) => Number(isStarved(b)) - Number(isStarved(a)) || b.depth - a.depth)\n .map((g) => ({\n group: g.group,\n queued: g.depth,\n liveWorkers: g.liveWorkers.length,\n status: isStarved(g) ? 'STARVED' : 'ok',\n }));\n return { rows };\n },\n };\n}\n\n// ─── New golden-signals providers ────────────────────────────────────────────\n\n/**\n * Duration percentiles (p50/p95/p99) + a histogram of ~8 buckets.\n * Durations are read from `content.durationMs` on `run.completed`/`run.failed`; when absent,\n * computed by pairing a `run.started` and its corresponding `run.completed`/`run.failed` entry\n * by `runId` using their `createdAt` timestamps.\n *\n * With `query.metric === 'p50'|'p95'|'p99'` returns `{ value }` for use as a stat panel.\n */\nexport function durableDurationProvider(): DataProvider {\n return {\n name: 'durable.duration',\n async resolve(query, ctx: ExtensionContext) {\n const entries = await fetchEntries(ctx);\n\n // Index run.started entries by runId for the pairing fallback.\n const startedAt = new Map<string, number>();\n for (const e of entries) {\n const c = (e.content ?? {}) as { event?: string; runId?: string };\n if (c.event === 'run.started' && c.runId && e.createdAt) {\n startedAt.set(c.runId, +new Date(e.createdAt));\n }\n }\n\n const durs: number[] = [];\n for (const e of entries) {\n const c = (e.content ?? {}) as { event?: string; runId?: string; durationMs?: number };\n if (c.event === 'run.completed' || c.event === 'run.failed') {\n if (typeof c.durationMs === 'number') {\n durs.push(c.durationMs);\n } else if (c.runId) {\n const start = startedAt.get(c.runId);\n const end = e.createdAt ? +new Date(e.createdAt) : undefined;\n if (start !== undefined && end !== undefined && end >= start) {\n durs.push(end - start);\n }\n }\n }\n }\n durs.sort((a, b) => a - b);\n\n const p50 = percentile(durs, 50);\n const p95 = percentile(durs, 95);\n const p99 = percentile(durs, 99);\n\n // Stat shortcut: return a single value for use in stat panels.\n const metric = (query as Record<string, unknown>)?.metric as string | undefined;\n if (metric === 'p50') return { value: p50 };\n if (metric === 'p95') return { value: p95 };\n if (metric === 'p99') return { value: p99 };\n\n // Build ~8 equal-width buckets between 0 and max.\n const max = durs.at(-1) ?? 0;\n const bucketCount = 8;\n const size = Math.max(1, Math.ceil((max + 1) / bucketCount));\n const buckets = Array.from({ length: bucketCount }, (_, i) => ({\n label: `${Math.round((i * size) / 100) / 10}s`,\n count: 0,\n }));\n for (const d of durs) {\n const bi = Math.min(bucketCount - 1, Math.floor(d / size));\n const bucket = buckets[bi];\n if (bucket) bucket.count += 1;\n }\n\n return { buckets, p50, p95, p99 };\n },\n };\n}\n\n/**\n * Buckets `run.completed` (-> done) and `run.failed` (-> failed) entries by `createdAt` into\n * N=`query.buckets ?? 24` equal-width time buckets. Returns `{ rows: Array<{ label; done; failed }> }`.\n */\nexport function durableRunsOverTimeProvider(): DataProvider {\n return {\n name: 'durable.runsOverTime',\n async resolve(query, ctx: ExtensionContext) {\n const entries = await fetchEntries(ctx);\n const n = Number((query as Record<string, unknown>)?.buckets ?? 24);\n const now = Date.now();\n\n // Determine the time window from the oldest entry or default to 24h.\n let minT = now;\n for (const e of entries) {\n if (e.createdAt) {\n const t = +new Date(e.createdAt);\n if (t < minT) minT = t;\n }\n }\n const span = Math.max(now - minT, 1);\n const bucketSize = span / n;\n\n const rows: Array<{ label: string; done: number; failed: number }> = Array.from(\n { length: n },\n (_, i) => {\n const bucketStart = new Date(minT + i * bucketSize);\n const label = bucketStart.toISOString().slice(11, 16); // \"HH:mm\"\n return { label, done: 0, failed: 0 };\n },\n );\n\n for (const e of entries) {\n const c = (e.content ?? {}) as { event?: string };\n if (c.event !== 'run.completed' && c.event !== 'run.failed') continue;\n const t = e.createdAt ? +new Date(e.createdAt) : 0;\n const idx = Math.min(n - 1, Math.floor((t - minT) / bucketSize));\n const row = rows[idx];\n if (row) {\n if (c.event === 'run.completed') row.done += 1;\n else row.failed += 1;\n }\n }\n\n return { rows };\n },\n };\n}\n\n/**\n * Success rate over the last `query.windowMs` (default 24h), with a `delta` vs. the previous\n * equal-length window and a `spark` array of per-sub-bucket success rates.\n */\nexport function durableSuccessRateProvider(): DataProvider {\n return {\n name: 'durable.successRate',\n async resolve(query, ctx: ExtensionContext) {\n const entries = await fetchEntries(ctx);\n const windowMs = Number((query as Record<string, unknown>)?.windowMs ?? 24 * 60 * 60 * 1000);\n const now = Date.now();\n const { current, previous } = splitWindows(entries, windowMs, now);\n\n const value = successRateOf(current);\n const prevRate = successRateOf(previous);\n const delta = previous.length > 0 ? value - prevRate : undefined;\n\n // Spark: split the current window into 8 sub-buckets.\n const sparkBuckets = 8;\n const bucketSize = windowMs / sparkBuckets;\n const sparkStart = now - windowMs;\n const spark = Array.from({ length: sparkBuckets }, (_, i) => {\n const bStart = sparkStart + i * bucketSize;\n const bEnd = bStart + bucketSize;\n const bEntries = current.filter((e) => {\n const t = e.createdAt ? +new Date(e.createdAt) : 0;\n return t > bStart && t <= bEnd;\n });\n return successRateOf(bEntries);\n });\n\n return { value, delta, spark };\n },\n };\n}\n\n/**\n * Completed runs per hour over the last `query.windowMs` (default 24h), with a `delta` vs. the\n * previous equal-length window and a `spark` array of per-sub-bucket throughput values.\n */\nexport function durableThroughputProvider(): DataProvider {\n return {\n name: 'durable.throughput',\n async resolve(query, ctx: ExtensionContext) {\n const entries = await fetchEntries(ctx);\n const windowMs = Number((query as Record<string, unknown>)?.windowMs ?? 24 * 60 * 60 * 1000);\n const now = Date.now();\n const { current, previous } = splitWindows(entries, windowMs, now);\n\n const countCompleted = (es: StorageEntry[]) =>\n es.filter((e) => ((e.content ?? {}) as { event?: string }).event === 'run.completed')\n .length;\n\n const windowHours = windowMs / (60 * 60 * 1000);\n const value = countCompleted(current) / windowHours;\n const prevValue = countCompleted(previous) / windowHours;\n const delta = previous.length > 0 ? value - prevValue : undefined;\n\n // Spark: 8 sub-buckets of current window.\n const sparkBuckets = 8;\n const bucketSize = windowMs / sparkBuckets;\n const bucketHours = bucketSize / (60 * 60 * 1000);\n const sparkStart = now - windowMs;\n const spark = Array.from({ length: sparkBuckets }, (_, i) => {\n const bStart = sparkStart + i * bucketSize;\n const bEnd = bStart + bucketSize;\n const bEntries = current.filter((e) => {\n const t = e.createdAt ? +new Date(e.createdAt) : 0;\n return t > bStart && t <= bEnd;\n });\n return countCompleted(bEntries) / bucketHours;\n });\n\n return { value, delta, spark };\n },\n };\n}\n\n/** Color palette for the state breakdown pie segments. */\nconst STATE_BREAKDOWN_PALETTE = ['#34d399', '#fbbf24', '#f87171', '#38bdf8', '#a78bfa'];\nconst STATE_BREAKDOWN_STATUSES: RunStatus[] = ['running', 'pending', 'completed', 'failed', 'dead'];\n\n/**\n * Counts from `STATE_STORE.listRuns({ status })` for each of the 5 statuses and returns pie\n * segments with the standard palette: `{ segments: Array<{ label, value, color }> }`.\n */\nexport function durableStateBreakdownProvider(): DataProvider {\n return {\n name: 'durable.stateBreakdown',\n async resolve(_query, ctx: ExtensionContext) {\n const store = ctx.moduleRef.get(STATE_STORE_CANONICAL, { strict: false }) as StateStore;\n const counts = await Promise.all(\n STATE_BREAKDOWN_STATUSES.map((status) =>\n store.listRuns({ status, limit: STATE_CAP }).then((runs) => runs.length),\n ),\n );\n const segments = STATE_BREAKDOWN_STATUSES.map((label, i) => ({\n label,\n value: counts[i],\n color: STATE_BREAKDOWN_PALETTE[i],\n }));\n return { segments };\n },\n };\n}\n\n// NOTE: durableRetryHotspotsProvider is NOT implemented.\n// StateStore only exposes `listCheckpoints(runId: string)` (per-run lookup), with no cross-run\n// query by step `attempts`. There is no API to enumerate all step checkpoints across runs without\n// first listing every run — which would be O(N*M) and impractical. Task 13 should omit that panel.\n"],"mappings":";;;;AAAA,SAA2BA,sBAAsB;AAEjD,SAAoBC,gBAAgBC,SAASC,aAAa;AAgBnD,IAAMC,0BAAN,MAAMA;EAlBb,OAkBaA;;;EACFC,OAAO;;EAECC,QAAQ,oBAAIC,IAAAA;EAE7BC,SAASC,KAA2B;AAClC,UAAMC,SAASD,IAAIE,UAAUC,IAAIC,gBAAgB;MAAEC,QAAQ;IAAM,CAAA;AACjE,UAAMC,SAASC,MAAMC,UAAU,oCAAA;AAE/BP,WAAOQ,UAAU,CAACC,UAAAA;AAChB,YAAMC,SAAS,6BACbX,IAAIW,OAAO;QACTf,MAAM,KAAKA;QACXgB,SAAS;UACPF,OAAOA,MAAMd;UACbiB,UAAUH,MAAMG;UAChBC,OAAOJ,MAAMI;UACb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ableTelescopeWatcher","type","roots","Map","register","ctx","engine","moduleRef","get","WorkflowEngine","strict","tracer","trace","getTracer","subscribe","event","record","content","workflow","runId","seq","name","kind","output","error","durationMs","tags","set","startSpan","attributes","root","base","setSpan","context","active","step","with","end","delete","message","setStatus","undefined","code","SpanStatusCode","ERROR","push","defineTelescopeExtension","durableDashboard","opts","runHref","windowMs","recentFailuresWindowMs","id","label","panels","sections","title","cols","kind","data","provider","max","format","thresholds","warn","bad","direction","query","metric","spark","status","limit","columns","key","link","href","series","style","markers","STATE_STORE_CANONICAL","WorkflowEngine","TELESCOPE_STORAGE","percentile","sorted","p","length","idx","Math","min","ceil","max","fetchEntries","ctx","storage","moduleRef","get","TELESCOPE_STORAGE","strict","page","type","limit","data","splitWindows","entries","windowMs","now","start","prevStart","current","filter","e","t","createdAt","Date","previous","successRateOf","completed","failed","c","content","event","total","STATE_CAP","durableStateProvider","name","resolve","query","store","STATE_STORE_CANONICAL","status","runs","listRuns","value","durableTimeseriesProvider","Number","failByWorkflow","Map","wf","workflow","set","metric","items","map","label","sort","a","b","durableRecentFailuresProvider","undefined","cutoff","dead","Promise","all","rows","r","updatedAt","slice","toISOString","replace","runId","id","error","message","durableWorkerHealthProvider","engine","WorkflowEngine","health","workerHealth","isStarved","g","depth","liveWorkers","group","queued","durableDurationProvider","startedAt","durs","durationMs","push","end","p50","p95","p99","at","bucketCount","size","buckets","Array","from","_","i","round","count","d","bi","floor","bucket","durableRunsOverTimeProvider","n","minT","span","bucketSize","bucketStart","done","row","durableSuccessRateProvider","prevRate","delta","sparkBuckets","sparkStart","spark","bStart","bEnd","bEntries","durableThroughputProvider","countCompleted","es","windowHours","prevValue","bucketHours","STATE_BREAKDOWN_PALETTE","STATE_BREAKDOWN_STATUSES","durableStateBreakdownProvider","_query","counts","then","segments","color","durableTelescopeExtension","opts","defineTelescopeExtension","name","watchers","DurableTelescopeWatcher","entryTypes","id","label","dot","dashboards","durableDashboard","dataProviders","durableStateProvider","durableTimeseriesProvider","durableRecentFailuresProvider","durableWorkerHealthProvider","durableDurationProvider","durableRunsOverTimeProvider","durableSuccessRateProvider","durableThroughputProvider","durableStateBreakdownProvider"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudousxd/nestjs-durable-telescope",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "Telescope watcher for nestjs-durable — workflow runs and steps as Telescope entries",
5
5
  "license": "MIT",
6
6
  "author": "Davide Carvalho",
@@ -9,9 +9,9 @@
9
9
  "url": "https://github.com/DavideCarvalho/nestjs-durable.git",
10
10
  "directory": "packages/telescope"
11
11
  },
12
- "type": "commonjs",
13
- "main": "dist/index.js",
14
- "types": "dist/index.d.ts",
12
+ "type": "module",
13
+ "main": "./dist/index.cjs",
14
+ "types": "./dist/index.d.ts",
15
15
  "files": [
16
16
  "dist"
17
17
  ],
@@ -22,14 +22,28 @@
22
22
  "@opentelemetry/api": "^1.0.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@dudousxd/nestjs-telescope": "1.8.0",
25
+ "@dudousxd/nestjs-telescope": "1.10.0",
26
26
  "@nestjs/core": "11.1.26",
27
27
  "@opentelemetry/api": "1.9.0",
28
28
  "typescript": "5.9.3",
29
- "@dudousxd/nestjs-durable-core": "^0.23.0"
29
+ "tsup": "8.3.5",
30
+ "@dudousxd/nestjs-durable-core": "^0.32.1"
31
+ },
32
+ "module": "./dist/index.js",
33
+ "exports": {
34
+ ".": {
35
+ "import": {
36
+ "types": "./dist/index.d.ts",
37
+ "default": "./dist/index.js"
38
+ },
39
+ "require": {
40
+ "types": "./dist/index.d.cts",
41
+ "default": "./dist/index.cjs"
42
+ }
43
+ }
30
44
  },
31
45
  "scripts": {
32
- "build": "tsc -p tsconfig.json",
46
+ "build": "tsup",
33
47
  "typecheck": "tsc -p tsconfig.json --noEmit"
34
48
  }
35
49
  }
@@ -1,12 +0,0 @@
1
- import type { DashboardSpec } from '@dudousxd/nestjs-telescope';
2
- /**
3
- * The "Workflows" health dashboard. `runHref` is a URL template for deep-linking a run
4
- * out to the durable dashboard (e.g. '/durable/runs/{runId}'). `recentFailuresWindowMs`
5
- * bounds the "Recent failed runs" table (default 24h) so a healthy system shows an empty
6
- * table instead of days-old failures; pass `0` to show all.
7
- */
8
- export declare function durableDashboard(opts?: {
9
- runHref?: string;
10
- recentFailuresWindowMs?: number;
11
- }): DashboardSpec;
12
- //# sourceMappingURL=durable-dashboard.spec-data.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"durable-dashboard.spec-data.d.ts","sourceRoot":"","sources":["../src/durable-dashboard.spec-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAEhE;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,sBAAsB,CAAC,EAAE,MAAM,CAAA;CAAO,GAC/D,aAAa,CA6Ef"}
@@ -1,88 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.durableDashboard = durableDashboard;
4
- /**
5
- * The "Workflows" health dashboard. `runHref` is a URL template for deep-linking a run
6
- * out to the durable dashboard (e.g. '/durable/runs/{runId}'). `recentFailuresWindowMs`
7
- * bounds the "Recent failed runs" table (default 24h) so a healthy system shows an empty
8
- * table instead of days-old failures; pass `0` to show all.
9
- */
10
- function durableDashboard(opts = {}) {
11
- const runHref = opts.runHref ?? '/durable/runs/{runId}';
12
- const windowMs = opts.recentFailuresWindowMs ?? 24 * 60 * 60 * 1000;
13
- return {
14
- id: 'durable.workflows',
15
- label: 'Workflows',
16
- panels: [
17
- {
18
- kind: 'stat',
19
- title: 'Success rate',
20
- data: { provider: 'durable.timeseries', query: { metric: 'successRate' } },
21
- format: 'percent',
22
- accent: 'text-emerald-400',
23
- },
24
- {
25
- kind: 'stat',
26
- title: 'Failed (window)',
27
- data: { provider: 'durable.timeseries', query: { metric: 'failed' } },
28
- accent: 'text-red-400',
29
- },
30
- {
31
- kind: 'stat',
32
- title: 'Dead now',
33
- data: { provider: 'durable.state', query: { status: 'dead' } },
34
- accent: 'text-red-400',
35
- },
36
- {
37
- kind: 'stat',
38
- title: 'Suspended now',
39
- data: { provider: 'durable.state', query: { status: 'suspended' } },
40
- },
41
- {
42
- kind: 'stat',
43
- title: 'Running now',
44
- data: { provider: 'durable.state', query: { status: 'running' } },
45
- },
46
- {
47
- kind: 'stat',
48
- title: 'Pending now',
49
- data: { provider: 'durable.state', query: { status: 'pending' } },
50
- },
51
- {
52
- kind: 'stat',
53
- title: 'Starved groups',
54
- data: { provider: 'durable.workerHealth', query: { metric: 'starvedCount' } },
55
- accent: 'text-red-400',
56
- },
57
- {
58
- kind: 'topN',
59
- title: 'Top failing workflows',
60
- data: { provider: 'durable.timeseries', query: { metric: 'topFailures' } },
61
- limit: 10,
62
- },
63
- {
64
- kind: 'table',
65
- title: 'Worker groups (backlog vs. live workers)',
66
- data: { provider: 'durable.workerHealth', query: {} },
67
- columns: [
68
- { key: 'group', label: 'Group' },
69
- { key: 'queued', label: 'Queued' },
70
- { key: 'liveWorkers', label: 'Live workers' },
71
- { key: 'status', label: 'Status' },
72
- ],
73
- },
74
- {
75
- kind: 'table',
76
- title: 'Recent failed runs (last 24h)',
77
- data: { provider: 'durable.recentFailures', query: { windowMs } },
78
- columns: [
79
- { key: 'updatedAt', label: 'Updated' },
80
- { key: 'workflow', label: 'Workflow' },
81
- { key: 'runId', label: 'Run', link: { href: runHref } },
82
- { key: 'error', label: 'Error' },
83
- ],
84
- },
85
- ],
86
- };
87
- }
88
- //# sourceMappingURL=durable-dashboard.spec-data.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"durable-dashboard.spec-data.js","sourceRoot":"","sources":["../src/durable-dashboard.spec-data.ts"],"names":[],"mappings":";;AAQA,4CA+EC;AArFD;;;;;GAKG;AACH,SAAgB,gBAAgB,CAC9B,OAA8D,EAAE;IA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AAE,IAAI,EAAE,OAAO,EAAE,EAAE;oBACvD,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE;iBACjC;aACF;SACF;KACF,CAAC;AACJ,CAAC"}
@@ -1,25 +0,0 @@
1
- import type { DataProvider } from '@dudousxd/nestjs-telescope';
2
- /** Source C: current-state gauge from the durable store. query.status selects which (default 'dead'). */
3
- export declare function durableStateProvider(): DataProvider;
4
- /**
5
- * Source A: rollups from captured `durable` entries in Telescope's own storage.
6
- * Reads recent run.* lifecycle entries and aggregates. Bounded by Telescope's prune
7
- * window (by design — this is the "history" series, not the source of truth).
8
- */
9
- export declare function durableTimeseriesProvider(): DataProvider;
10
- /**
11
- * Source C: recent failed + dead runs as table rows (newest first), time-bounded.
12
- * Only failures updated within `query.windowMs` (default 24h) are returned, so a
13
- * healthy system shows an EMPTY table instead of surfacing days-old failures as if
14
- * they were a live incident. `windowMs: 0` disables the window (return all). Each
15
- * row carries a compact `updatedAt` stamp so recency is visible in the table.
16
- */
17
- export declare function durableRecentFailuresProvider(): DataProvider;
18
- /**
19
- * Source D: per-group worker health from the engine (`WorkflowEngine.workerHealth()` — queue depth
20
- * vs. live worker heartbeats). `query.metric: 'starvedCount'` returns the number of groups with work
21
- * queued and zero live workers (the "alive but not consuming" alert state) as a stat; otherwise a
22
- * table, starved groups sorted first. Empty when the transport can't report health (in-process).
23
- */
24
- export declare function durableWorkerHealthProvider(): DataProvider;
25
- //# sourceMappingURL=durable-data-providers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"durable-data-providers.d.ts","sourceRoot":"","sources":["../src/durable-data-providers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,4BAA4B,CAAC;AAKjF,yGAAyG;AACzG,wBAAgB,oBAAoB,IAAI,YAAY,CAUnD;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,IAAI,YAAY,CAuCxD;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,IAAI,YAAY,CA2B5D;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,IAAI,YAAY,CAwB1D"}
@@ -1,131 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.durableStateProvider = durableStateProvider;
4
- exports.durableTimeseriesProvider = durableTimeseriesProvider;
5
- exports.durableRecentFailuresProvider = durableRecentFailuresProvider;
6
- exports.durableWorkerHealthProvider = durableWorkerHealthProvider;
7
- const nestjs_durable_core_1 = require("@dudousxd/nestjs-durable-core");
8
- const nestjs_telescope_1 = require("@dudousxd/nestjs-telescope");
9
- const STATE_CAP = 10_000;
10
- /** Source C: current-state gauge from the durable store. query.status selects which (default 'dead'). */
11
- function durableStateProvider() {
12
- return {
13
- name: 'durable.state',
14
- async resolve(query, ctx) {
15
- const store = ctx.moduleRef.get(nestjs_durable_core_1.STATE_STORE, { strict: false });
16
- const status = query?.status ?? 'dead';
17
- const runs = await store.listRuns({ status, limit: STATE_CAP });
18
- return { value: runs.length };
19
- },
20
- };
21
- }
22
- /**
23
- * Source A: rollups from captured `durable` entries in Telescope's own storage.
24
- * Reads recent run.* lifecycle entries and aggregates. Bounded by Telescope's prune
25
- * window (by design — this is the "history" series, not the source of truth).
26
- */
27
- function durableTimeseriesProvider() {
28
- return {
29
- name: 'durable.timeseries',
30
- async resolve(query, ctx) {
31
- // TELESCOPE_STORAGE.get(query) → { data: Entry[]; nextCursor }. Entry = { content, createdAt, ... }.
32
- const storage = ctx.moduleRef.get(nestjs_telescope_1.TELESCOPE_STORAGE, { strict: false });
33
- const limit = Math.min(5_000, Math.max(100, Number(query?.limit ?? 2_000)));
34
- const page = await storage.get({ type: 'durable', limit });
35
- let completed = 0;
36
- let failed = 0;
37
- const failByWorkflow = new Map();
38
- for (const e of page.data) {
39
- const c = (e.content ?? {});
40
- if (c.event === 'run.completed')
41
- completed += 1;
42
- else if (c.event === 'run.failed') {
43
- failed += 1;
44
- const wf = c.workflow ?? 'unknown';
45
- failByWorkflow.set(wf, (failByWorkflow.get(wf) ?? 0) + 1);
46
- }
47
- }
48
- const total = completed + failed;
49
- const metric = query?.metric ?? 'successRate';
50
- if (metric === 'successRate')
51
- return { value: total === 0 ? 1 : completed / total };
52
- if (metric === 'failed')
53
- return { value: failed };
54
- if (metric === 'total')
55
- return { value: total };
56
- if (metric === 'topFailures') {
57
- const items = [...failByWorkflow.entries()]
58
- .map(([label, value]) => ({ label, value }))
59
- .sort((a, b) => b.value - a.value);
60
- return { items };
61
- }
62
- return { value: total };
63
- },
64
- };
65
- }
66
- /**
67
- * Source C: recent failed + dead runs as table rows (newest first), time-bounded.
68
- * Only failures updated within `query.windowMs` (default 24h) are returned, so a
69
- * healthy system shows an EMPTY table instead of surfacing days-old failures as if
70
- * they were a live incident. `windowMs: 0` disables the window (return all). Each
71
- * row carries a compact `updatedAt` stamp so recency is visible in the table.
72
- */
73
- function durableRecentFailuresProvider() {
74
- return {
75
- name: 'durable.recentFailures',
76
- async resolve(query, ctx) {
77
- const store = ctx.moduleRef.get(nestjs_durable_core_1.STATE_STORE, { strict: false });
78
- const limit = Math.min(200, Math.max(10, Number(query?.limit ?? 50)));
79
- const windowMs = query?.windowMs === undefined ? 24 * 60 * 60 * 1000 : Number(query.windowMs);
80
- const cutoff = windowMs > 0 ? Date.now() - windowMs : 0;
81
- const [failed, dead] = await Promise.all([
82
- store.listRuns({ status: 'failed', limit }),
83
- store.listRuns({ status: 'dead', limit }),
84
- ]);
85
- const rows = [...failed, ...dead]
86
- .filter((r) => +new Date(r.updatedAt) >= cutoff)
87
- .sort((a, b) => +new Date(b.updatedAt) - +new Date(a.updatedAt))
88
- .slice(0, limit)
89
- .map((r) => ({
90
- // Compact UTC stamp ("YYYY-MM-DD HH:mm Z"); the generic table renderer
91
- // prints column values as-is, so we format here.
92
- updatedAt: `${new Date(r.updatedAt).toISOString().replace('T', ' ').slice(0, 16)}Z`,
93
- workflow: r.workflow,
94
- runId: r.id,
95
- error: r.error?.message ?? '',
96
- }));
97
- return { rows };
98
- },
99
- };
100
- }
101
- /**
102
- * Source D: per-group worker health from the engine (`WorkflowEngine.workerHealth()` — queue depth
103
- * vs. live worker heartbeats). `query.metric: 'starvedCount'` returns the number of groups with work
104
- * queued and zero live workers (the "alive but not consuming" alert state) as a stat; otherwise a
105
- * table, starved groups sorted first. Empty when the transport can't report health (in-process).
106
- */
107
- function durableWorkerHealthProvider() {
108
- return {
109
- name: 'durable.workerHealth',
110
- async resolve(query, ctx) {
111
- const engine = ctx.moduleRef.get(nestjs_durable_core_1.WorkflowEngine, { strict: false });
112
- const health = await engine.workerHealth();
113
- const isStarved = (g) => g.depth > 0 && g.liveWorkers.length === 0;
114
- if (query?.metric === 'starvedCount') {
115
- return { value: health.filter(isStarved).length };
116
- }
117
- const rows = health
118
- .slice()
119
- // Starved groups first, then deepest backlog — the rows that need attention rise to the top.
120
- .sort((a, b) => Number(isStarved(b)) - Number(isStarved(a)) || b.depth - a.depth)
121
- .map((g) => ({
122
- group: g.group,
123
- queued: g.depth,
124
- liveWorkers: g.liveWorkers.length,
125
- status: isStarved(g) ? 'STARVED' : 'ok',
126
- }));
127
- return { rows };
128
- },
129
- };
130
- }
131
- //# sourceMappingURL=durable-data-providers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"durable-data-providers.js","sourceRoot":"","sources":["../src/durable-data-providers.ts"],"names":[],"mappings":";;AAQA,oDAUC;AAOD,8DAuCC;AASD,sEA2BC;AAQD,kEAwBC;AApID,uEAA4E;AAG5E,iEAA+D;AAE/D,MAAM,SAAS,GAAG,MAAM,CAAC;AAEzB,yGAAyG;AACzG,SAAgB,oBAAoB;IAClC,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,GAAqB;YACxC,MAAM,KAAK,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,iCAAW,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAe,CAAC;YAC9E,MAAM,MAAM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AAC,CAAC,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;iBAChF,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBACX,KAAK,EAAE,CAAC,CAAC,KAAK;gBACd,MAAM,EAAE,CAAC,CAAC,KAAK;gBACf,WAAW,EAAE,CAAC,CAAC,WAAW,CAAC,MAAM;gBACjC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI;aACxC,CAAC,CAAC,CAAC;YACN,OAAO,EAAE,IAAI,EAAE,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,6 +0,0 @@
1
- /** The first-class Telescope extension for nestjs-durable: watcher + Workflows dashboard. */
2
- export declare function durableTelescopeExtension(opts?: {
3
- runHref?: string;
4
- recentFailuresWindowMs?: number;
5
- }): import("@dudousxd/nestjs-telescope").TelescopeExtension;
6
- //# sourceMappingURL=durable-telescope.extension.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"durable-telescope.extension.d.ts","sourceRoot":"","sources":["../src/durable-telescope.extension.ts"],"names":[],"mappings":"AAUA,6FAA6F;AAC7F,wBAAgB,yBAAyB,CACvC,IAAI,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,sBAAsB,CAAC,EAAE,MAAM,CAAA;CAAO,2DAcjE"}
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.durableTelescopeExtension = durableTelescopeExtension;
4
- const nestjs_telescope_1 = require("@dudousxd/nestjs-telescope");
5
- const durable_dashboard_spec_data_1 = require("./durable-dashboard.spec-data");
6
- const durable_data_providers_1 = require("./durable-data-providers");
7
- const durable_telescope_watcher_1 = require("./durable-telescope.watcher");
8
- /** The first-class Telescope extension for nestjs-durable: watcher + Workflows dashboard. */
9
- function durableTelescopeExtension(opts = {}) {
10
- return (0, nestjs_telescope_1.defineTelescopeExtension)({
11
- name: 'durable',
12
- watchers: () => [new durable_telescope_watcher_1.DurableTelescopeWatcher()],
13
- entryTypes: () => [{ id: 'durable', label: 'Workflows', dot: 'bg-amber-400' }],
14
- dashboards: () => [(0, durable_dashboard_spec_data_1.durableDashboard)(opts)],
15
- dataProviders: () => [
16
- (0, durable_data_providers_1.durableStateProvider)(),
17
- (0, durable_data_providers_1.durableTimeseriesProvider)(),
18
- (0, durable_data_providers_1.durableRecentFailuresProvider)(),
19
- (0, durable_data_providers_1.durableWorkerHealthProvider)(),
20
- ],
21
- });
22
- }
23
- //# sourceMappingURL=durable-telescope.extension.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"durable-telescope.extension.js","sourceRoot":"","sources":["../src/durable-telescope.extension.ts"],"names":[],"mappings":";;AAWA,8DAeC;AA1BD,iEAAsE;AACtE,+EAAiE;AACjE,qEAKkC;AAClC,2EAAsE;AAEtE,6FAA6F;AAC7F,SAAgB,yBAAyB,CACvC,OAA8D,EAAE;IAEhE,OAAO,IAAA,2CAAwB,EAAC;QAC9B,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI,mDAAuB,EAAE,CAAC;QAC/C,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,cAAc,EAAE,CAAC;QAC9E,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,IAAA,8CAAgB,EAAC,IAAI,CAAC,CAAC;QAC1C,aAAa,EAAE,GAAG,EAAE,CAAC;YACnB,IAAA,6CAAoB,GAAE;YACtB,IAAA,kDAAyB,GAAE;YAC3B,IAAA,sDAA6B,GAAE;YAC/B,IAAA,oDAA2B,GAAE;SAC9B;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -1,23 +0,0 @@
1
- import type { Watcher, WatcherContext } from '@dudousxd/nestjs-telescope';
2
- /**
3
- * A Telescope watcher that turns durable-workflow lifecycle events into Telescope entries, so
4
- * runs and steps (including remote/Python steps) show up alongside the app's requests, queries
5
- * and jobs in the Telescope UI — under the **Workflows** tab.
6
- *
7
- * It also **trace-groups** a run: a root span is opened per run and every entry is recorded inside
8
- * that span's OTel context (step entries inside a child `step …` span). Telescope's trace-context
9
- * provider stamps each entry with the active span, so a whole workflow shows up as a single trace
10
- * on the Traces page — run → steps — with each entry carrying the run's `traceId`. When the host has
11
- * no OTel SDK the spans are no-ops and entries simply carry no trace (the prior behaviour).
12
- *
13
- * Add it to `TelescopeModule.forRoot({ watchers: [new DurableTelescopeWatcher()] })`. It resolves
14
- * the engine from the (global) durable providers and subscribes to its events.
15
- */
16
- export declare class DurableTelescopeWatcher implements Watcher {
17
- readonly type = "durable";
18
- /** Open root span per run, so step entries nest under it and share its traceId. */
19
- private readonly roots;
20
- register(ctx: WatcherContext): void;
21
- private tags;
22
- }
23
- //# sourceMappingURL=durable-telescope.watcher.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"durable-telescope.watcher.d.ts","sourceRoot":"","sources":["../src/durable-telescope.watcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAG1E;;;;;;;;;;;;;GAaG;AACH,qBAAa,uBAAwB,YAAW,OAAO;IACrD,QAAQ,CAAC,IAAI,aAAa;IAC1B,mFAAmF;IACnF,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA2B;IAEjD,QAAQ,CAAC,GAAG,EAAE,cAAc,GAAG,IAAI;IAkEnC,OAAO,CAAC,IAAI;CAOb"}
@@ -1,91 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DurableTelescopeWatcher = void 0;
4
- const nestjs_durable_core_1 = require("@dudousxd/nestjs-durable-core");
5
- const api_1 = require("@opentelemetry/api");
6
- /**
7
- * A Telescope watcher that turns durable-workflow lifecycle events into Telescope entries, so
8
- * runs and steps (including remote/Python steps) show up alongside the app's requests, queries
9
- * and jobs in the Telescope UI — under the **Workflows** tab.
10
- *
11
- * It also **trace-groups** a run: a root span is opened per run and every entry is recorded inside
12
- * that span's OTel context (step entries inside a child `step …` span). Telescope's trace-context
13
- * provider stamps each entry with the active span, so a whole workflow shows up as a single trace
14
- * on the Traces page — run → steps — with each entry carrying the run's `traceId`. When the host has
15
- * no OTel SDK the spans are no-ops and entries simply carry no trace (the prior behaviour).
16
- *
17
- * Add it to `TelescopeModule.forRoot({ watchers: [new DurableTelescopeWatcher()] })`. It resolves
18
- * the engine from the (global) durable providers and subscribes to its events.
19
- */
20
- class DurableTelescopeWatcher {
21
- type = 'durable';
22
- /** Open root span per run, so step entries nest under it and share its traceId. */
23
- roots = new Map();
24
- register(ctx) {
25
- const engine = ctx.moduleRef.get(nestjs_durable_core_1.WorkflowEngine, { strict: false });
26
- const tracer = api_1.trace.getTracer('@dudousxd/nestjs-durable-telescope');
27
- engine.subscribe((event) => {
28
- const record = () => ctx.record({
29
- type: this.type,
30
- content: {
31
- event: event.type,
32
- workflow: event.workflow,
33
- runId: event.runId,
34
- seq: event.seq,
35
- name: event.name,
36
- kind: event.kind,
37
- output: event.output,
38
- error: event.error,
39
- },
40
- tags: this.tags(event),
41
- });
42
- // Open the run's root span on first sight; later events nest under it.
43
- if (event.type === 'run.started') {
44
- this.roots.set(event.runId, tracer.startSpan(`workflow ${event.workflow ?? '?'}`, {
45
- attributes: { 'durable.run_id': event.runId, 'durable.workflow': event.workflow },
46
- }));
47
- }
48
- const root = this.roots.get(event.runId);
49
- const base = root ? api_1.trace.setSpan(api_1.context.active(), root) : api_1.context.active();
50
- // A step/signal/sleep event → give it its own child span so it's a distinct node in the
51
- // trace; run-level events record directly on the root. Either way the active span at record
52
- // time carries the run's traceId, so all entries group into one trace.
53
- if (event.name != null && event.seq != null) {
54
- const step = tracer.startSpan(`step ${event.name}`, {
55
- attributes: {
56
- 'durable.run_id': event.runId,
57
- 'durable.step.seq': event.seq,
58
- 'durable.step.kind': event.kind,
59
- },
60
- }, base);
61
- api_1.context.with(api_1.trace.setSpan(base, step), record);
62
- step.end();
63
- }
64
- else {
65
- api_1.context.with(base, record);
66
- }
67
- // Close the run's root span when it leaves the running state.
68
- if (event.type === 'run.completed' || event.type === 'run.suspended') {
69
- root?.end();
70
- this.roots.delete(event.runId);
71
- }
72
- else if (event.type === 'run.failed') {
73
- root?.setStatus({ code: api_1.SpanStatusCode.ERROR, message: event.error?.message });
74
- root?.end();
75
- this.roots.delete(event.runId);
76
- }
77
- });
78
- }
79
- tags(event) {
80
- const tags = ['durable', event.type, `run:${event.runId}`];
81
- if (event.workflow)
82
- tags.push(`workflow:${event.workflow}`);
83
- if (event.kind)
84
- tags.push(`kind:${event.kind}`);
85
- if (event.type === 'run.failed')
86
- tags.push('failed');
87
- return tags;
88
- }
89
- }
90
- exports.DurableTelescopeWatcher = DurableTelescopeWatcher;
91
- //# sourceMappingURL=durable-telescope.watcher.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"durable-telescope.watcher.js","sourceRoot":"","sources":["../src/durable-telescope.watcher.ts"],"names":[],"mappings":";;;AAAA,uEAAiF;AAEjF,4CAA+E;AAE/E;;;;;;;;;;;;;GAaG;AACH,MAAa,uBAAuB;IACzB,IAAI,GAAG,SAAS,CAAC;IAC1B,mFAAmF;IAClE,KAAK,GAAG,IAAI,GAAG,EAAgB,CAAC;IAEjD,QAAQ,CAAC,GAAmB;QAC1B,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,oCAAc,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QACpE,MAAM,MAAM,GAAG,WAAK,CAAC,SAAS,CAAC,oCAAoC,CAAC,CAAC;QAErE,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;YACzB,MAAM,MAAM,GAAG,GAAG,E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