Ai
2 Star 4 Fork 2

来贝科技/API网关插件库

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
index.js 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
老技 提交于 2018-07-26 11:48 +08:00 . 1. optimize trace id generation
"use strict";
/**
* 日志追踪
* Created by liamjung on 2018/7/2.
*/
const {randomHex} = require("@libfintech/api-gateway-core/util/hex_util");
const TRACE_ID_KEY = global.appConfig.log.traceIdKey;
const SPAN_ID_KEY = global.appConfig.log.spanIdKey;
const PARENT_SPAN_ID_KEY = global.appConfig.log.parentSpanIdKey;
async function main(pipeline, configs) {
let logTraceId = pipeline.request.headers[TRACE_ID_KEY];
let logSpanId = pipeline.request.headers[SPAN_ID_KEY];
let logParentSpanId = pipeline.request.headers[PARENT_SPAN_ID_KEY];
if (!logTraceId) {
logTraceId = randomHex();
logSpanId = logTraceId;
pipeline.logger.debug("No log trace id, generate new id (value: " + logTraceId + ")");
} else {
pipeline.logger.debug("Last log trace id (value: " + logTraceId + ")");
}
//当前
pipeline.logger.traceId = logTraceId;
pipeline.logger.spanId = logSpanId;
pipeline.logger.parentSpanId = logParentSpanId;
//下一环节
pipeline.request.headers[TRACE_ID_KEY] = logTraceId;
pipeline.request.headers[SPAN_ID_KEY] = randomHex();
pipeline.request.headers[PARENT_SPAN_ID_KEY] = logSpanId;
}
module.exports = {
main: main
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
NodeJS
1
https://gitee.com/libfintech/api_gateway_plugin.git
git@gitee.com:libfintech/api_gateway_plugin.git
libfintech
api_gateway_plugin
API网关插件库
master

搜索帮助