Skip to content
Back to skills

基于Asynclocalstorage的异步调用链追踪

ASecurity

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

  • 611 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
educationnode

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill '基于asynclocalstorage的异步调用链追踪' --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 基于Asynclocalstorage的异步调用链追踪?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 基于Asynclocalstorage的异步调用链追踪
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-asynclocalstorage/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-asynclocalstorage)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "1730215a-f5af-446b-80f0-b59d3ad7323e"
name: "基于AsyncLocalStorage的异步调用链追踪"
description: "在Node.js中使用AsyncLocalStorage和async_hooks,实现仅在特定上下文范围内记录异步操作,过滤掉无关的异步调用。"
version: "0.1.0"
tags:
  - "Node.js"
  - "async_hooks"
  - "AsyncLocalStorage"
  - "调用链"
  - "异步追踪"
triggers:
  - "async_hooks 只记录特定上下文"
  - "AsyncLocalStorage 过滤异步操作"
  - "async_hooks 局部调用链"
  - "在asynclocalstorage.run里创建async_hooks"
  - "只记录这个上下文里面的异步操作"
---

# 基于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
- 只记录这个上下文里面的异步操作

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in education →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.