@ngn-net/nestjs-telescope 0.3.5 → 0.3.7
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/ui/manifest.json
CHANGED
|
@@ -22,7 +22,7 @@ let RabbitMQWatcher = RabbitMQWatcher_1 = class RabbitMQWatcher {
|
|
|
22
22
|
}
|
|
23
23
|
onModuleInit() {
|
|
24
24
|
this.patchAmqpConnection();
|
|
25
|
-
this.
|
|
25
|
+
this.patchAmqplibChannel();
|
|
26
26
|
}
|
|
27
27
|
patchAmqpConnection() {
|
|
28
28
|
try {
|
|
@@ -37,14 +37,13 @@ let RabbitMQWatcher = RabbitMQWatcher_1 = class RabbitMQWatcher {
|
|
|
37
37
|
const startTime = Date.now();
|
|
38
38
|
const result = await originalPublish.call(this, exchange, routingKey, msg, ...args);
|
|
39
39
|
const duration = Date.now() - startTime;
|
|
40
|
-
const sanitizedMsg = self.sanitizeMessage(msg);
|
|
41
40
|
self.telescope.record({
|
|
42
41
|
type: entry_type_enum_1.EntryType.RABBITMQ,
|
|
43
42
|
content: {
|
|
44
43
|
direction: 'outgoing',
|
|
45
44
|
exchange,
|
|
46
45
|
routingKey,
|
|
47
|
-
message:
|
|
46
|
+
message: self.sanitizeMessage(msg),
|
|
48
47
|
duration,
|
|
49
48
|
status: 'sent',
|
|
50
49
|
},
|
|
@@ -54,138 +53,56 @@ let RabbitMQWatcher = RabbitMQWatcher_1 = class RabbitMQWatcher {
|
|
|
54
53
|
}
|
|
55
54
|
catch { }
|
|
56
55
|
}
|
|
57
|
-
|
|
56
|
+
patchAmqplibChannel() {
|
|
58
57
|
try {
|
|
59
|
-
const
|
|
60
|
-
if (!
|
|
58
|
+
const amqplib = require('amqplib');
|
|
59
|
+
if (!amqplib)
|
|
60
|
+
return;
|
|
61
|
+
const Channel = amqplib.Channel;
|
|
62
|
+
if (!Channel || !Channel.prototype)
|
|
63
|
+
return;
|
|
64
|
+
const originalConsume = Channel.prototype.consume;
|
|
65
|
+
if (!originalConsume)
|
|
61
66
|
return;
|
|
62
67
|
const self = this;
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
self.telescope.record({
|
|
92
|
-
type: entry_type_enum_1.EntryType.RABBITMQ,
|
|
93
|
-
content: {
|
|
94
|
-
direction: 'incoming_response',
|
|
95
|
-
exchange,
|
|
96
|
-
routingKey,
|
|
97
|
-
queue,
|
|
98
|
-
handler: `${target.constructor?.name || 'Unknown'}.${propertyKey}`,
|
|
99
|
-
duration,
|
|
100
|
-
status: 'completed',
|
|
101
|
-
},
|
|
102
|
-
}).catch(() => { });
|
|
103
|
-
return result;
|
|
104
|
-
}
|
|
105
|
-
catch (err) {
|
|
106
|
-
const duration = Date.now() - startTime;
|
|
107
|
-
self.telescope.record({
|
|
108
|
-
type: entry_type_enum_1.EntryType.RABBITMQ,
|
|
109
|
-
content: {
|
|
110
|
-
direction: 'incoming_response',
|
|
111
|
-
exchange,
|
|
112
|
-
routingKey,
|
|
113
|
-
queue,
|
|
114
|
-
handler: `${target.constructor?.name || 'Unknown'}.${propertyKey}`,
|
|
115
|
-
duration,
|
|
116
|
-
status: 'failed',
|
|
117
|
-
error: err.message || String(err),
|
|
118
|
-
},
|
|
119
|
-
}).catch(() => { });
|
|
120
|
-
throw err;
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
return descriptor;
|
|
124
|
-
};
|
|
68
|
+
const handlerMap = new Map();
|
|
69
|
+
Channel.prototype.consume = function (queue, onMessage, options) {
|
|
70
|
+
const wrappedOnMessage = (msg) => {
|
|
71
|
+
if (!msg || !msg.content)
|
|
72
|
+
return onMessage(msg);
|
|
73
|
+
const startTime = Date.now();
|
|
74
|
+
let parsed;
|
|
75
|
+
try {
|
|
76
|
+
parsed = JSON.parse(msg.content.toString());
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
parsed = msg.content.toString();
|
|
80
|
+
}
|
|
81
|
+
self.telescope.record({
|
|
82
|
+
type: entry_type_enum_1.EntryType.RABBITMQ,
|
|
83
|
+
content: {
|
|
84
|
+
direction: 'incoming',
|
|
85
|
+
queue,
|
|
86
|
+
exchange: msg.fields?.exchange || '',
|
|
87
|
+
routingKey: msg.fields?.routingKey || queue,
|
|
88
|
+
message: self.sanitizeMessage(parsed),
|
|
89
|
+
deliveryTag: msg.fields?.deliveryTag,
|
|
90
|
+
redelivered: msg.fields?.redelivered,
|
|
91
|
+
consumerTag: msg.fields?.consumerTag,
|
|
92
|
+
timestamp: new Date().toISOString(),
|
|
93
|
+
},
|
|
94
|
+
}).catch(() => { });
|
|
95
|
+
return onMessage(msg);
|
|
125
96
|
};
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const routingKey = options?.routingKey || '';
|
|
136
|
-
const queue = options?.queue || '';
|
|
137
|
-
descriptor.value = async function (...args) {
|
|
138
|
-
const startTime = Date.now();
|
|
139
|
-
const incomingMsg = args[0];
|
|
140
|
-
self.telescope.record({
|
|
141
|
-
type: entry_type_enum_1.EntryType.RABBITMQ,
|
|
142
|
-
content: {
|
|
143
|
-
direction: 'incoming_rpc',
|
|
144
|
-
exchange,
|
|
145
|
-
routingKey,
|
|
146
|
-
queue,
|
|
147
|
-
message: self.sanitizeMessage(incomingMsg),
|
|
148
|
-
handler: `${target.constructor?.name || 'Unknown'}.${propertyKey}`,
|
|
149
|
-
timestamp: new Date().toISOString(),
|
|
150
|
-
},
|
|
151
|
-
}).catch(() => { });
|
|
152
|
-
try {
|
|
153
|
-
const result = await originalMethod.apply(this, args);
|
|
154
|
-
const duration = Date.now() - startTime;
|
|
155
|
-
self.telescope.record({
|
|
156
|
-
type: entry_type_enum_1.EntryType.RABBITMQ,
|
|
157
|
-
content: {
|
|
158
|
-
direction: 'incoming_rpc_response',
|
|
159
|
-
exchange,
|
|
160
|
-
routingKey,
|
|
161
|
-
queue,
|
|
162
|
-
handler: `${target.constructor?.name || 'Unknown'}.${propertyKey}`,
|
|
163
|
-
duration,
|
|
164
|
-
status: 'completed',
|
|
165
|
-
},
|
|
166
|
-
}).catch(() => { });
|
|
167
|
-
return result;
|
|
168
|
-
}
|
|
169
|
-
catch (err) {
|
|
170
|
-
const duration = Date.now() - startTime;
|
|
171
|
-
self.telescope.record({
|
|
172
|
-
type: entry_type_enum_1.EntryType.RABBITMQ,
|
|
173
|
-
content: {
|
|
174
|
-
direction: 'incoming_rpc_response',
|
|
175
|
-
exchange,
|
|
176
|
-
routingKey,
|
|
177
|
-
queue,
|
|
178
|
-
handler: `${target.constructor?.name || 'Unknown'}.${propertyKey}`,
|
|
179
|
-
duration,
|
|
180
|
-
status: 'failed',
|
|
181
|
-
error: err.message || String(err),
|
|
182
|
-
},
|
|
183
|
-
}).catch(() => { });
|
|
184
|
-
throw err;
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
return descriptor;
|
|
188
|
-
};
|
|
97
|
+
handlerMap.set(queue, wrappedOnMessage);
|
|
98
|
+
return originalConsume.call(this, queue, wrappedOnMessage, options);
|
|
99
|
+
};
|
|
100
|
+
// Also patch cancel to clean up
|
|
101
|
+
const originalCancel = Channel.prototype.cancel;
|
|
102
|
+
if (originalCancel) {
|
|
103
|
+
Channel.prototype.cancel = function (consumerTag) {
|
|
104
|
+
handlerMap.delete(consumerTag);
|
|
105
|
+
return originalCancel.call(this, consumerTag);
|
|
189
106
|
};
|
|
190
107
|
}
|
|
191
108
|
}
|