@ngn-net/nestjs-telescope 0.3.10 → 0.3.12
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
|
@@ -14,49 +14,46 @@ exports.RabbitMQWatcher = void 0;
|
|
|
14
14
|
const common_1 = require("@nestjs/common");
|
|
15
15
|
const telescope_service_1 = require("../telescope.service");
|
|
16
16
|
const entry_type_enum_1 = require("../enums/entry-type.enum");
|
|
17
|
-
// Patch amqplib.connect at file load time (before any NestJS module initializes)
|
|
18
|
-
// This ensures we intercept channels BEFORE @golevelup/nestjs-rabbitmq creates them
|
|
19
17
|
let telescopeRef = null;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const conn = await originalConnect.apply(this, args);
|
|
31
|
-
if (conn && typeof conn.createChannel === 'function') {
|
|
32
|
-
const originalCreateChannel = conn.createChannel.bind(conn);
|
|
33
|
-
conn.createChannel = async function (...channelArgs) {
|
|
34
|
-
const channel = await originalCreateChannel(...channelArgs);
|
|
35
|
-
if (channel && typeof channel.consume === 'function') {
|
|
36
|
-
instrumentChannel(channel);
|
|
37
|
-
}
|
|
38
|
-
return channel;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
return conn;
|
|
42
|
-
};
|
|
43
|
-
amqplibPatched = true;
|
|
18
|
+
function sanitizeMessage(msg) {
|
|
19
|
+
if (!msg)
|
|
20
|
+
return null;
|
|
21
|
+
if (typeof msg === 'string') {
|
|
22
|
+
try {
|
|
23
|
+
return sanitizeMessage(JSON.parse(msg));
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return msg.length > 1000 ? msg.substring(0, 1000) + '...[truncated]' : msg;
|
|
27
|
+
}
|
|
44
28
|
}
|
|
45
|
-
|
|
29
|
+
if (Buffer.isBuffer(msg))
|
|
30
|
+
return '[Buffer]';
|
|
31
|
+
if (typeof msg === 'object') {
|
|
32
|
+
const sanitized = {};
|
|
33
|
+
for (const [key, value] of Object.entries(msg)) {
|
|
34
|
+
if (/password|secret|token/i.test(key))
|
|
35
|
+
sanitized[key] = '[REDACTED]';
|
|
36
|
+
else if (typeof value === 'string' && value.length > 500)
|
|
37
|
+
sanitized[key] = value.substring(0, 500) + '...[truncated]';
|
|
38
|
+
else
|
|
39
|
+
sanitized[key] = value;
|
|
40
|
+
}
|
|
41
|
+
return sanitized;
|
|
42
|
+
}
|
|
43
|
+
return msg;
|
|
46
44
|
}
|
|
47
45
|
function instrumentChannel(channel) {
|
|
46
|
+
if (!channel || typeof channel.consume !== 'function')
|
|
47
|
+
return;
|
|
48
48
|
if (channel.__telescopePatched)
|
|
49
49
|
return;
|
|
50
50
|
channel.__telescopePatched = true;
|
|
51
51
|
const originalConsume = channel.consume;
|
|
52
|
-
if (!originalConsume)
|
|
53
|
-
return;
|
|
54
52
|
channel.consume = function (queue, onMessage, options) {
|
|
55
53
|
const wrappedOnMessage = (msg) => {
|
|
56
54
|
if (!msg || !msg.content)
|
|
57
55
|
return onMessage(msg);
|
|
58
56
|
if (telescopeRef) {
|
|
59
|
-
const startTime = Date.now();
|
|
60
57
|
let parsed;
|
|
61
58
|
try {
|
|
62
59
|
parsed = JSON.parse(msg.content.toString());
|
|
@@ -82,39 +79,26 @@ function instrumentChannel(channel) {
|
|
|
82
79
|
return originalConsume.call(this, queue, wrappedOnMessage, options);
|
|
83
80
|
};
|
|
84
81
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
82
|
+
// Patch at file load time — wrap the channel getter on AmqpConnection.prototype
|
|
83
|
+
try {
|
|
84
|
+
const { AmqpConnection } = require('@golevelup/nestjs-rabbitmq');
|
|
85
|
+
if (AmqpConnection && AmqpConnection.prototype) {
|
|
86
|
+
const desc = Object.getOwnPropertyDescriptor(AmqpConnection.prototype, 'channel');
|
|
87
|
+
if (desc && desc.get) {
|
|
88
|
+
const originalGetter = desc.get;
|
|
89
|
+
Object.defineProperty(AmqpConnection.prototype, 'channel', {
|
|
90
|
+
get: function () {
|
|
91
|
+
const ch = originalGetter.call(this);
|
|
92
|
+
instrumentChannel(ch);
|
|
93
|
+
return ch;
|
|
94
|
+
},
|
|
95
|
+
configurable: true,
|
|
96
|
+
enumerable: true,
|
|
97
|
+
});
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
|
-
if (Buffer.isBuffer(msg))
|
|
98
|
-
return '[Buffer]';
|
|
99
|
-
if (typeof msg === 'object') {
|
|
100
|
-
const sanitized = {};
|
|
101
|
-
for (const [key, value] of Object.entries(msg)) {
|
|
102
|
-
if (key.toLowerCase().includes('password') || key.toLowerCase().includes('secret') || key.toLowerCase().includes('token')) {
|
|
103
|
-
sanitized[key] = '[REDACTED]';
|
|
104
|
-
}
|
|
105
|
-
else if (typeof value === 'string' && value.length > 500) {
|
|
106
|
-
sanitized[key] = value.substring(0, 500) + '...[truncated]';
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
sanitized[key] = value;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return sanitized;
|
|
113
|
-
}
|
|
114
|
-
return msg;
|
|
115
100
|
}
|
|
116
|
-
|
|
117
|
-
patchAmqplibEarly();
|
|
101
|
+
catch { }
|
|
118
102
|
let RabbitMQWatcher = RabbitMQWatcher_1 = class RabbitMQWatcher {
|
|
119
103
|
telescope;
|
|
120
104
|
logger = new common_1.Logger(RabbitMQWatcher_1.name);
|