@kangc/skywalking-backend-js
Version:
The NodeJS agent for Apache SkyWalking
70 lines • 3.04 kB
JavaScript
;
/*!
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var SwPlugin_1 = require("../core/SwPlugin");
var Tracing_pb_1 = require("../proto/language-agent/Tracing_pb");
var Tag_1 = tslib_1.__importDefault(require("../Tag"));
var Component_1 = require("../trace/Component");
var ContextManager_1 = tslib_1.__importDefault(require("../trace/context/ContextManager"));
var IORedisPlugin = /** @class */ (function () {
function IORedisPlugin() {
this.module = 'ioredis';
this.versions = '*';
}
IORedisPlugin.prototype.install = function (installer) {
var Redis = installer.require('ioredis');
this.interceptOperation(Redis, 'sendCommand');
};
IORedisPlugin.prototype.interceptOperation = function (Cls, operation) {
var _original = Cls.prototype[operation];
if (!_original)
return;
Cls.prototype[operation] = function () {
var _a, _b;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var command = args[0];
var host = this.options.host + ":" + this.options.port;
var span = ContextManager_1.default.current.newExitSpan("redis/" + (command === null || command === void 0 ? void 0 : command.name), Component_1.Component.REDIS);
span.start();
span.component = Component_1.Component.REDIS;
span.layer = Tracing_pb_1.SpanLayer.CACHE;
span.peer = host;
span.tag(Tag_1.default.dbType('Redis'));
span.tag(Tag_1.default.dbInstance("" + ((_b = (_a = this.condition) === null || _a === void 0 ? void 0 : _a.select) !== null && _b !== void 0 ? _b : host)));
try {
var ret = SwPlugin_1.wrapPromise(span, _original.apply(this, args));
span.async();
return ret;
}
catch (err) {
span.error(err);
span.stop();
throw err;
}
};
};
return IORedisPlugin;
}());
exports.default = new IORedisPlugin();
//# sourceMappingURL=IORedisPlugin.js.map