@ngn-net/nestjs-telescope 0.3.6 → 0.3.8
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,98 +22,98 @@ let RabbitMQWatcher = RabbitMQWatcher_1 = class RabbitMQWatcher {
|
|
|
22
22
|
}
|
|
23
23
|
onModuleInit() {
|
|
24
24
|
this.patchAmqpConnection();
|
|
25
|
+
this.patchAmqplibConnect();
|
|
25
26
|
}
|
|
26
27
|
patchAmqpConnection() {
|
|
27
28
|
try {
|
|
28
29
|
const { AmqpConnection } = require('@golevelup/nestjs-rabbitmq');
|
|
29
30
|
if (!AmqpConnection || !AmqpConnection.prototype)
|
|
30
31
|
return;
|
|
31
|
-
const self = this;
|
|
32
|
-
// Patch publish for outgoing messages
|
|
33
32
|
const originalPublish = AmqpConnection.prototype.publish;
|
|
34
|
-
if (originalPublish)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
exchange: options?.exchange || '',
|
|
73
|
-
routingKey: options?.routingKey || queue,
|
|
74
|
-
message: self.sanitizeMessage(parsed),
|
|
75
|
-
timestamp: new Date().toISOString(),
|
|
76
|
-
},
|
|
77
|
-
}).catch(() => { });
|
|
78
|
-
try {
|
|
79
|
-
const result = await handler(msg, ...rest);
|
|
80
|
-
const duration = Date.now() - startTime;
|
|
81
|
-
self.telescope.record({
|
|
82
|
-
type: entry_type_enum_1.EntryType.RABBITMQ,
|
|
83
|
-
content: {
|
|
84
|
-
direction: 'incoming_response',
|
|
85
|
-
queue,
|
|
86
|
-
exchange: options?.exchange || '',
|
|
87
|
-
routingKey: options?.routingKey || queue,
|
|
88
|
-
duration,
|
|
89
|
-
status: 'completed',
|
|
90
|
-
},
|
|
91
|
-
}).catch(() => { });
|
|
92
|
-
return result;
|
|
93
|
-
}
|
|
94
|
-
catch (err) {
|
|
95
|
-
const duration = Date.now() - startTime;
|
|
96
|
-
self.telescope.record({
|
|
97
|
-
type: entry_type_enum_1.EntryType.RABBITMQ,
|
|
98
|
-
content: {
|
|
99
|
-
direction: 'incoming_response',
|
|
100
|
-
queue,
|
|
101
|
-
exchange: options?.exchange || '',
|
|
102
|
-
routingKey: options?.routingKey || queue,
|
|
103
|
-
duration,
|
|
104
|
-
status: 'failed',
|
|
105
|
-
error: err.message || String(err),
|
|
106
|
-
},
|
|
107
|
-
}).catch(() => { });
|
|
108
|
-
throw err;
|
|
33
|
+
if (!originalPublish)
|
|
34
|
+
return;
|
|
35
|
+
const self = this;
|
|
36
|
+
AmqpConnection.prototype.publish = async function (exchange, routingKey, msg, ...args) {
|
|
37
|
+
const startTime = Date.now();
|
|
38
|
+
const result = await originalPublish.call(this, exchange, routingKey, msg, ...args);
|
|
39
|
+
const duration = Date.now() - startTime;
|
|
40
|
+
self.telescope.record({
|
|
41
|
+
type: entry_type_enum_1.EntryType.RABBITMQ,
|
|
42
|
+
content: {
|
|
43
|
+
direction: 'outgoing',
|
|
44
|
+
exchange,
|
|
45
|
+
routingKey,
|
|
46
|
+
message: self.sanitizeMessage(msg),
|
|
47
|
+
duration,
|
|
48
|
+
status: 'sent',
|
|
49
|
+
},
|
|
50
|
+
}).catch(() => { });
|
|
51
|
+
return result;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
catch { }
|
|
55
|
+
}
|
|
56
|
+
patchAmqplibConnect() {
|
|
57
|
+
try {
|
|
58
|
+
const amqplib = require('amqplib');
|
|
59
|
+
if (!amqplib || typeof amqplib.connect !== 'function')
|
|
60
|
+
return;
|
|
61
|
+
const originalConnect = amqplib.connect;
|
|
62
|
+
const self = this;
|
|
63
|
+
amqplib.connect = async function (...args) {
|
|
64
|
+
const conn = await originalConnect.apply(this, args);
|
|
65
|
+
if (conn && typeof conn.createChannel === 'function') {
|
|
66
|
+
const originalCreateChannel = conn.createChannel.bind(conn);
|
|
67
|
+
conn.createChannel = async function (...channelArgs) {
|
|
68
|
+
const channel = await originalCreateChannel(...channelArgs);
|
|
69
|
+
if (channel && typeof channel.consume === 'function') {
|
|
70
|
+
self.instrumentChannel(channel);
|
|
109
71
|
}
|
|
72
|
+
return channel;
|
|
110
73
|
};
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
74
|
+
}
|
|
75
|
+
return conn;
|
|
76
|
+
};
|
|
114
77
|
}
|
|
115
78
|
catch { }
|
|
116
79
|
}
|
|
80
|
+
instrumentChannel(channel) {
|
|
81
|
+
const self = this;
|
|
82
|
+
if (channel.__telescopePatched)
|
|
83
|
+
return;
|
|
84
|
+
channel.__telescopePatched = true;
|
|
85
|
+
const originalConsume = channel.consume;
|
|
86
|
+
if (!originalConsume)
|
|
87
|
+
return;
|
|
88
|
+
channel.consume = function (queue, onMessage, options) {
|
|
89
|
+
const wrappedOnMessage = (msg) => {
|
|
90
|
+
if (!msg || !msg.content)
|
|
91
|
+
return onMessage(msg);
|
|
92
|
+
const startTime = Date.now();
|
|
93
|
+
let parsed;
|
|
94
|
+
try {
|
|
95
|
+
parsed = JSON.parse(msg.content.toString());
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
parsed = msg.content.toString();
|
|
99
|
+
}
|
|
100
|
+
self.telescope.record({
|
|
101
|
+
type: entry_type_enum_1.EntryType.RABBITMQ,
|
|
102
|
+
content: {
|
|
103
|
+
direction: 'incoming',
|
|
104
|
+
queue,
|
|
105
|
+
exchange: msg.fields?.exchange || '',
|
|
106
|
+
routingKey: msg.fields?.routingKey || queue,
|
|
107
|
+
message: self.sanitizeMessage(parsed),
|
|
108
|
+
deliveryTag: msg.fields?.deliveryTag,
|
|
109
|
+
timestamp: new Date().toISOString(),
|
|
110
|
+
},
|
|
111
|
+
}).catch(() => { });
|
|
112
|
+
return onMessage(msg);
|
|
113
|
+
};
|
|
114
|
+
return originalConsume.call(this, queue, wrappedOnMessage, options);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
117
|
sanitizeMessage(msg) {
|
|
118
118
|
if (!msg)
|
|
119
119
|
return null;
|