@ngn-net/nestjs-telescope 0.3.12 → 0.3.14
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
|
@@ -42,59 +42,100 @@ function sanitizeMessage(msg) {
|
|
|
42
42
|
}
|
|
43
43
|
return msg;
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
if (!channel || typeof channel.consume !== 'function')
|
|
47
|
-
return;
|
|
48
|
-
if (channel.__telescopePatched)
|
|
49
|
-
return;
|
|
50
|
-
channel.__telescopePatched = true;
|
|
51
|
-
const originalConsume = channel.consume;
|
|
52
|
-
channel.consume = function (queue, onMessage, options) {
|
|
53
|
-
const wrappedOnMessage = (msg) => {
|
|
54
|
-
if (!msg || !msg.content)
|
|
55
|
-
return onMessage(msg);
|
|
56
|
-
if (telescopeRef) {
|
|
57
|
-
let parsed;
|
|
58
|
-
try {
|
|
59
|
-
parsed = JSON.parse(msg.content.toString());
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
62
|
-
parsed = msg.content.toString();
|
|
63
|
-
}
|
|
64
|
-
telescopeRef.record({
|
|
65
|
-
type: entry_type_enum_1.EntryType.RABBITMQ,
|
|
66
|
-
content: {
|
|
67
|
-
direction: 'incoming',
|
|
68
|
-
queue,
|
|
69
|
-
exchange: msg.fields?.exchange || '',
|
|
70
|
-
routingKey: msg.fields?.routingKey || queue,
|
|
71
|
-
message: sanitizeMessage(parsed),
|
|
72
|
-
deliveryTag: msg.fields?.deliveryTag,
|
|
73
|
-
timestamp: new Date().toISOString(),
|
|
74
|
-
},
|
|
75
|
-
}).catch(() => { });
|
|
76
|
-
}
|
|
77
|
-
return onMessage(msg);
|
|
78
|
-
};
|
|
79
|
-
return originalConsume.call(this, queue, wrappedOnMessage, options);
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
// Patch at file load time — wrap the channel getter on AmqpConnection.prototype
|
|
45
|
+
// Patch at file load time
|
|
83
46
|
try {
|
|
84
47
|
const { AmqpConnection } = require('@golevelup/nestjs-rabbitmq');
|
|
85
48
|
if (AmqpConnection && AmqpConnection.prototype) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
49
|
+
// Patch publish for outgoing
|
|
50
|
+
const originalPublish = AmqpConnection.prototype.publish;
|
|
51
|
+
if (originalPublish) {
|
|
52
|
+
AmqpConnection.prototype.publish = async function (exchange, routingKey, msg, ...args) {
|
|
53
|
+
const startTime = Date.now();
|
|
54
|
+
const result = await originalPublish.call(this, exchange, routingKey, msg, ...args);
|
|
55
|
+
const duration = Date.now() - startTime;
|
|
56
|
+
if (telescopeRef) {
|
|
57
|
+
telescopeRef.record({
|
|
58
|
+
type: entry_type_enum_1.EntryType.RABBITMQ,
|
|
59
|
+
content: {
|
|
60
|
+
direction: 'outgoing',
|
|
61
|
+
exchange,
|
|
62
|
+
routingKey,
|
|
63
|
+
message: sanitizeMessage(msg),
|
|
64
|
+
duration,
|
|
65
|
+
status: 'sent',
|
|
66
|
+
},
|
|
67
|
+
}).catch(() => { });
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
// Patch setupSubscriberChannel for incoming (subscribe handlers)
|
|
73
|
+
const origSetupSubscriber = AmqpConnection.prototype.setupSubscriberChannel;
|
|
74
|
+
if (origSetupSubscriber) {
|
|
75
|
+
AmqpConnection.prototype.setupSubscriberChannel = async function (handler, msgOptions, channel, originalHandlerName) {
|
|
76
|
+
const queue = msgOptions?.queue || '';
|
|
77
|
+
const exchange = msgOptions?.exchange || '';
|
|
78
|
+
const routingKey = msgOptions?.routingKey || '';
|
|
79
|
+
const wrappedHandler = async (msg, rawMsg, headers) => {
|
|
80
|
+
if (rawMsg && rawMsg.content && telescopeRef) {
|
|
81
|
+
let parsed;
|
|
82
|
+
try {
|
|
83
|
+
parsed = JSON.parse(rawMsg.content.toString());
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
parsed = rawMsg.content.toString();
|
|
87
|
+
}
|
|
88
|
+
telescopeRef.record({
|
|
89
|
+
type: entry_type_enum_1.EntryType.RABBITMQ,
|
|
90
|
+
content: {
|
|
91
|
+
direction: 'incoming',
|
|
92
|
+
queue,
|
|
93
|
+
exchange: rawMsg.fields?.exchange || exchange,
|
|
94
|
+
routingKey: rawMsg.fields?.routingKey || routingKey,
|
|
95
|
+
message: sanitizeMessage(parsed),
|
|
96
|
+
deliveryTag: rawMsg.fields?.deliveryTag,
|
|
97
|
+
handler: originalHandlerName,
|
|
98
|
+
timestamp: new Date().toISOString(),
|
|
99
|
+
},
|
|
100
|
+
}).catch(() => { });
|
|
101
|
+
}
|
|
102
|
+
return handler(msg, rawMsg, headers);
|
|
103
|
+
};
|
|
104
|
+
return origSetupSubscriber.call(this, wrappedHandler, msgOptions, channel, originalHandlerName);
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
// Patch setupBatchSubscriberChannel for incoming (batch subscribe handlers)
|
|
108
|
+
const origSetupBatch = AmqpConnection.prototype.setupBatchSubscriberChannel;
|
|
109
|
+
if (origSetupBatch) {
|
|
110
|
+
AmqpConnection.prototype.setupBatchSubscriberChannel = async function (handler, msgOptions, channel) {
|
|
111
|
+
const queue = msgOptions?.queue || '';
|
|
112
|
+
const wrappedHandler = async (msgs, rawMsgs, headers) => {
|
|
113
|
+
if (telescopeRef && rawMsgs && rawMsgs.length > 0) {
|
|
114
|
+
const firstMsg = rawMsgs[0];
|
|
115
|
+
let parsed;
|
|
116
|
+
try {
|
|
117
|
+
parsed = JSON.parse(firstMsg.content.toString());
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
parsed = firstMsg.content.toString();
|
|
121
|
+
}
|
|
122
|
+
telescopeRef.record({
|
|
123
|
+
type: entry_type_enum_1.EntryType.RABBITMQ,
|
|
124
|
+
content: {
|
|
125
|
+
direction: 'incoming',
|
|
126
|
+
queue,
|
|
127
|
+
exchange: firstMsg.fields?.exchange || '',
|
|
128
|
+
routingKey: firstMsg.fields?.routingKey || queue,
|
|
129
|
+
message: sanitizeMessage(parsed),
|
|
130
|
+
batchSize: msgs.length,
|
|
131
|
+
timestamp: new Date().toISOString(),
|
|
132
|
+
},
|
|
133
|
+
}).catch(() => { });
|
|
134
|
+
}
|
|
135
|
+
return handler(msgs, rawMsgs, headers);
|
|
136
|
+
};
|
|
137
|
+
return origSetupBatch.call(this, wrappedHandler, msgOptions, channel);
|
|
138
|
+
};
|
|
98
139
|
}
|
|
99
140
|
}
|
|
100
141
|
}
|
|
@@ -107,38 +148,8 @@ let RabbitMQWatcher = RabbitMQWatcher_1 = class RabbitMQWatcher {
|
|
|
107
148
|
}
|
|
108
149
|
onModuleInit() {
|
|
109
150
|
telescopeRef = this.telescope;
|
|
110
|
-
this.patchAmqpConnectionPublish();
|
|
111
151
|
this.logger.log('RabbitMQWatcher initialized — incoming & outgoing messages will be recorded');
|
|
112
152
|
}
|
|
113
|
-
patchAmqpConnectionPublish() {
|
|
114
|
-
try {
|
|
115
|
-
const { AmqpConnection } = require('@golevelup/nestjs-rabbitmq');
|
|
116
|
-
if (!AmqpConnection || !AmqpConnection.prototype)
|
|
117
|
-
return;
|
|
118
|
-
const originalPublish = AmqpConnection.prototype.publish;
|
|
119
|
-
if (!originalPublish)
|
|
120
|
-
return;
|
|
121
|
-
const self = this;
|
|
122
|
-
AmqpConnection.prototype.publish = async function (exchange, routingKey, msg, ...args) {
|
|
123
|
-
const startTime = Date.now();
|
|
124
|
-
const result = await originalPublish.call(this, exchange, routingKey, msg, ...args);
|
|
125
|
-
const duration = Date.now() - startTime;
|
|
126
|
-
self.telescope.record({
|
|
127
|
-
type: entry_type_enum_1.EntryType.RABBITMQ,
|
|
128
|
-
content: {
|
|
129
|
-
direction: 'outgoing',
|
|
130
|
-
exchange,
|
|
131
|
-
routingKey,
|
|
132
|
-
message: sanitizeMessage(msg),
|
|
133
|
-
duration,
|
|
134
|
-
status: 'sent',
|
|
135
|
-
},
|
|
136
|
-
}).catch(() => { });
|
|
137
|
-
return result;
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
catch { }
|
|
141
|
-
}
|
|
142
153
|
};
|
|
143
154
|
exports.RabbitMQWatcher = RabbitMQWatcher;
|
|
144
155
|
exports.RabbitMQWatcher = RabbitMQWatcher = RabbitMQWatcher_1 = __decorate([
|