@ngn-net/nestjs-telescope 0.3.11 → 0.3.12

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.11",
4
- "builtAt": "2026-06-13T11:21:01.736Z"
3
+ "version": "0.3.12",
4
+ "builtAt": "2026-06-13T11:22:47.918Z"
5
5
  }
@@ -5,6 +5,5 @@ export declare class RabbitMQWatcher implements OnModuleInit {
5
5
  private readonly logger;
6
6
  constructor(telescope: TelescopeService);
7
7
  onModuleInit(): void;
8
- private patchExistingChannels;
9
8
  private patchAmqpConnectionPublish;
10
9
  }
@@ -43,12 +43,12 @@ function sanitizeMessage(msg) {
43
43
  return msg;
44
44
  }
45
45
  function instrumentChannel(channel) {
46
+ if (!channel || typeof channel.consume !== 'function')
47
+ return;
46
48
  if (channel.__telescopePatched)
47
49
  return;
48
50
  channel.__telescopePatched = true;
49
51
  const originalConsume = channel.consume;
50
- if (!originalConsume)
51
- return;
52
52
  channel.consume = function (queue, onMessage, options) {
53
53
  const wrappedOnMessage = (msg) => {
54
54
  if (!msg || !msg.content)
@@ -79,42 +79,22 @@ function instrumentChannel(channel) {
79
79
  return originalConsume.call(this, queue, wrappedOnMessage, options);
80
80
  };
81
81
  }
82
- // Patch at file load time — intercept AmqpConnection.createChannel
82
+ // Patch at file load time — wrap the channel getter on AmqpConnection.prototype
83
83
  try {
84
84
  const { AmqpConnection } = require('@golevelup/nestjs-rabbitmq');
85
85
  if (AmqpConnection && AmqpConnection.prototype) {
86
- const origCreateChannel = AmqpConnection.prototype.createChannel;
87
- if (origCreateChannel) {
88
- AmqpConnection.prototype.createChannel = async function (...args) {
89
- const channel = await origCreateChannel.apply(this, args);
90
- if (channel && typeof channel.consume === 'function') {
91
- instrumentChannel(channel);
92
- }
93
- return channel;
94
- };
95
- }
96
- // Also patch the internal init method that creates channels
97
- const origInit = AmqpConnection.prototype.init;
98
- if (origInit) {
99
- AmqpConnection.prototype.init = async function (...args) {
100
- const result = await origInit.apply(this, args);
101
- // After init, patch any existing channel
102
- if (this.channel && typeof this.channel.consume === 'function') {
103
- instrumentChannel(this.channel);
104
- }
105
- return result;
106
- };
107
- }
108
- // Patch the 'managedConnection' setter to catch channel creation
109
- const origConnect = AmqpConnection.prototype.connect;
110
- if (origConnect) {
111
- AmqpConnection.prototype.connect = async function (...args) {
112
- const result = await origConnect.apply(this, args);
113
- if (this.channel && typeof this.channel.consume === 'function') {
114
- instrumentChannel(this.channel);
115
- }
116
- return result;
117
- };
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
+ });
118
98
  }
119
99
  }
120
100
  }
@@ -128,25 +108,8 @@ let RabbitMQWatcher = RabbitMQWatcher_1 = class RabbitMQWatcher {
128
108
  onModuleInit() {
129
109
  telescopeRef = this.telescope;
130
110
  this.patchAmqpConnectionPublish();
131
- this.patchExistingChannels();
132
111
  this.logger.log('RabbitMQWatcher initialized — incoming & outgoing messages will be recorded');
133
112
  }
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
113
  patchAmqpConnectionPublish() {
151
114
  try {
152
115
  const { AmqpConnection } = require('@golevelup/nestjs-rabbitmq');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngn-net/nestjs-telescope",
3
- "version": "0.3.11",
3
+ "version": "0.3.12",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },