UNPKG

2.35 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.enable = exports.redis = void 0;
4// Copyright (c) Microsoft Corporation. All rights reserved.
5// Licensed under the MIT license. See LICENSE file in the project root for details.
6var diagnostic_channel_1 = require("diagnostic-channel");
7var redisPatchFunction = function (originalRedis) {
8 var originalSend = originalRedis.RedisClient.prototype.internal_send_command;
9 // Note: This is mixing together both context tracking and dependency tracking
10 originalRedis.RedisClient.prototype.internal_send_command = function (commandObj) {
11 if (commandObj) {
12 var cb_1 = commandObj.callback;
13 if (!cb_1 || !cb_1.pubsubBound) {
14 var address_1 = this.address;
15 var startTime_1 = process.hrtime();
16 var startDate_1 = new Date();
17 // Note: augmenting the callback on internal_send_command is correct for context
18 // tracking, but may be too low-level for dependency tracking. There are some 'errors'
19 // which higher levels expect in some cases
20 // However, the only other option is to intercept every individual command.
21 commandObj.callback = diagnostic_channel_1.channel.bindToContext(function (err, result) {
22 var hrDuration = process.hrtime(startTime_1);
23 /* tslint:disable-next-line:no-bitwise */
24 var duration = (hrDuration[0] * 1e3 + hrDuration[1] / 1e6) | 0;
25 diagnostic_channel_1.channel.publish("redis", { duration: duration, address: address_1, commandObj: commandObj, err: err, result: result, time: startDate_1 });
26 if (typeof cb_1 === "function") {
27 cb_1.apply(this, arguments);
28 }
29 });
30 commandObj.callback.pubsubBound = true;
31 }
32 }
33 return originalSend.call(this, commandObj);
34 };
35 return originalRedis;
36};
37exports.redis = {
38 versionSpecifier: ">= 2.0.0 < 4.0.0",
39 patch: redisPatchFunction,
40};
41function enable() {
42 diagnostic_channel_1.channel.registerMonkeyPatch("redis", exports.redis);
43}
44exports.enable = enable;
45//# sourceMappingURL=redis.pub.js.map
\No newline at end of file