Skip to content

Commit

Permalink
fix(instrumentation-redis-4): avoid shimmer warning by only wrapping …
Browse files Browse the repository at this point in the history
…multi/MULTI if they exist (#1729)

Co-authored-by: Marc Pichler <[email protected]>
  • Loading branch information
trentm and pichlermarc authored Oct 13, 2023
1 parent a8c225d commit 247a81c
Showing 1 changed file with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,23 +166,31 @@ export class RedisInstrumentation extends InstrumentationBase<any> {
this._diag.debug('Patching redis client');
const redisClientPrototype = moduleExports?.default?.prototype;

if (isWrapped(redisClientPrototype?.multi)) {
this._unwrap(redisClientPrototype, 'multi');
// In some @redis/client versions 'multi' is a method. In later
// versions, as of https://github.com/redis/node-redis/pull/2324,
// 'MULTI' is a method and 'multi' is a property defined in the
// constructor that points to 'MULTI', and therefore it will not
// be defined on the prototype.
if (redisClientPrototype?.multi) {
if (isWrapped(redisClientPrototype?.multi)) {
this._unwrap(redisClientPrototype, 'multi');
}
this._wrap(
redisClientPrototype,
'multi',
this._getPatchRedisClientMulti()
);
}
this._wrap(
redisClientPrototype,
'multi',
this._getPatchRedisClientMulti()
);

if (isWrapped(redisClientPrototype?.MULTI)) {
this._unwrap(redisClientPrototype, 'MULTI');
if (redisClientPrototype?.MULTI) {
if (isWrapped(redisClientPrototype?.MULTI)) {
this._unwrap(redisClientPrototype, 'MULTI');
}
this._wrap(
redisClientPrototype,
'MULTI',
this._getPatchRedisClientMulti()
);
}
this._wrap(
redisClientPrototype,
'MULTI',
this._getPatchRedisClientMulti()
);

if (isWrapped(redisClientPrototype?.sendCommand)) {
this._unwrap(redisClientPrototype, 'sendCommand');
Expand Down

0 comments on commit 247a81c

Please sign in to comment.