UNPKG

skywalking-backend-js-netease

Version:

The NodeJS agent for Apache SkyWalking

65 lines 2.78 kB
"use strict"; /*! * * 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 }); const tslib_1 = require("tslib"); const SwPlugin_1 = require("../core/SwPlugin"); const Tracing_pb_1 = require("../proto/language-agent/Tracing_pb"); const Tag_1 = tslib_1.__importDefault(require("../Tag")); const Component_1 = require("../trace/Component"); const ContextManager_1 = tslib_1.__importDefault(require("../trace/context/ContextManager")); class IORedisPlugin { constructor() { this.module = 'ioredis'; this.versions = '*'; } install(installer) { const Redis = installer.require('ioredis'); this.interceptOperation(Redis, 'sendCommand'); } interceptOperation(Cls, operation) { const _original = Cls.prototype[operation]; if (!_original) return; Cls.prototype[operation] = function (...args) { var _a, _b; const command = args[0]; const host = `${this.options.host}:${this.options.port}`; const 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 { const ret = SwPlugin_1.wrapPromise(span, _original.apply(this, args)); span.async(); return ret; } catch (err) { span.error(err); span.stop(); throw err; } }; } } exports.default = new IORedisPlugin(); //# sourceMappingURL=IORedisPlugin.js.map