MCPcopy Create free account
hub / github.com/apache/skywalking-nodejs / IORedisPlugin

Class IORedisPlugin

src/plugins/IORedisPlugin.ts:27–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25import ContextManager from '../trace/context/ContextManager';
26
27class IORedisPlugin implements SwPlugin {
28 readonly module = 'ioredis';
29 readonly versions = '*';
30
31 install(installer: PluginInstaller): void {
32 const Redis = installer.require?.('ioredis') ?? require('ioredis');
33
34 this.interceptOperation(Redis, 'sendCommand');
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
68export default new IORedisPlugin();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected