@dudousxd/nestjs-diagnostics-telescope 0.3.2 → 0.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @dudousxd/nestjs-diagnostics-telescope
2
2
 
3
+ ## 0.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#14](https://github.com/DavideCarvalho/nestjs-diagnostics/pull/14) [`cced7fc`](https://github.com/DavideCarvalho/nestjs-diagnostics/commit/cced7fc843c84eaf7b51686321294355bf2dd346) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Ship TanStack Intent agent skills (SKILL.md) inside the package.
8
+
9
+ - Updated dependencies [[`cced7fc`](https://github.com/DavideCarvalho/nestjs-diagnostics/commit/cced7fc843c84eaf7b51686321294355bf2dd346)]:
10
+ - @dudousxd/nestjs-diagnostics@0.6.1
11
+
12
+ ## 0.4.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [`16bd3a5`](https://github.com/DavideCarvalho/nestjs-diagnostics/commit/16bd3a5ae975edb8e8b9b8ea59d52e7a9a0b470f) - Diagnostics events can carry an optional `durationMs`. `emit(lib, event, payload, { durationMs })` stamps a wall-clock duration onto the envelope, and the generic Telescope watcher forwards it to the recorded entry's `durationMs`. This lets an observer (e.g. the Telescope OTel exporter) turn an `aviary:<lib>:<event>` stream into a **duration histogram** (p95/p99) instead of only a counter — so latency metrics can move onto the diagnostics→telescope path without losing their distribution.
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [[`16bd3a5`](https://github.com/DavideCarvalho/nestjs-diagnostics/commit/16bd3a5ae975edb8e8b9b8ea59d52e7a9a0b470f)]:
21
+ - @dudousxd/nestjs-diagnostics@0.6.0
22
+
3
23
  ## 0.3.2
4
24
 
5
25
  ### Patch Changes
package/README.md CHANGED
@@ -24,12 +24,18 @@ TelescopeModule.forRoot({
24
24
  });
25
25
  ```
26
26
 
27
- Then anywhere a library emits:
27
+ Then anywhere a library emits — e.g. from a provider:
28
28
 
29
29
  ```ts
30
+ import { Injectable } from '@nestjs/common';
30
31
  import { emit } from '@dudousxd/nestjs-diagnostics';
31
32
 
32
- emit('billing', 'invoice-paid', { invoiceId: 'inv_123', amount: 4200 });
33
+ @Injectable()
34
+ export class BillingService {
35
+ async markInvoicePaid(invoiceId: string, amount: number) {
36
+ emit('billing', 'invoice-paid', { invoiceId, amount });
37
+ }
38
+ }
33
39
  ```
34
40
 
35
41
  …a `diagnostic` entry lands in Telescope with `content` = the payload, the
@@ -1 +1 @@
1
- {"version":3,"file":"diagnostic.watcher.d.ts","sourceRoot":"","sources":["../src/diagnostic.watcher.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,eAAe,EAGrB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEvF,uDAAuD;AACvD,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAElD;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjB,8CAA8C;IAC9C,GAAG,EAAE,MAAM,CAAC;IACZ,4DAA4D;IAC5D,KAAK,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,EAAE,EAAE,MAAM,CAAC;IACX,+DAA+D;IAC/D,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,mDAAmD;IACnD,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,iBAAkB,YAAW,OAAO;IAC/C,QAAQ,CAAC,IAAI,gBAAyB;IACtC,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,oBAAoB,CAA6B;IACzD,gFAAgF;IAChF,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA6C;IAE3E,QAAQ,CAAC,GAAG,EAAE,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,qEAAqE;IACrE,OAAO,IAAI,IAAI;IAUf,gFAAgF;IAChF,OAAO,CAAC,SAAS;IAQjB,+EAA+E;IAC/E,OAAO,CAAC,UAAU;CASnB;AAED,2EAA2E;AAC3E,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,eAAe,GAAG,WAAW,CAAC,sBAAsB,CAAC,CA0B9F;AAED,8DAA8D;AAC9D,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,eAAe,CAYtE"}
@@ -87,6 +87,11 @@ export function buildDiagnosticEntry(msg) {
87
87
  ...(msg.traceId ? [`trace:${msg.traceId}`] : []),
88
88
  ],
89
89
  content,
90
+ // Forward the emitter-supplied duration so the OTel exporter can feed it
91
+ // into a histogram instrument instead of only incrementing a counter.
92
+ // Only set the key when the envelope carried a duration; omit it otherwise
93
+ // so the Recorder treats it as "unknown duration" (null after enrichment).
94
+ ...(msg.durationMs !== undefined && { durationMs: msg.durationMs }),
90
95
  };
91
96
  }
92
97
  /** Strict structural validation of a diagnostics envelope. */
@@ -1 +1 @@
1
- {"version":3,"file":"diagnostic.watcher.js","sourceRoot":"","sources":["../src/diagnostic.watcher.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAqC,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAEL,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,8BAA8B,CAAC;AAGtC,uDAAuD;AACvD,MAAM,CAAC,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAyBlD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,iBAAiB;IACnB,IAAI,GAAG,qBAAqB,CAAC;IAC9B,UAAU,GAAG,KAAK,CAAC;IACnB,oBAAoB,GAAwB,IAAI,CAAC;IACzD,gFAAgF;IAC/D,aAAa,GAAG,IAAI,GAAG,EAAkC,CAAC;IAE3E,QAAQ,CAAC,GAAmB;QAC1B,IAAI,IAAI,CAAC,UAAU;YAAE,OAAO;QAC5B,IAAI,CAAC,UA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I,OAAO,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAC/C,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudousxd/nestjs-diagnostics-telescope",
3
- "version": "0.3.2",
3
+ "version": "0.4.1",
4
4
  "description": "nestjs-telescope extension for @dudousxd/nestjs-diagnostics — one generic watcher records every aviary:<lib>:<event> diagnostic event in the Telescope dashboard.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -22,12 +22,13 @@
22
22
  "files": [
23
23
  "dist/",
24
24
  "README.md",
25
- "CHANGELOG.md"
25
+ "CHANGELOG.md",
26
+ "skills"
26
27
  ],
27
28
  "//sideEffects": "Safe to be false: this package has NO module-level side effects. The watcher subscribes to diagnostics channels only inside register() at runtime, never at import time, and the rest are pure declarations/exports. Enables tree-shaking for consumers.",
28
29
  "sideEffects": false,
29
30
  "dependencies": {
30
- "@dudousxd/nestjs-diagnostics": "^0.5.0"
31
+ "@dudousxd/nestjs-diagnostics": "^0.6.1"
31
32
  },
32
33
  "peerDependencies": {
33
34
  "@dudousxd/nestjs-telescope": "^1.9.0"
@@ -49,7 +50,8 @@
49
50
  "telescope",
50
51
  "observability",
51
52
  "watcher",
52
- "extension"
53
+ "extension",
54
+ "tanstack-intent"
53
55
  ],
54
56
  "scripts": {
55
57
  "build": "tsc -p tsconfig.json",
@@ -0,0 +1,152 @@
1
+ ---
2
+ name: telescope-watcher
3
+ description: Record every @dudousxd/nestjs-diagnostics event in the Telescope dashboard with @dudousxd/nestjs-diagnostics-telescope. nestjsDiagnosticsTelescope({ topEventsLimit, recentLimit }) is one generic extension passed to TelescopeModule.forRoot({ extensions }); a single DiagnosticWatcher subscribes to every aviary:<lib>:<event> channel (current and future) and writes one diagnostic entry per publish, with payload as content, traceId, and tags lib:<lib> / event:<event>. Adds a Diagnostics dashboard (diagnostics.topEvents, diagnostics.recentEvents). No per-library watcher needed.
4
+ license: MIT
5
+ metadata:
6
+ type: core
7
+ library: "@dudousxd/nestjs-diagnostics-telescope"
8
+ library_version: 0.4.0
9
+ framework: nestjs
10
+ ---
11
+
12
+ # Record diagnostics in Telescope
13
+
14
+ `@dudousxd/nestjs-diagnostics-telescope` is a `@dudousxd/nestjs-telescope`
15
+ extension. ONE generic watcher records **every** `aviary:<lib>:<event>`
16
+ diagnostics event — from any `@dudousxd/nestjs-*` library — as a `diagnostic`
17
+ entry in the Telescope dashboard. No per-library watcher needed.
18
+
19
+ ## Setup
20
+
21
+ ```bash
22
+ pnpm add @dudousxd/nestjs-diagnostics-telescope
23
+ # peers: @dudousxd/nestjs-telescope, plus @dudousxd/nestjs-diagnostics on producers
24
+ ```
25
+
26
+ Pass the extension to Telescope at the app root:
27
+
28
+ ```ts
29
+ import { TelescopeModule } from '@dudousxd/nestjs-telescope';
30
+ import { nestjsDiagnosticsTelescope } from '@dudousxd/nestjs-diagnostics-telescope';
31
+
32
+ @Module({
33
+ imports: [
34
+ TelescopeModule.forRoot({
35
+ extensions: [nestjsDiagnosticsTelescope()],
36
+ }),
37
+ ],
38
+ })
39
+ export class AppModule {}
40
+ ```
41
+
42
+ Then anywhere a library emits, a `diagnostic` entry lands in Telescope with
43
+ `content` = the payload, the envelope's `traceId`, and tags
44
+ `lib:<lib>` / `event:<event>`:
45
+
46
+ ```ts
47
+ import { Injectable } from '@nestjs/common';
48
+ import { emit } from '@dudousxd/nestjs-diagnostics';
49
+
50
+ @Injectable()
51
+ export class BillingService {
52
+ markInvoicePaid(invoiceId: string, amount: number) {
53
+ emit('billing', 'invoice-paid', { invoiceId, amount });
54
+ }
55
+ }
56
+ ```
57
+
58
+ Source: `packages/telescope/src/diagnostics-telescope.extension.ts`,
59
+ `packages/telescope/src/diagnostic.watcher.ts`.
60
+
61
+ ## Core patterns
62
+
63
+ ### 1. One generic watcher auto-subscribes to current + future channels
64
+
65
+ `node:diagnostics_channel` has no wildcard, so on `register` the
66
+ `DiagnosticWatcher` subscribes to every channel already in the diagnostics
67
+ registry (`registeredChannels()`) and registers an `onChannelRegistered` callback
68
+ so any channel that appears later (a library's first `emit('newlib', …)`) is
69
+ subscribed automatically. Subscribing also flips each producer's
70
+ `channel.hasSubscribers` to `true`, which is what makes `emit()` start publishing.
71
+
72
+ Source: `packages/telescope/src/diagnostic.watcher.ts` (`DiagnosticWatcher.register`).
73
+
74
+ ### 2. Tuning the dashboard panels
75
+
76
+ `nestjsDiagnosticsTelescope(options)` accepts `topEventsLimit` (busiest
77
+ `lib:event` pairs panel, default 10) and `recentLimit` (recent-events table,
78
+ default 50):
79
+
80
+ ```ts
81
+ nestjsDiagnosticsTelescope({ topEventsLimit: 20, recentLimit: 100 });
82
+ ```
83
+
84
+ The extension contributes a `diagnostic` entry type (sky dot), a "Diagnostics"
85
+ dashboard, and two data providers — `diagnostics.topEvents` and
86
+ `diagnostics.recentEvents`.
87
+
88
+ Source: `packages/telescope/src/diagnostics-telescope.extension.ts` (`DiagnosticsTelescopeOptions`, `dashboards`, `dataProviders`).
89
+
90
+ ### 3. What a recorded entry looks like
91
+
92
+ Each publish becomes a `RecordInput` with `type: 'diagnostic'`, `familyHash`
93
+ `<lib>:<event>` (so the dashboard rolls up "billing:invoice-paid"), tags, and a
94
+ `DiagnosticEntryContent` (`v`, `lib`, `event`, `ts`, `traceId`, `payload`). An
95
+ emitter-supplied `durationMs` is forwarded so a downstream OTel exporter can feed
96
+ a histogram. Malformed envelopes are rejected by `isDiagnosticEvent`.
97
+
98
+ Source: `packages/telescope/src/diagnostic.watcher.ts` (`buildDiagnosticEntry`, `isDiagnosticEvent`, `DiagnosticEntryContent`).
99
+
100
+ ## Common mistakes
101
+
102
+ ### Calling the extension's name as a string instead of invoking the factory
103
+
104
+ ```ts
105
+ // Wrong — passing the module specifier / the function itself, not its result.
106
+ TelescopeModule.forRoot({ extensions: ['nestjs-diagnostics'] });
107
+ TelescopeModule.forRoot({ extensions: [nestjsDiagnosticsTelescope] }); // not called
108
+ ```
109
+
110
+ ```ts
111
+ // Correct — call the factory; it returns the TelescopeExtension object.
112
+ TelescopeModule.forRoot({ extensions: [nestjsDiagnosticsTelescope()] });
113
+ ```
114
+
115
+ `nestjsDiagnosticsTelescope()` builds and returns the extension (with its
116
+ `watchers`/`entryTypes`/`dashboards`/`dataProviders` hooks); the bare reference or
117
+ a string is not a valid extension.
118
+ Source: `packages/telescope/src/diagnostics-telescope.extension.ts` (`nestjsDiagnosticsTelescope` returns `TelescopeExtension`).
119
+
120
+ ### Adding a per-library watcher alongside this one
121
+
122
+ ```ts
123
+ // Wrong — a bespoke watcher per library double-records and is unnecessary.
124
+ extensions: [nestjsDiagnosticsTelescope(), myBillingDiagnosticsWatcher()];
125
+ ```
126
+
127
+ ```ts
128
+ // Correct — the single generic watcher already covers every aviary channel.
129
+ extensions: [nestjsDiagnosticsTelescope()];
130
+ ```
131
+
132
+ One `DiagnosticWatcher` subscribes to all current and future `aviary:<lib>:<event>`
133
+ channels, so every library's events are recorded without a per-library watcher.
134
+ Source: `packages/telescope/src/diagnostics-telescope.extension.ts` (`watchers()` returns one `DiagnosticWatcher`).
135
+
136
+ ### Expecting entries when no producer ever emits
137
+
138
+ ```ts
139
+ // Wrong — registering the extension but never emitting anything.
140
+ TelescopeModule.forRoot({ extensions: [nestjsDiagnosticsTelescope()] });
141
+ // (no library calls emit / trace) — the Diagnostics page stays empty
142
+ ```
143
+
144
+ ```ts
145
+ // Correct — a producer must emit on an aviary channel for entries to appear.
146
+ import { emit } from '@dudousxd/nestjs-diagnostics';
147
+ emit('billing', 'invoice-paid', { invoiceId, amount });
148
+ ```
149
+
150
+ The watcher only records what is published; a channel is registered the first
151
+ time a producer touches it, and entries appear only on actual `emit`/`trace`.
152
+ Source: `packages/telescope/src/diagnostic.watcher.ts` (`safeRecord` records on publish).