Skip to content

Commit 247a81c

Browse files
trentmpichlermarc
andauthored
fix(instrumentation-redis-4): avoid shimmer warning by only wrapping multi/MULTI if they exist (#1729)
Co-authored-by: Marc Pichler <[email protected]>
1 parent a8c225d commit 247a81c

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

plugins/node/opentelemetry-instrumentation-redis-4/src/instrumentation.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -166,23 +166,31 @@ export class RedisInstrumentation extends InstrumentationBase<any> {
166166
this._diag.debug('Patching redis client');
167167
const redisClientPrototype = moduleExports?.default?.prototype;
168168

169-
if (isWrapped(redisClientPrototype?.multi)) {
170-
this._unwrap(redisClientPrototype, 'multi');
169+
// In some @redis/client versions 'multi' is a method. In later
170+
// versions, as of https://github.com/redis/node-redis/pull/2324,
171+
// 'MULTI' is a method and 'multi' is a property defined in the
172+
// constructor that points to 'MULTI', and therefore it will not
173+
// be defined on the prototype.
174+
if (redisClientPrototype?.multi) {
175+
if (isWrapped(redisClientPrototype?.multi)) {
176+
this._unwrap(redisClientPrototype, 'multi');
177+
}
178+
this._wrap(
179+
redisClientPrototype,
180+
'multi',
181+
this._getPatchRedisClientMulti()
182+
);
171183
}
172-
this._wrap(
173-
redisClientPrototype,
174-
'multi',
175-
this._getPatchRedisClientMulti()
176-
);
177-
178-
if (isWrapped(redisClientPrototype?.MULTI)) {
179-
this._unwrap(redisClientPrototype, 'MULTI');
184+
if (redisClientPrototype?.MULTI) {
185+
if (isWrapped(redisClientPrototype?.MULTI)) {
186+
this._unwrap(redisClientPrototype, 'MULTI');
187+
}
188+
this._wrap(
189+
redisClientPrototype,
190+
'MULTI',
191+
this._getPatchRedisClientMulti()
192+
);
180193
}
181-
this._wrap(
182-
redisClientPrototype,
183-
'MULTI',
184-
this._getPatchRedisClientMulti()
185-
);
186194

187195
if (isWrapped(redisClientPrototype?.sendCommand)) {
188196
this._unwrap(redisClientPrototype, 'sendCommand');

0 commit comments

Comments
 (0)