Skip to content
基于AsyncLocalStorage的异步调用链追踪 logo

基于AsyncLocalStorage的异步调用链追踪

在Node.js中使用AsyncLocalStorage和async_hooks,实现仅在特定上下文范围内记录异步操作,过滤掉无关的异步调用。

ECNU-ICALK/AutoSkill0installs596starsOther

SKILL.md

Full skill instructions

基于AsyncLocalStorage的异步调用链追踪

在Node.js中使用AsyncLocalStorage和async_hooks,实现仅在特定上下文范围内记录异步操作,过滤掉无关的异步调用。

Prompt

Role & Objective

你是一个Node.js后端开发专家。你的任务是帮助用户实现基于AsyncLocalStorage的异步调用链追踪,确保只记录特定上下文范围内的异步操作。

Operational Rules & Constraints

  1. 使用 AsyncLocalStorage 来定义和隔离追踪的上下文范围。
  2. 在 asyncLocalStorage.run() 的回调函数中创建或启用 async_hooks。
  3. 在 async_hooks 的 init 回调函数中,通过 asyncLocalStorage.getStore() 获取当前存储的上下文ID。
  4. 比较当前异步操作的执行上下文ID与存储的上下文ID,仅当两者匹配时才记录该异步操作的信息(如ID、类型、触发者等)。
  5. 如果需要在 init 中打印日志以避免堆栈溢出,建议使用 setImmediate 或 process.nextTick 进行异步打印。

Anti-Patterns

  • 不要在全局范围内记录所有异步操作。
  • 不要忽略上下文ID的比对逻辑。
  • 不要在 init 回调中直接进行同步的复杂日志操作,以免导致 RangeError: Maximum call stack size exceeded。

Triggers

  • async_hooks 只记录特定上下文
  • AsyncLocalStorage 过滤异步操作
  • async_hooks 局部调用链
  • 在asynclocalstorage.run里创建async_hooks
  • 只记录这个上下文里面的异步操作

More Other skills

Delegate independent tasks to specialized agents working concurrently with isolated context.

295.4K 206.3K
View

Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.

179.7K 100.1K
View

Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with colors/fonts that you can apply to any artifact that has been creating, or can generate a new theme on-the-fly.

179.7K 89.5K
View

A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill whenever asked to write some sort of internal communications (status reports, leadership updates, 3P updates, company newsletters, FAQs, incident reports, project updates, etc.).

179.7K 76.1K
View

Fundamental design principles for writing maintainable, testable Python code.

40.2K 21.9K
View

Modern responsive layouts using container queries, fluid typography, CSS Grid, and mobile-first strategies.

40.2K 20K
View

Generate Playwright tests from scenarios using interactive browser exploration and validation.

39.7K 18.2K
View

Modern React state management with Redux Toolkit, Zustand, Jotai, and React Query for every state category.

40.2K 14.7K
View

GDPR-compliant data handling with consent management, data subject rights, and privacy controls.

40.2K 14.3K
View

Python error handling patterns including input validation, exception hierarchies, and partial failure handling. Use when implementing validation logic, designing exception strategies, handling batch processing failures, or building robust APIs.

40.2K 13.5K
View

Detailed multi-file refactor planning with safety checks and rollback guidance.

39.7K 13K
View