@longzai-intelligence-logger/tracing-node
v0.1.2
Published
Readme
Logger Adapter Tracing Node
Node.js 平台的追踪上下文适配器,使用 AsyncLocalStorage 实现追踪上下文管理。
安装
bun add @longzai-intelligence-logger/tracing-node基础使用
快速开始
import {
createNodeTracingAdapter,
setTracingContextManager,
} from '@longzai-intelligence-logger/tracing-node';
const tracingAdapter = createNodeTracingAdapter();
setTracingContextManager(tracingAdapter);在追踪上下文中运行
import {
createNodeTracingAdapter,
setTracingContextManager,
getCurrentTraceContext,
} from '@longzai-intelligence-logger/tracing-node';
const adapter = createNodeTracingAdapter();
setTracingContextManager(adapter);
adapter.runWithNewTrace(() => {
const context = getCurrentTraceContext();
console.log('当前追踪 ID:', context?.traceId);
adapter.runWithChildSpan(() => {
const childContext = getCurrentTraceContext();
console.log('子跨度 ID:', childContext?.spanId);
console.log('父跨度 ID:', childContext?.parentSpanId);
});
});导出内容
NodeTracingAdapter- Node.js 追踪适配器类createNodeTracingAdapter- 创建追踪适配器工厂函数setTracingContextManager- 设置全局追踪上下文管理器getTracingContextManager- 获取全局追踪上下文管理器getCurrentTraceContext- 获取当前追踪上下文getCurrentTraceId- 获取当前追踪 IDgetCurrentSpanId- 获取当前跨度 ID
