@midwayjs/redis 4.0.0-beta.11 → 4.0.0-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/manager.d.ts +6 -1
- package/dist/manager.js +63 -0
- package/package.json +4 -4
package/dist/manager.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import { ServiceFactory, ServiceFactoryConfigOption, ILogger } from '@midwayjs/core';
|
|
1
|
+
import { MidwayTraceService, ServiceFactory, ServiceFactoryConfigOption, ILogger } from '@midwayjs/core';
|
|
2
2
|
import Redis from 'ioredis';
|
|
3
3
|
import { RedisConfigOptions } from './interface';
|
|
4
4
|
export declare class RedisServiceFactory extends ServiceFactory<Redis> {
|
|
5
5
|
protected redisConfig: ServiceFactoryConfigOption<RedisConfigOptions>;
|
|
6
6
|
protected init(): Promise<void>;
|
|
7
7
|
protected logger: ILogger;
|
|
8
|
+
protected traceService: MidwayTraceService;
|
|
9
|
+
protected traceMetaResolver: any;
|
|
10
|
+
protected traceEnabled: any;
|
|
11
|
+
protected traceInjector: any;
|
|
8
12
|
protected createClient(config: any, name: string): Promise<Redis>;
|
|
13
|
+
protected bindTraceContext(client: Redis, clientName: string): void;
|
|
9
14
|
getName(): string;
|
|
10
15
|
protected destroyClient(redisInstance: Redis, name: string): Promise<void>;
|
|
11
16
|
}
|
package/dist/manager.js
CHANGED
|
@@ -21,6 +21,10 @@ let RedisServiceFactory = class RedisServiceFactory extends core_1.ServiceFactor
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
logger;
|
|
24
|
+
traceService;
|
|
25
|
+
traceMetaResolver;
|
|
26
|
+
traceEnabled;
|
|
27
|
+
traceInjector;
|
|
24
28
|
async createClient(config, name) {
|
|
25
29
|
let client;
|
|
26
30
|
if (config.cluster === true) {
|
|
@@ -54,8 +58,51 @@ let RedisServiceFactory = class RedisServiceFactory extends core_1.ServiceFactor
|
|
|
54
58
|
reject(err);
|
|
55
59
|
});
|
|
56
60
|
});
|
|
61
|
+
this.bindTraceContext(client, name);
|
|
57
62
|
return client;
|
|
58
63
|
}
|
|
64
|
+
bindTraceContext(client, clientName) {
|
|
65
|
+
if (!client || !this.traceService) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const rawSendCommand = client.sendCommand?.bind(client);
|
|
69
|
+
if (!rawSendCommand) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
client.sendCommand = (command, stream) => {
|
|
73
|
+
const commandName = command?.name?.toLowerCase?.() || command?.name || 'unknown';
|
|
74
|
+
const rawCarrier = typeof this.traceInjector === 'function'
|
|
75
|
+
? this.traceInjector({
|
|
76
|
+
request: command,
|
|
77
|
+
custom: {
|
|
78
|
+
clientName,
|
|
79
|
+
commandName,
|
|
80
|
+
},
|
|
81
|
+
})
|
|
82
|
+
: {};
|
|
83
|
+
const carrier = rawCarrier && typeof rawCarrier === 'object' ? rawCarrier : {};
|
|
84
|
+
return this.traceService.runWithExitSpan(`redis.${commandName}`, {
|
|
85
|
+
enable: this.traceEnabled !== false,
|
|
86
|
+
carrier,
|
|
87
|
+
attributes: {
|
|
88
|
+
'midway.protocol': 'redis',
|
|
89
|
+
'midway.redis.command': commandName,
|
|
90
|
+
'midway.redis.client': clientName,
|
|
91
|
+
},
|
|
92
|
+
meta: this.traceMetaResolver,
|
|
93
|
+
metaArgs: {
|
|
94
|
+
carrier,
|
|
95
|
+
request: command,
|
|
96
|
+
custom: {
|
|
97
|
+
clientName,
|
|
98
|
+
commandName,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
}, async () => {
|
|
102
|
+
return rawSendCommand(command, stream);
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
}
|
|
59
106
|
getName() {
|
|
60
107
|
return 'redis';
|
|
61
108
|
}
|
|
@@ -89,6 +136,22 @@ __decorate([
|
|
|
89
136
|
(0, core_1.Logger)('coreLogger'),
|
|
90
137
|
__metadata("design:type", Object)
|
|
91
138
|
], RedisServiceFactory.prototype, "logger", void 0);
|
|
139
|
+
__decorate([
|
|
140
|
+
(0, core_1.Inject)(),
|
|
141
|
+
__metadata("design:type", core_1.MidwayTraceService)
|
|
142
|
+
], RedisServiceFactory.prototype, "traceService", void 0);
|
|
143
|
+
__decorate([
|
|
144
|
+
(0, core_1.Config)('redis.tracing.meta'),
|
|
145
|
+
__metadata("design:type", Object)
|
|
146
|
+
], RedisServiceFactory.prototype, "traceMetaResolver", void 0);
|
|
147
|
+
__decorate([
|
|
148
|
+
(0, core_1.Config)('redis.tracing.enable'),
|
|
149
|
+
__metadata("design:type", Object)
|
|
150
|
+
], RedisServiceFactory.prototype, "traceEnabled", void 0);
|
|
151
|
+
__decorate([
|
|
152
|
+
(0, core_1.Config)('redis.tracing.injector'),
|
|
153
|
+
__metadata("design:type", Object)
|
|
154
|
+
], RedisServiceFactory.prototype, "traceInjector", void 0);
|
|
92
155
|
exports.RedisServiceFactory = RedisServiceFactory = __decorate([
|
|
93
156
|
(0, core_1.Provide)(),
|
|
94
157
|
(0, core_1.Scope)(core_1.ScopeEnum.Singleton)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/redis",
|
|
3
3
|
"description": "midway redis component",
|
|
4
|
-
"version": "4.0.0-beta.
|
|
4
|
+
"version": "4.0.0-beta.12",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"index.d.ts"
|
|
11
11
|
],
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"@midwayjs/core": "^4.0.0-beta.
|
|
14
|
-
"@midwayjs/mock": "^4.0.0-beta.
|
|
13
|
+
"@midwayjs/core": "^4.0.0-beta.12",
|
|
14
|
+
"@midwayjs/mock": "^4.0.0-beta.12"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"ioredis": "5.4.2"
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"type": "git",
|
|
36
36
|
"url": "https://github.com/midwayjs/midway.git"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "1c48179b7c827ba8ec9351e9b6c36ec1726d3e11"
|
|
39
39
|
}
|