@dudousxd/nestjs-diagnostics-telescope 0.4.0 → 0.5.0
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 +29 -0
- package/README.md +8 -2
- package/dist/diagnostics-telescope.extension.d.ts.map +1 -1
- package/dist/diagnostics-telescope.extension.js +62 -2
- package/dist/diagnostics-telescope.extension.js.map +1 -1
- package/package.json +6 -4
- package/skills/telescope-watcher/SKILL.md +152 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @dudousxd/nestjs-diagnostics-telescope
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#16](https://github.com/DavideCarvalho/nestjs-diagnostics/pull/16) [`3183b6a`](https://github.com/DavideCarvalho/nestjs-diagnostics/commit/3183b6abbfc3d17f8b85bf62d783099983e2d063) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Enrich the Diagnostics dashboard: add an "Events captured" stat and a "By
|
|
8
|
+
library" top-N, and give the Recent events table a time + duration column plus a
|
|
9
|
+
deep-link from each event's trace id straight to the Telescope Traces page — so a
|
|
10
|
+
diagnostic event jumps to the request it was emitted from. New `diagnostics.count`
|
|
11
|
+
and `diagnostics.byLib` data providers back the additions.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#16](https://github.com/DavideCarvalho/nestjs-diagnostics/pull/16) [`540ef8a`](https://github.com/DavideCarvalho/nestjs-diagnostics/commit/540ef8aca15c3c5070088cad1c7777862fc612b7) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Fix the Diagnostics dashboard rendering empty: the extension `name` was
|
|
16
|
+
`nestjs-diagnostics`, but its dashboard id (`diagnostics.diagnostics`) and data
|
|
17
|
+
providers (`diagnostics.*`) use the `diagnostics` namespace. Telescope's
|
|
18
|
+
controller scopes each panel fetch to `/ext/<dashboard-prefix>/data/<provider>`
|
|
19
|
+
and 404s unless the provider's owning extension name equals that prefix, so
|
|
20
|
+
every panel failed with "Unknown data provider". The extension is now named
|
|
21
|
+
`diagnostics` to match.
|
|
22
|
+
|
|
23
|
+
## 0.4.1
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- [#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.
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [[`cced7fc`](https://github.com/DavideCarvalho/nestjs-diagnostics/commit/cced7fc843c84eaf7b51686321294355bf2dd346)]:
|
|
30
|
+
- @dudousxd/nestjs-diagnostics@0.6.1
|
|
31
|
+
|
|
3
32
|
## 0.4.0
|
|
4
33
|
|
|
5
34
|
### Minor 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
|
-
|
|
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":"diagnostics-telescope.extension.d.ts","sourceRoot":"","sources":["../src/diagnostics-telescope.extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,kBAAkB,EAExB,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"diagnostics-telescope.extension.d.ts","sourceRoot":"","sources":["../src/diagnostics-telescope.extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,kBAAkB,EAExB,MAAM,4BAA4B,CAAC;AAapC,sDAAsD;AACtD,MAAM,WAAW,2BAA2B;IAC1C,sEAAsE;IACtE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qEAAqE;IACrE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,GAAE,2BAAgC,GACxC,kBAAkB,CAsIpB;AAmBD,eAAe,0BAA0B,CAAC"}
|
|
@@ -3,6 +3,8 @@ import { DIAGNOSTIC_ENTRY_TYPE, DiagnosticWatcher, } from './diagnostic.watcher.
|
|
|
3
3
|
/** Provider names the dashboard panels bind to (namespaced to avoid collisions). */
|
|
4
4
|
const TOP_EVENTS_PROVIDER = 'diagnostics.topEvents';
|
|
5
5
|
const RECENT_EVENTS_PROVIDER = 'diagnostics.recentEvents';
|
|
6
|
+
const COUNT_PROVIDER = 'diagnostics.count';
|
|
7
|
+
const BY_LIB_PROVIDER = 'diagnostics.byLib';
|
|
6
8
|
/**
|
|
7
9
|
* A `@dudousxd/nestjs-telescope` extension that records every diagnostics event
|
|
8
10
|
* any `@dudousxd/nestjs-*` library emits through `@dudousxd/nestjs-diagnostics`
|
|
@@ -24,7 +26,14 @@ export function nestjsDiagnosticsTelescope(options = {}) {
|
|
|
24
26
|
const topEventsLimit = options.topEventsLimit ?? 10;
|
|
25
27
|
const recentLimit = options.recentLimit ?? 50;
|
|
26
28
|
return {
|
|
27
|
-
name
|
|
29
|
+
// The extension name MUST equal the prefix of the dashboard id and of every
|
|
30
|
+
// data-provider name ('diagnostics.*'). Telescope's controller scopes each
|
|
31
|
+
// panel fetch as `GET /ext/<prefix>/data/<provider>` where `<prefix>` is the
|
|
32
|
+
// dashboard id before the first dot ('diagnostics'), and rejects the request
|
|
33
|
+
// (404 "Unknown data provider") unless `providerOwner(provider) === <prefix>`.
|
|
34
|
+
// A mismatched name ('nestjs-diagnostics') made every panel 404 — the whole
|
|
35
|
+
// Diagnostics dashboard rendered empty.
|
|
36
|
+
name: 'diagnostics',
|
|
28
37
|
watchers() {
|
|
29
38
|
return [new DiagnosticWatcher()];
|
|
30
39
|
},
|
|
@@ -38,20 +47,37 @@ export function nestjsDiagnosticsTelescope(options = {}) {
|
|
|
38
47
|
label: 'Diagnostics',
|
|
39
48
|
navGroup: 'Observability',
|
|
40
49
|
panels: [
|
|
50
|
+
{
|
|
51
|
+
kind: 'stat',
|
|
52
|
+
title: 'Events captured',
|
|
53
|
+
data: { provider: COUNT_PROVIDER },
|
|
54
|
+
format: 'number',
|
|
55
|
+
},
|
|
41
56
|
{
|
|
42
57
|
kind: 'topN',
|
|
43
58
|
title: 'Busiest events',
|
|
44
59
|
data: { provider: TOP_EVENTS_PROVIDER, query: { limit: topEventsLimit } },
|
|
45
60
|
limit: topEventsLimit,
|
|
46
61
|
},
|
|
62
|
+
{
|
|
63
|
+
kind: 'topN',
|
|
64
|
+
title: 'By library',
|
|
65
|
+
data: { provider: BY_LIB_PROVIDER, query: { limit: topEventsLimit } },
|
|
66
|
+
limit: topEventsLimit,
|
|
67
|
+
},
|
|
47
68
|
{
|
|
48
69
|
kind: 'table',
|
|
49
70
|
title: 'Recent events',
|
|
50
71
|
data: { provider: RECENT_EVENTS_PROVIDER, query: { limit: recentLimit } },
|
|
51
72
|
columns: [
|
|
73
|
+
{ key: 'time', label: 'Time' },
|
|
52
74
|
{ key: 'lib', label: 'Library' },
|
|
53
75
|
{ key: 'event', label: 'Event' },
|
|
54
|
-
{ key: '
|
|
76
|
+
{ key: 'durationMs', label: 'ms' },
|
|
77
|
+
// Deep-link to the Traces page so a diagnostic event jumps straight
|
|
78
|
+
// to the request/trace it was emitted from. Empty traceId renders as
|
|
79
|
+
// plain text via the {traceId} template collapsing to the list route.
|
|
80
|
+
{ key: 'traceId', label: 'Trace', link: { href: '#/traces/{traceId}' } },
|
|
55
81
|
],
|
|
56
82
|
},
|
|
57
83
|
],
|
|
@@ -60,6 +86,32 @@ export function nestjsDiagnosticsTelescope(options = {}) {
|
|
|
60
86
|
},
|
|
61
87
|
dataProviders() {
|
|
62
88
|
return [
|
|
89
|
+
{
|
|
90
|
+
name: COUNT_PROVIDER,
|
|
91
|
+
async resolve(_query, ctx) {
|
|
92
|
+
const entries = await loadDiagnostics(ctx, 5_000);
|
|
93
|
+
return { value: entries.length };
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: BY_LIB_PROVIDER,
|
|
98
|
+
async resolve(query, ctx) {
|
|
99
|
+
const limit = numberOr(query?.limit, topEventsLimit);
|
|
100
|
+
const entries = await loadDiagnostics(ctx, 5_000);
|
|
101
|
+
const counts = new Map();
|
|
102
|
+
for (const entry of entries) {
|
|
103
|
+
const content = entry.content;
|
|
104
|
+
if (!content)
|
|
105
|
+
continue;
|
|
106
|
+
counts.set(content.lib, (counts.get(content.lib) ?? 0) + 1);
|
|
107
|
+
}
|
|
108
|
+
const items = [...counts.entries()]
|
|
109
|
+
.map(([label, value]) => ({ label, value }))
|
|
110
|
+
.sort((a, b) => b.value - a.value)
|
|
111
|
+
.slice(0, limit);
|
|
112
|
+
return { items };
|
|
113
|
+
},
|
|
114
|
+
},
|
|
63
115
|
{
|
|
64
116
|
name: TOP_EVENTS_PROVIDER,
|
|
65
117
|
async resolve(query, ctx) {
|
|
@@ -88,8 +140,10 @@ export function nestjsDiagnosticsTelescope(options = {}) {
|
|
|
88
140
|
const rows = entries.map((entry) => {
|
|
89
141
|
const content = entry.content;
|
|
90
142
|
return {
|
|
143
|
+
time: formatTime(content?.ts),
|
|
91
144
|
lib: content?.lib ?? null,
|
|
92
145
|
event: content?.event ?? null,
|
|
146
|
+
durationMs: entry.durationMs ?? null,
|
|
93
147
|
traceId: content?.traceId ?? null,
|
|
94
148
|
};
|
|
95
149
|
});
|
|
@@ -109,5 +163,11 @@ async function loadDiagnostics(ctx, limit = 200) {
|
|
|
109
163
|
function numberOr(value, fallback) {
|
|
110
164
|
return typeof value === 'number' && Number.isFinite(value) ? value : fallback;
|
|
111
165
|
}
|
|
166
|
+
/** Format a producer epoch-ms timestamp as a compact UTC `HH:mm:ss`, or '' when absent. */
|
|
167
|
+
function formatTime(ts) {
|
|
168
|
+
if (typeof ts !== 'number' || !Number.isFinite(ts))
|
|
169
|
+
return '';
|
|
170
|
+
return new Date(ts).toISOString().slice(11, 19);
|
|
171
|
+
}
|
|
112
172
|
export default nestjsDiagnosticsTelescope;
|
|
113
173
|
//# sourceMappingURL=diagnostics-telescope.extension.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics-telescope.extension.js","sourceRoot":"","sources":["../src/diagnostics-telescope.extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,iBAAiB,GAGlB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,qBAAqB,EAErB,iBAAiB,GAClB,MAAM,yBAAyB,CAAC;AAEjC,oFAAoF;AACpF,MAAM,mBAAmB,GAAG,uBAAuB,CAAC;AACpD,MAAM,sBAAsB,GAAG,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"diagnostics-telescope.extension.js","sourceRoot":"","sources":["../src/diagnostics-telescope.extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,iBAAiB,GAGlB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,qBAAqB,EAErB,iBAAiB,GAClB,MAAM,yBAAyB,CAAC;AAEjC,oFAAoF;AACpF,MAAM,mBAAmB,GAAG,uBAAuB,CAAC;AACpD,MAAM,sBAAsB,GAAG,0BAA0B,CAAC;AAC1D,MAAM,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AAC;KACF,CAAC;AACJ,CAAC;AAED,kEAAkE;AAClE,KAAK,UAAU,eAAe,CAAC,GAAqB,EAAE,KAAK,GAAG,GAAG;IAC/D,MAAM,OAAO,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAAkB,iBAAiB,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IACzF,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,qBAAqB,EAAE,KAAK,EAAE,CAAC,CAAC;IACvE,OAAO,IAAI,CAAC,IAAI,CAAC;AACnB,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc,EAAE,QAAgB;IAChD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC;AAChF,CAAC;AAED,2FAA2F;AAC3F,SAAS,UAAU,CAAC,EAAsB;IACxC,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;QAAE,OAAO,EAAE,CAAC;IAC9D,OAAO,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAClD,CAAC;AAED,eAAe,0BAA0B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dudousxd/nestjs-diagnostics-telescope",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
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.6.
|
|
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).
|