@ngn-net/nestjs-telescope 0.3.11 → 0.3.13
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,78 +42,62 @@ function sanitizeMessage(msg) {
|
|
|
42
42
|
}
|
|
43
43
|
return msg;
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
if (channel.__telescopePatched)
|
|
47
|
-
return;
|
|
48
|
-
channel.__telescopePatched = true;
|
|
49
|
-
const originalConsume = channel.consume;
|
|
50
|
-
if (!originalConsume)
|
|
51
|
-
return;
|
|
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 — intercept AmqpConnection.createChannel
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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(() => { });
|
|
104
68
|
}
|
|
105
69
|
return result;
|
|
106
70
|
};
|
|
107
71
|
}
|
|
108
|
-
// Patch
|
|
109
|
-
const
|
|
110
|
-
if (
|
|
111
|
-
AmqpConnection.prototype.
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
72
|
+
// Patch subscribe for incoming
|
|
73
|
+
const originalSubscribe = AmqpConnection.prototype.subscribe;
|
|
74
|
+
if (originalSubscribe) {
|
|
75
|
+
AmqpConnection.prototype.subscribe = async function (queue, handler, options) {
|
|
76
|
+
const wrappedHandler = (msg) => {
|
|
77
|
+
if (msg && msg.content && telescopeRef) {
|
|
78
|
+
let parsed;
|
|
79
|
+
try {
|
|
80
|
+
parsed = JSON.parse(msg.content.toString());
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
parsed = msg.content.toString();
|
|
84
|
+
}
|
|
85
|
+
telescopeRef.record({
|
|
86
|
+
type: entry_type_enum_1.EntryType.RABBITMQ,
|
|
87
|
+
content: {
|
|
88
|
+
direction: 'incoming',
|
|
89
|
+
queue,
|
|
90
|
+
exchange: msg.fields?.exchange || '',
|
|
91
|
+
routingKey: msg.fields?.routingKey || queue,
|
|
92
|
+
message: sanitizeMessage(parsed),
|
|
93
|
+
deliveryTag: msg.fields?.deliveryTag,
|
|
94
|
+
timestamp: new Date().toISOString(),
|
|
95
|
+
},
|
|
96
|
+
}).catch(() => { });
|
|
97
|
+
}
|
|
98
|
+
return handler(msg);
|
|
99
|
+
};
|
|
100
|
+
return originalSubscribe.call(this, queue, wrappedHandler, options);
|
|
117
101
|
};
|
|
118
102
|
}
|
|
119
103
|
}
|
|
@@ -127,55 +111,8 @@ let RabbitMQWatcher = RabbitMQWatcher_1 = class RabbitMQWatcher {
|
|
|
127
111
|
}
|
|
128
112
|
onModuleInit() {
|
|
129
113
|
telescopeRef = this.telescope;
|
|
130
|
-
this.patchAmqpConnectionPublish();
|
|
131
|
-
this.patchExistingChannels();
|
|
132
114
|
this.logger.log('RabbitMQWatcher initialized — incoming & outgoing messages will be recorded');
|
|
133
115
|
}
|
|
134
|
-
patchExistingChannels() {
|
|
135
|
-
try {
|
|
136
|
-
const { AmqpConnection } = require('@golevelup/nestjs-rabbitmq');
|
|
137
|
-
if (!AmqpConnection)
|
|
138
|
-
return;
|
|
139
|
-
// Try to get the instance from the global scope
|
|
140
|
-
// @golevelup/nestjs-rabbitmq stores it as a module provider
|
|
141
|
-
const instances = AmqpConnection.__instances || [];
|
|
142
|
-
for (const inst of instances) {
|
|
143
|
-
if (inst?.channel && typeof inst.channel.consume === 'function') {
|
|
144
|
-
instrumentChannel(inst.channel);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
catch { }
|
|
149
|
-
}
|
|
150
|
-
patchAmqpConnectionPublish() {
|
|
151
|
-
try {
|
|
152
|
-
const { AmqpConnection } = require('@golevelup/nestjs-rabbitmq');
|
|
153
|
-
if (!AmqpConnection || !AmqpConnection.prototype)
|
|
154
|
-
return;
|
|
155
|
-
const originalPublish = AmqpConnection.prototype.publish;
|
|
156
|
-
if (!originalPublish)
|
|
157
|
-
return;
|
|
158
|
-
const self = this;
|
|
159
|
-
AmqpConnection.prototype.publish = async function (exchange, routingKey, msg, ...args) {
|
|
160
|
-
const startTime = Date.now();
|
|
161
|
-
const result = await originalPublish.call(this, exchange, routingKey, msg, ...args);
|
|
162
|
-
const duration = Date.now() - startTime;
|
|
163
|
-
self.telescope.record({
|
|
164
|
-
type: entry_type_enum_1.EntryType.RABBITMQ,
|
|
165
|
-
content: {
|
|
166
|
-
direction: 'outgoing',
|
|
167
|
-
exchange,
|
|
168
|
-
routingKey,
|
|
169
|
-
message: sanitizeMessage(msg),
|
|
170
|
-
duration,
|
|
171
|
-
status: 'sent',
|
|
172
|
-
},
|
|
173
|
-
}).catch(() => { });
|
|
174
|
-
return result;
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
catch { }
|
|
178
|
-
}
|
|
179
116
|
};
|
|
180
117
|
exports.RabbitMQWatcher = RabbitMQWatcher;
|
|
181
118
|
exports.RabbitMQWatcher = RabbitMQWatcher = RabbitMQWatcher_1 = __decorate([
|