@ngn-net/nestjs-telescope 0.3.5 → 0.3.6

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.6",
4
+ "builtAt": "2026-06-13T10:59:23.325Z"
5
5
  }
@@ -6,6 +6,5 @@ export declare class RabbitMQWatcher implements OnModuleInit {
6
6
  constructor(telescope: TelescopeService);
7
7
  onModuleInit(): void;
8
8
  private patchAmqpConnection;
9
- private patchRabbitSubscribe;
10
9
  private sanitizeMessage;
11
10
  }
@@ -22,170 +22,93 @@ let RabbitMQWatcher = RabbitMQWatcher_1 = class RabbitMQWatcher {
22
22
  }
23
23
  onModuleInit() {
24
24
  this.patchAmqpConnection();
25
- this.patchRabbitSubscribe();
26
25
  }
27
26
  patchAmqpConnection() {
28
27
  try {
29
28
  const { AmqpConnection } = require('@golevelup/nestjs-rabbitmq');
30
29
  if (!AmqpConnection || !AmqpConnection.prototype)
31
30
  return;
32
- const originalPublish = AmqpConnection.prototype.publish;
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
- const sanitizedMsg = self.sanitizeMessage(msg);
41
- self.telescope.record({
42
- type: entry_type_enum_1.EntryType.RABBITMQ,
43
- content: {
44
- direction: 'outgoing',
45
- exchange,
46
- routingKey,
47
- message: sanitizedMsg,
48
- duration,
49
- status: 'sent',
50
- },
51
- }).catch(() => { });
52
- return result;
53
- };
54
- }
55
- catch { }
56
- }
57
- patchRabbitSubscribe() {
58
- try {
59
- const rabbitmq = require('@golevelup/nestjs-rabbitmq');
60
- if (!rabbitmq)
61
- return;
62
31
  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];
32
+ // Patch publish for outgoing messages
33
+ const originalPublish = AmqpConnection.prototype.publish;
34
+ if (originalPublish) {
35
+ AmqpConnection.prototype.publish = async function (exchange, routingKey, msg, ...args) {
36
+ const startTime = Date.now();
37
+ const result = await originalPublish.call(this, exchange, routingKey, msg, ...args);
38
+ const duration = Date.now() - startTime;
39
+ self.telescope.record({
40
+ type: entry_type_enum_1.EntryType.RABBITMQ,
41
+ content: {
42
+ direction: 'outgoing',
43
+ exchange,
44
+ routingKey,
45
+ message: self.sanitizeMessage(msg),
46
+ duration,
47
+ status: 'sent',
48
+ },
49
+ }).catch(() => { });
50
+ return result;
51
+ };
52
+ }
53
+ // Patch consume for incoming messages
54
+ const originalConsume = AmqpConnection.prototype.consume;
55
+ if (originalConsume) {
56
+ AmqpConnection.prototype.consume = async function (queue, handler, options) {
57
+ const wrappedHandler = async (msg, ...rest) => {
58
+ const startTime = Date.now();
59
+ const content = msg?.content ? msg.content.toString() : msg;
60
+ let parsed;
61
+ try {
62
+ parsed = JSON.parse(content);
63
+ }
64
+ catch {
65
+ parsed = content;
66
+ }
67
+ self.telescope.record({
68
+ type: entry_type_enum_1.EntryType.RABBITMQ,
69
+ content: {
70
+ direction: 'incoming',
71
+ queue,
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;
76
81
  self.telescope.record({
77
82
  type: entry_type_enum_1.EntryType.RABBITMQ,
78
83
  content: {
79
- direction: 'incoming',
80
- exchange,
81
- routingKey,
84
+ direction: 'incoming_response',
82
85
  queue,
83
- message: self.sanitizeMessage(incomingMsg),
84
- handler: `${target.constructor?.name || 'Unknown'}.${propertyKey}`,
85
- timestamp: new Date().toISOString(),
86
+ exchange: options?.exchange || '',
87
+ routingKey: options?.routingKey || queue,
88
+ duration,
89
+ status: 'completed',
86
90
  },
87
91
  }).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
- };
125
- };
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];
92
+ return result;
93
+ }
94
+ catch (err) {
95
+ const duration = Date.now() - startTime;
140
96
  self.telescope.record({
141
97
  type: entry_type_enum_1.EntryType.RABBITMQ,
142
98
  content: {
143
- direction: 'incoming_rpc',
144
- exchange,
145
- routingKey,
99
+ direction: 'incoming_response',
146
100
  queue,
147
- message: self.sanitizeMessage(incomingMsg),
148
- handler: `${target.constructor?.name || 'Unknown'}.${propertyKey}`,
149
- timestamp: new Date().toISOString(),
101
+ exchange: options?.exchange || '',
102
+ routingKey: options?.routingKey || queue,
103
+ duration,
104
+ status: 'failed',
105
+ error: err.message || String(err),
150
106
  },
151
107
  }).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;
108
+ throw err;
109
+ }
188
110
  };
111
+ return originalConsume.call(this, queue, wrappedHandler, options);
189
112
  };
190
113
  }
191
114
  }
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.6",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },