(Cls: any, operation: string)
| 35 | } |
| 36 | |
| 37 | interceptOperation(Cls: any, operation: string): void { |
| 38 | const _original = Cls.prototype[operation]; |
| 39 | |
| 40 | if (!_original) return; |
| 41 | |
| 42 | Cls.prototype[operation] = function (...args: any[]) { |
| 43 | const command = args[0]; |
| 44 | const host = `${this.options.host}:${this.options.port}`; |
| 45 | const span = ContextManager.current.newExitSpan(`redis/${command?.name}`, Component.REDIS); |
| 46 | |
| 47 | span.start(); |
| 48 | span.component = Component.REDIS; |
| 49 | span.layer = SpanLayer.CACHE; |
| 50 | span.peer = host; |
| 51 | span.tag(Tag.dbType('Redis')); |
| 52 | span.tag(Tag.dbInstance(`${this.condition?.select ?? host}`)); |
| 53 | |
| 54 | try { |
| 55 | const ret = wrapPromise(span, _original.apply(this, args)); |
| 56 | span.async(); |
| 57 | return ret; |
| 58 | } catch (err) { |
| 59 | span.error(err); |
| 60 | span.stop(); |
| 61 | |
| 62 | throw err; |
| 63 | } |
| 64 | }; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | export default new IORedisPlugin(); |
no test coverage detected