@aomex/async-trace
Advanced tools
Comparing version 1.0.4 to 1.1.0
@@ -1,11 +0,11 @@ | ||
# @aomex/async-trace | ||
# Change Log | ||
## 1.0.4 | ||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
## 1.0.3 | ||
# 1.1.0 (2024-06-27) | ||
## 1.0.2 | ||
### Patch Changes | ||
### Features | ||
- [`57683f8`](https://github.com/aomex/aomex/commit/57683f8da5c02eb07946c3fdb3d4339587d356a2) Thanks [@geekact](https://github.com/geekact)! - feat(async-trace): 异步逻辑链路追踪 | ||
* 初始化 ([3350159](https://github.com/aomex/aomex/commit/3350159454ad230e6d910405f907293b059b1f49)) |
@@ -5,3 +5,3 @@ import { AsyncLocalStorage } from 'async_hooks'; | ||
interface AsyncTraceRecord { | ||
id: number; | ||
id: string; | ||
/** | ||
@@ -26,3 +26,3 @@ * 标签 | ||
*/ | ||
parent?: number; | ||
parent?: string; | ||
/** | ||
@@ -35,6 +35,6 @@ * 子链路 | ||
records: AsyncTraceRecord[]; | ||
protected readonly storage: AsyncLocalStorage<number>; | ||
protected readonly storage: AsyncLocalStorage<string>; | ||
protected idSequence: number; | ||
run<T>(label: string, callback: (id: number) => Promise<T>): Promise<T>; | ||
getRecord(id: number): AsyncTraceRecord; | ||
run<T>(label: string, callback: (id: string) => Promise<T>): Promise<T>; | ||
getRecord(id: string): AsyncTraceRecord; | ||
} | ||
@@ -41,0 +41,0 @@ declare const asyncTrace: AsyncTrace; |
@@ -9,6 +9,9 @@ // src/async-trace.ts | ||
const parent = this.storage.getStore(); | ||
const id = ++this.idSequence; | ||
if (++this.idSequence >= Number.MAX_SAFE_INTEGER) { | ||
this.idSequence = 0; | ||
} | ||
return new Promise((resolve, reject) => { | ||
const start = Date.now(); | ||
const id = start + "." + this.idSequence; | ||
this.storage.run(id, async () => { | ||
const start = Date.now(); | ||
const done = () => { | ||
@@ -15,0 +18,0 @@ const end = Date.now(); |
{ | ||
"name": "@aomex/async-trace", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "异步逻辑链路追踪", | ||
@@ -32,5 +32,5 @@ "repository": "git@github.com:aomex/aomex.git", | ||
"devDependencies": { | ||
"@aomex/core": "^1.0.4" | ||
"@aomex/core": "^1.1.0" | ||
}, | ||
"scripts": {} | ||
} |
Sorry, the diff of this file is not supported yet
13625
181