skywalking-backend-js-netease
Version:
The NodeJS agent for Apache SkyWalking
69 lines • 2.6 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 });
exports.tagCustomIds = void 0;
const tslib_1 = require("tslib");
const AgentConfig_1 = tslib_1.__importDefault(require("../config/AgentConfig"));
const customIdKey = 'custom_id';
function collectCustomIds(req, span) {
if (AgentConfig_1.default.customIdList && AgentConfig_1.default.customIdList.length > 0) {
const vals = new Set();
const url = new URL((req === null || req === void 0 ? void 0 : req.url) || '/avoid-exception', 'http://any');
const query = url.searchParams;
for (let i = 0; i < AgentConfig_1.default.customIdList.length; i++) {
const key = AgentConfig_1.default.customIdList[i];
const type = AgentConfig_1.default.customIdTypeList[i] || '0';
switch (type) {
case '0': // from header
const head = get(req.headers[key]);
if (head)
vals.add(head);
continue;
case '1':
const param = query.get(key);
if (param)
vals.add(param);
continue;
}
}
if (vals.size > 0) {
span.tag({ key: customIdKey, overridable: true, val: [...vals].join(',') });
}
}
return undefined;
}
exports.default = collectCustomIds;
;
function tagCustomIds(ids, span) {
if (ids) {
span.tag({ key: customIdKey, overridable: true, val: ids });
}
}
exports.tagCustomIds = tagCustomIds;
function get(val) {
if (!val) {
return val;
}
if (Array.isArray(val)) {
return val.length > 0 ? val[0] : undefined;
}
return val;
}
//# sourceMappingURL=CustomMonitor.js.map