From 247a81c047264ba638abb9a2ef2ca14801094040 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Fri, 13 Oct 2023 05:04:30 -0700 Subject: [PATCH] fix(instrumentation-redis-4): avoid shimmer warning by only wrapping multi/MULTI if they exist (#1729) Co-authored-by: Marc Pichler --- .../src/instrumentation.ts | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/plugins/node/opentelemetry-instrumentation-redis-4/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-redis-4/src/instrumentation.ts index 07628f2055..aa30a98822 100644 --- a/plugins/node/opentelemetry-instrumentation-redis-4/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-redis-4/src/instrumentation.ts @@ -166,23 +166,31 @@ export class RedisInstrumentation extends InstrumentationBase { 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');