@ngn-net/nestjs-telescope 0.3.12 → 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.
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ngn-net/nestjs-telescope",
3
- "version": "0.3.12",
4
- "builtAt": "2026-06-13T11:22:47.918Z"
3
+ "version": "0.3.13",
4
+ "builtAt": "2026-06-13T11:26:28.718Z"
5
5
  }
@@ -5,5 +5,4 @@ export declare class RabbitMQWatcher implements OnModuleInit {
5
5
  private readonly logger;
6
6
  constructor(telescope: TelescopeService);
7
7
  onModuleInit(): void;
8
- private patchAmqpConnectionPublish;
9
8
  }
@@ -42,59 +42,63 @@ function sanitizeMessage(msg) {
42
42
  }
43
43
  return msg;
44
44
  }
45
- function instrumentChannel(channel) {
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
- 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
- });
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 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);
101
+ };
98
102
  }
99
103
  }
100
104
  }
@@ -107,38 +111,8 @@ let RabbitMQWatcher = RabbitMQWatcher_1 = class RabbitMQWatcher {
107
111
  }
108
112
  onModuleInit() {
109
113
  telescopeRef = this.telescope;
110
- this.patchAmqpConnectionPublish();
111
114
  this.logger.log('RabbitMQWatcher initialized — incoming & outgoing messages will be recorded');
112
115
  }
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
116
  };
143
117
  exports.RabbitMQWatcher = RabbitMQWatcher;
144
118
  exports.RabbitMQWatcher = RabbitMQWatcher = RabbitMQWatcher_1 = __decorate([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngn-net/nestjs-telescope",
3
- "version": "0.3.12",
3
+ "version": "0.3.13",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },