@dudousxd/nestjs-diagnostics-redis 0.2.0 → 0.2.2
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 +16 -0
- package/package.json +6 -4
- package/skills/redis-transport/SKILL.md +168 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @dudousxd/nestjs-diagnostics-redis
|
|
2
2
|
|
|
3
|
+
## 0.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`1568de4`](https://github.com/DavideCarvalho/nestjs-diagnostics/commit/1568de44f05770ad2559f7d6d4ea38d9d213d7e5)]:
|
|
8
|
+
- @dudousxd/nestjs-diagnostics@0.7.0
|
|
9
|
+
|
|
10
|
+
## 0.2.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [#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.
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [[`cced7fc`](https://github.com/DavideCarvalho/nestjs-diagnostics/commit/cced7fc843c84eaf7b51686321294355bf2dd346)]:
|
|
17
|
+
- @dudousxd/nestjs-diagnostics@0.6.1
|
|
18
|
+
|
|
3
19
|
## 0.2.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dudousxd/nestjs-diagnostics-redis",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Cross-process transport for @dudousxd/nestjs-diagnostics — relay aviary:<lib>:<event> events over Redis pub/sub so @OnDiagnostic handlers fire across processes.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -22,11 +22,12 @@
|
|
|
22
22
|
"files": [
|
|
23
23
|
"dist/",
|
|
24
24
|
"README.md",
|
|
25
|
-
"CHANGELOG.md"
|
|
25
|
+
"CHANGELOG.md",
|
|
26
|
+
"skills"
|
|
26
27
|
],
|
|
27
28
|
"sideEffects": false,
|
|
28
29
|
"dependencies": {
|
|
29
|
-
"@dudousxd/nestjs-diagnostics": "^0.
|
|
30
|
+
"@dudousxd/nestjs-diagnostics": "^0.7.0"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {
|
|
32
33
|
"ioredis": "^5",
|
|
@@ -65,7 +66,8 @@
|
|
|
65
66
|
"redis",
|
|
66
67
|
"transport",
|
|
67
68
|
"cross-process",
|
|
68
|
-
"aviary"
|
|
69
|
+
"aviary",
|
|
70
|
+
"tanstack-intent"
|
|
69
71
|
],
|
|
70
72
|
"scripts": {
|
|
71
73
|
"build": "tsc -p tsconfig.json",
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: redis-transport
|
|
3
|
+
description: Relay @dudousxd/nestjs-diagnostics events across processes/pods over Redis pub/sub with @dudousxd/nestjs-diagnostics-redis. DiagnosticsRedisModule.forRootAsync/forRoot({ pub, sub, libs, channels, all }) wires it from DI; createDiagnosticsRedisRelay() is the manual form returning a teardown. Forwards selected local aviary:<lib>:<event> channels to Redis and re-emits remote events locally so @OnDiagnostic fires cross-process. Needs separate pub and sub ioredis connections (redis.duplicate()); loop-safe via nodeId echo suppression; payloads cross as JSON.
|
|
4
|
+
license: MIT
|
|
5
|
+
metadata:
|
|
6
|
+
type: core
|
|
7
|
+
library: "@dudousxd/nestjs-diagnostics-redis"
|
|
8
|
+
library_version: 0.1.2
|
|
9
|
+
framework: nestjs
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Cross-process diagnostics over Redis
|
|
13
|
+
|
|
14
|
+
`@dudousxd/nestjs-diagnostics-redis` is an opt-in **relay**: it forwards selected
|
|
15
|
+
local `aviary:<lib>:<event>` channels onto Redis pub/sub and re-emits
|
|
16
|
+
Redis-received events back onto the local diagnostics bus — so `@OnDiagnostic`
|
|
17
|
+
handlers and `getChannel(...).subscribe(...)` reactions fire **across
|
|
18
|
+
processes/pods**. The diagnostics core stays in-process and untouched.
|
|
19
|
+
|
|
20
|
+
## Setup
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pnpm add @dudousxd/nestjs-diagnostics-redis @dudousxd/nestjs-diagnostics ioredis
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Supply your own ioredis connections — a publisher and a **separate** subscriber
|
|
27
|
+
(`redis.duplicate()`, since a subscribed connection can't publish). Prefer
|
|
28
|
+
`forRootAsync` so the relay's clients come from the same DI container:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import type Redis from 'ioredis';
|
|
32
|
+
import { Module } from '@nestjs/common';
|
|
33
|
+
import { DiagnosticsRedisModule } from '@dudousxd/nestjs-diagnostics-redis';
|
|
34
|
+
import { REDIS, RedisModule } from './redis.module';
|
|
35
|
+
|
|
36
|
+
@Module({
|
|
37
|
+
imports: [
|
|
38
|
+
DiagnosticsRedisModule.forRootAsync({
|
|
39
|
+
imports: [RedisModule],
|
|
40
|
+
inject: [REDIS],
|
|
41
|
+
useFactory: (redis: Redis) => ({
|
|
42
|
+
pub: redis,
|
|
43
|
+
sub: redis.duplicate(),
|
|
44
|
+
libs: ['durable', 'notifications'], // forward all events of these libs
|
|
45
|
+
}),
|
|
46
|
+
}),
|
|
47
|
+
],
|
|
48
|
+
})
|
|
49
|
+
export class AppModule {}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Now an `@OnDiagnostic('durable', 'run.failed')` handler in **another** process
|
|
53
|
+
fires when a worker elsewhere emits it.
|
|
54
|
+
|
|
55
|
+
Source: `packages/redis/src/diagnostics-redis.module.ts`, `packages/redis/src/relay.ts`.
|
|
56
|
+
|
|
57
|
+
## Core patterns
|
|
58
|
+
|
|
59
|
+
### 1. Selecting what to forward: libs, channels, all
|
|
60
|
+
|
|
61
|
+
The relay options pick which local channels are forwarded:
|
|
62
|
+
|
|
63
|
+
- `libs: ['durable']` — every `aviary:durable:*` channel (current + future).
|
|
64
|
+
- `channels: [{ lib: 'resilience', event: 'circuit-opened' }]` — exact channels.
|
|
65
|
+
- `all: true` — every `aviary:*` channel; overrides `libs`/`channels`.
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
DiagnosticsRedisModule.forRoot({
|
|
69
|
+
pub: redis,
|
|
70
|
+
sub: redis.duplicate(),
|
|
71
|
+
channels: [{ lib: 'resilience', event: 'circuit-opened' }],
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Wildcard selections subscribe to matching channels at startup and via
|
|
76
|
+
`onChannelRegistered` for ones that appear later.
|
|
77
|
+
|
|
78
|
+
Source: `packages/redis/src/relay.ts` (`wildcardMatches`, `subscribeRef`, `DiagnosticsRedisRelayOptions`).
|
|
79
|
+
|
|
80
|
+
### 2. Manual relay outside Nest
|
|
81
|
+
|
|
82
|
+
`createDiagnosticsRedisRelay(options)` returns a `teardown()` that removes all
|
|
83
|
+
local subscriptions and the Redis message handler. It never opens or closes your
|
|
84
|
+
Redis connections — you own their lifecycle:
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import { createDiagnosticsRedisRelay } from '@dudousxd/nestjs-diagnostics-redis';
|
|
88
|
+
|
|
89
|
+
const teardown = createDiagnosticsRedisRelay({
|
|
90
|
+
pub: redis,
|
|
91
|
+
sub: redis.duplicate(),
|
|
92
|
+
libs: ['durable'],
|
|
93
|
+
});
|
|
94
|
+
// … later
|
|
95
|
+
teardown();
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Source: `packages/redis/src/relay.ts` (`createDiagnosticsRedisRelay`).
|
|
99
|
+
|
|
100
|
+
### 3. Loop-safety
|
|
101
|
+
|
|
102
|
+
Each relay tags its publishes with a per-process `nodeId`. The receiver skips its
|
|
103
|
+
own echoes (`node === nodeId`) and a re-emit guard (a `WeakSet`) stops a
|
|
104
|
+
received event from being forwarded back — so two processes never ping-pong. The
|
|
105
|
+
default Redis channel is `aviary:diagnostics:relay` (override with
|
|
106
|
+
`redisChannel`).
|
|
107
|
+
|
|
108
|
+
Source: `packages/redis/src/relay.ts` (`forward`, `onMessage`, `reEmitting`).
|
|
109
|
+
|
|
110
|
+
## Common mistakes
|
|
111
|
+
|
|
112
|
+
### Reusing one ioredis connection for both pub and sub
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
// Wrong — once `sub` enters subscriber mode it can't publish; commands error.
|
|
116
|
+
const conn = new Redis();
|
|
117
|
+
DiagnosticsRedisModule.forRoot({ pub: conn, sub: conn, libs: ['durable'] });
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
// Correct — a separate subscriber via duplicate().
|
|
122
|
+
const redis = new Redis();
|
|
123
|
+
DiagnosticsRedisModule.forRoot({ pub: redis, sub: redis.duplicate(), libs: ['durable'] });
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
ioredis puts a connection that has `subscribe`d into subscriber mode where most
|
|
127
|
+
commands (including `publish`) are rejected — the relay needs two connections.
|
|
128
|
+
Source: `packages/redis/src/relay.ts` (`sub` docs: "separate from `pub`").
|
|
129
|
+
|
|
130
|
+
### Reading methods/Date on a cross-process payload
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
// Wrong — across the boundary the payload is plain JSON; methods/prototype are gone.
|
|
134
|
+
@OnDiagnostic('durable', 'run.failed')
|
|
135
|
+
onFail(e: DiagnosticEvent<RunFailed>) {
|
|
136
|
+
e.payload.failedAt.getTime(); // failedAt is an ISO string, not a Date — throws
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
// Correct — read fields, and parse serialized values yourself.
|
|
142
|
+
onFail(e: DiagnosticEvent<{ failedAt: string }>) {
|
|
143
|
+
const at = new Date(e.payload.failedAt).getTime();
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Payloads cross the process boundary as JSON: class instances arrive as plain
|
|
148
|
+
objects (no methods/prototype), `Date` as an ISO string. Read fields, not
|
|
149
|
+
behavior, in cross-process handlers.
|
|
150
|
+
Source: `packages/redis/src/relay.ts` (`forward`/`onMessage` JSON), redis README "Notes".
|
|
151
|
+
|
|
152
|
+
### Expecting the module to manage your Redis connection lifecycle
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
// Wrong — assuming the module connects/quits Redis for you.
|
|
156
|
+
DiagnosticsRedisModule.forRoot({ pub: redis, sub: redis.duplicate(), libs: ['durable'] });
|
|
157
|
+
// (no redis.quit() anywhere) — connections leak on shutdown
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
// Correct — you own connect/quit; the module only manages relay subscriptions.
|
|
162
|
+
// e.g. in your Redis provider's onApplicationShutdown: await redis.quit();
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The relay teardown removes only its own subscriptions and Redis message handler;
|
|
166
|
+
it never opens or closes `pub`/`sub`. Manage their lifecycle in your own provider.
|
|
167
|
+
Source: `packages/redis/src/diagnostics-redis.module.ts` (`DiagnosticsRedisStarter` teardown),
|
|
168
|
+
`packages/redis/src/relay.ts` (return teardown).
|