@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.
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ngn-net/nestjs-telescope",
3
- "version": "0.3.5",
4
- "builtAt": "2026-06-13T10:45:28.758Z"
3
+ "version": "0.3.7",
4
+ "builtAt": "2026-06-13T11:07:43.039Z"
5
5
  }
@@ -6,6 +6,6 @@ export declare class RabbitMQWatcher implements OnModuleInit {
6
6
  constructor(telescope: TelescopeService);
7
7
  onModuleInit(): void;
8
8
  private patchAmqpConnection;
9
- private patchRabbitSubscribe;
9
+ private patchAmqplibChannel;
10
10
  private sanitizeMessage;
11
11
  }
@@ -22,7 +22,7 @@ let RabbitMQWatcher = RabbitMQWatcher_1 = class RabbitMQWatcher {
22
22
  }
23
23
  onModuleInit() {
24
24
  this.patchAmqpConnection();
25
- this.patchRabbitSubscribe();
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: sanitizedMsg,
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
- patchRabbitSubscribe() {
56
+ patchAmqplibChannel() {
58
57
  try {
59
- const rabbitmq = require('@golevelup/nestjs-rabbitmq');
60
- if (!rabbitmq)
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 RabbitSubscribeHandler = rabbitmq.RabbitSubscribe;
64
- if (RabbitSubscribeHandler) {
65
- const originalHandler = RabbitSubscribeHandler;
66
- rabbitmq.RabbitSubscribe = function (options) {
67
- const decorator = originalHandler(options);
68
- return function (target, propertyKey, descriptor) {
69
- const originalMethod = descriptor.value;
70
- const exchange = options?.exchange || '';
71
- const routingKey = options?.routingKey || '';
72
- const queue = options?.queue || '';
73
- descriptor.value = async function (...args) {
74
- const startTime = Date.now();
75
- const incomingMsg = args[0];
76
- self.telescope.record({
77
- type: entry_type_enum_1.EntryType.RABBITMQ,
78
- content: {
79
- direction: 'incoming',
80
- exchange,
81
- routingKey,
82
- queue,
83
- message: self.sanitizeMessage(incomingMsg),
84
- handler: `${target.constructor?.name || 'Unknown'}.${propertyKey}`,
85
- timestamp: new Date().toISOString(),
86
- },
87
- }).catch(() => { });
88
- try {
89
- const result = await originalMethod.apply(this, args);
90
- const duration = Date.now() - startTime;
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
- const RabbitRPCHandler = rabbitmq.RabbitRPC;
128
- if (RabbitRPCHandler) {
129
- const originalRPCHandler = RabbitRPCHandler;
130
- rabbitmq.RabbitRPC = function (options) {
131
- const decorator = originalRPCHandler(options);
132
- return function (target, propertyKey, descriptor) {
133
- const originalMethod = descriptor.value;
134
- const exchange = options?.exchange || '';
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngn-net/nestjs-telescope",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },