mermaid-trace 0.3.1__tar.gz → 0.4.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/PKG-INFO +25 -8
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/README.md +22 -7
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/README_CN.md +33 -7
- mermaid_trace-0.4.1/docs/en/API.md +157 -0
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/docs/en/CHANGELOG.md +30 -0
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/docs/en/CONTRIBUTING.md +11 -1
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/docs/en/USER_GUIDE.md +54 -0
- mermaid_trace-0.4.1/docs/zh/API.md +157 -0
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/docs/zh/CHANGELOG.md +31 -1
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/docs/zh/CONTRIBUTING.md +11 -1
- mermaid_trace-0.4.1/docs/zh/UPDATE_SUMMARY.md +99 -0
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/docs/zh/USER_GUIDE.md +54 -0
- mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/__init__.md +122 -0
- mermaid_trace-0.3.1/src/mermaid_trace/cli.py → mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/cli.md +94 -25
- mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/core/context.md +203 -0
- mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/core/decorators.md +325 -0
- mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/core/events.md +158 -0
- mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/core/formatter.md +143 -0
- mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/core/image/context/1769443810901.png +0 -0
- mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/core/image/context/1769443817389.png +0 -0
- mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/core/image/context/1769443818915.png +0 -0
- mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/core/image/context/1769443830665.png +0 -0
- mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/core/image/context/1769443835553.png +0 -0
- mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/handlers/async_handler.md +124 -0
- mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/handlers/mermaid_handler.md +119 -0
- mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/integrations/fastapi.md +150 -0
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/examples/concurrency_demo.py +8 -8
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/examples/demo.py +6 -1
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/examples/error_handling_demo.py +6 -3
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/examples/nested_demo.py +5 -1
- mermaid_trace-0.4.1/flow.mmd +33 -0
- mermaid_trace-0.4.1/image/README_CN/1769402097355.png +0 -0
- mermaid_trace-0.4.1/improvement_plan.md +253 -0
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/pyproject.toml +14 -2
- mermaid_trace-0.4.1/src/mermaid_trace/__init__.py +133 -0
- mermaid_trace-0.4.1/src/mermaid_trace/cli.py +303 -0
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/src/mermaid_trace/core/context.py +102 -41
- mermaid_trace-0.4.1/src/mermaid_trace/core/decorators.py +470 -0
- mermaid_trace-0.4.1/src/mermaid_trace/core/events.py +190 -0
- mermaid_trace-0.4.1/src/mermaid_trace/core/formatter.py +151 -0
- mermaid_trace-0.4.1/src/mermaid_trace/handlers/async_handler.py +105 -0
- mermaid_trace-0.4.1/src/mermaid_trace/handlers/mermaid_handler.py +119 -0
- mermaid_trace-0.4.1/src/mermaid_trace/integrations/fastapi.py +166 -0
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/tests/conftest.py +1 -0
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/tests/core/test_cli.py +42 -23
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/tests/core/test_context.py +13 -7
- mermaid_trace-0.4.1/tests/core/test_context_extra.py +32 -0
- mermaid_trace-0.4.1/tests/core/test_decorators_extra.py +86 -0
- mermaid_trace-0.4.1/tests/core/test_events.py +71 -0
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/tests/core/test_formatter.py +29 -10
- mermaid_trace-0.4.1/tests/core/test_formatter_extra.py +130 -0
- mermaid_trace-0.4.1/tests/handlers/test_handlers.py +122 -0
- mermaid_trace-0.3.1/tests/integrations/test_decorators.py → mermaid_trace-0.4.1/tests/integrations/test_integration_decorators.py +97 -21
- mermaid_trace-0.4.1/tests/integrations/test_integration_fastapi.py +149 -0
- mermaid_trace-0.4.1/tests/scenarios/test_basic_flow.py +44 -0
- mermaid_trace-0.4.1/tests/scenarios/test_concurrency.py +96 -0
- mermaid_trace-0.4.1/tests/scenarios/test_edge_cases.py +81 -0
- mermaid_trace-0.4.1/tests/scenarios/test_performance.py +94 -0
- mermaid_trace-0.4.1/tox.ini +24 -0
- mermaid_trace-0.3.1/docs/en/API.md +0 -63
- mermaid_trace-0.3.1/docs/zh/API.md +0 -63
- mermaid_trace-0.3.1/flow.mmd +0 -15
- mermaid_trace-0.3.1/src/mermaid_trace/__init__.py +0 -70
- mermaid_trace-0.3.1/src/mermaid_trace/core/decorators.py +0 -252
- mermaid_trace-0.3.1/src/mermaid_trace/core/events.py +0 -75
- mermaid_trace-0.3.1/src/mermaid_trace/core/formatter.py +0 -72
- mermaid_trace-0.3.1/src/mermaid_trace/handlers/mermaid_handler.py +0 -86
- mermaid_trace-0.3.1/src/mermaid_trace/integrations/fastapi.py +0 -122
- mermaid_trace-0.3.1/tests/core/test_events.py +0 -21
- mermaid_trace-0.3.1/tests/handlers/test_mermaid_handler.py +0 -60
- mermaid_trace-0.3.1/tests/integrations/test_fastapi_full.py +0 -63
- mermaid_trace-0.3.1/tests/repro_concurrency.py +0 -43
- mermaid_trace-0.3.1/tests/test_fastapi.py +0 -54
- mermaid_trace-0.3.1/tests/test_fastapi_integration.py +0 -76
- mermaid_trace-0.3.1/tests/test_flow.py +0 -44
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/.github/workflows/ci.yml +0 -0
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/.github/workflows/release.yml +0 -0
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/.gitignore +0 -0
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/LICENSE +0 -0
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/SECURITY.md +0 -0
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/docs/en/LICENSE +0 -0
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/docs/zh/LICENSE +0 -0
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/src/mermaid_trace/core/__init__.py +0 -0
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/src/mermaid_trace/py.typed +0 -0
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/tests/__init__.py +0 -0
- {mermaid_trace-0.3.1 → mermaid_trace-0.4.1}/tests/core/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mermaid-trace
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: Visualize your Python code execution flow as Mermaid Sequence Diagrams.
|
|
5
5
|
Project-URL: Documentation, https://github.com/xt765/mermaid-trace#readme
|
|
6
6
|
Project-URL: Changelog, https://github.com/xt765/mermaid-trace/blob/main/docs/en/CHANGELOG.md
|
|
@@ -38,6 +38,8 @@ Classifier: Programming Language :: Python
|
|
|
38
38
|
Classifier: Programming Language :: Python :: 3.10
|
|
39
39
|
Classifier: Programming Language :: Python :: 3.11
|
|
40
40
|
Classifier: Programming Language :: Python :: 3.12
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
41
43
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
42
44
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
43
45
|
Classifier: Topic :: Software Development :: Debuggers
|
|
@@ -61,17 +63,31 @@ Description-Content-Type: text/markdown
|
|
|
61
63
|
|
|
62
64
|
# MermaidTrace: The Python Logger That Draws Diagrams
|
|
63
65
|
|
|
64
|
-
[
|
|
65
|
-
|
|
66
|
+
🌐 **Language**: [English](README.md) | [中文](README_CN.md)
|
|
67
|
+
|
|
68
|
+
[](https://pypi.org/project/mermaid-trace/)
|
|
69
|
+
[](https://pypi.org/project/mermaid-trace/)
|
|
66
70
|
[](LICENSE)
|
|
67
71
|
[](https://github.com/xt765/mermaid-trace/actions/workflows/ci.yml)
|
|
68
72
|
[](https://codecov.io/gh/xt765/mermaid-trace)
|
|
69
73
|
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## 📋 Overview
|
|
77
|
+
|
|
70
78
|
**Stop reading logs. Start watching them.**
|
|
71
79
|
|
|
72
80
|
MermaidTrace is a specialized logging tool that automatically generates [Mermaid JS](https://mermaid.js.org/) sequence diagrams from your code execution. It's perfect for visualizing complex business logic, microservice interactions, or asynchronous flows.
|
|
73
81
|
|
|
74
|
-
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## 📚 Documentation
|
|
85
|
+
|
|
86
|
+
[User Guide](docs/en/USER_GUIDE.md) · [API Reference](docs/en/API.md) · [Contributing Guidelines](docs/en/CONTRIBUTING.md) · [Changelog](docs/en/CHANGELOG.md) · [License](docs/en/LICENSE)
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## ✨ Key Features
|
|
75
91
|
|
|
76
92
|
- **Decorator-Driven**: Just add `@trace` or `@trace_interaction` to your functions.
|
|
77
93
|
- **Auto-Diagramming**: Generates `.mmd` files that can be viewed in VS Code, GitHub, or Mermaid Live Editor.
|
|
@@ -80,6 +96,8 @@ MermaidTrace is a specialized logging tool that automatically generates [Mermaid
|
|
|
80
96
|
- **FastAPI Integration**: Includes middleware for zero-config HTTP request tracing.
|
|
81
97
|
- **CLI Tool**: Built-in viewer to preview diagrams in your browser.
|
|
82
98
|
|
|
99
|
+
---
|
|
100
|
+
|
|
83
101
|
## 🚀 Quick Start
|
|
84
102
|
|
|
85
103
|
### Installation
|
|
@@ -149,15 +167,14 @@ Visualize your generated `.mmd` files instantly:
|
|
|
149
167
|
mermaid-trace serve my_flow.mmd
|
|
150
168
|
```
|
|
151
169
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
- [English Documentation](docs/en/README.md)
|
|
155
|
-
- [中文文档](README_CN.md)
|
|
170
|
+
---
|
|
156
171
|
|
|
157
172
|
## 🤝 Contributing
|
|
158
173
|
|
|
159
174
|
We welcome contributions! Please see [CONTRIBUTING.md](docs/en/CONTRIBUTING.md) for details.
|
|
160
175
|
|
|
176
|
+
---
|
|
177
|
+
|
|
161
178
|
## 📄 License
|
|
162
179
|
|
|
163
180
|
MIT
|
|
@@ -1,16 +1,30 @@
|
|
|
1
1
|
# MermaidTrace: The Python Logger That Draws Diagrams
|
|
2
2
|
|
|
3
|
-
[
|
|
4
|
-
|
|
3
|
+
🌐 **Language**: [English](README.md) | [中文](README_CN.md)
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/mermaid-trace/)
|
|
6
|
+
[](https://pypi.org/project/mermaid-trace/)
|
|
5
7
|
[](LICENSE)
|
|
6
8
|
[](https://github.com/xt765/mermaid-trace/actions/workflows/ci.yml)
|
|
7
9
|
[](https://codecov.io/gh/xt765/mermaid-trace)
|
|
8
10
|
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 📋 Overview
|
|
14
|
+
|
|
9
15
|
**Stop reading logs. Start watching them.**
|
|
10
16
|
|
|
11
17
|
MermaidTrace is a specialized logging tool that automatically generates [Mermaid JS](https://mermaid.js.org/) sequence diagrams from your code execution. It's perfect for visualizing complex business logic, microservice interactions, or asynchronous flows.
|
|
12
18
|
|
|
13
|
-
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 📚 Documentation
|
|
22
|
+
|
|
23
|
+
[User Guide](docs/en/USER_GUIDE.md) · [API Reference](docs/en/API.md) · [Contributing Guidelines](docs/en/CONTRIBUTING.md) · [Changelog](docs/en/CHANGELOG.md) · [License](docs/en/LICENSE)
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## ✨ Key Features
|
|
14
28
|
|
|
15
29
|
- **Decorator-Driven**: Just add `@trace` or `@trace_interaction` to your functions.
|
|
16
30
|
- **Auto-Diagramming**: Generates `.mmd` files that can be viewed in VS Code, GitHub, or Mermaid Live Editor.
|
|
@@ -19,6 +33,8 @@ MermaidTrace is a specialized logging tool that automatically generates [Mermaid
|
|
|
19
33
|
- **FastAPI Integration**: Includes middleware for zero-config HTTP request tracing.
|
|
20
34
|
- **CLI Tool**: Built-in viewer to preview diagrams in your browser.
|
|
21
35
|
|
|
36
|
+
---
|
|
37
|
+
|
|
22
38
|
## 🚀 Quick Start
|
|
23
39
|
|
|
24
40
|
### Installation
|
|
@@ -88,15 +104,14 @@ Visualize your generated `.mmd` files instantly:
|
|
|
88
104
|
mermaid-trace serve my_flow.mmd
|
|
89
105
|
```
|
|
90
106
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
- [English Documentation](docs/en/README.md)
|
|
94
|
-
- [中文文档](README_CN.md)
|
|
107
|
+
---
|
|
95
108
|
|
|
96
109
|
## 🤝 Contributing
|
|
97
110
|
|
|
98
111
|
We welcome contributions! Please see [CONTRIBUTING.md](docs/en/CONTRIBUTING.md) for details.
|
|
99
112
|
|
|
113
|
+
---
|
|
114
|
+
|
|
100
115
|
## 📄 License
|
|
101
116
|
|
|
102
117
|
MIT
|
|
@@ -1,16 +1,41 @@
|
|
|
1
1
|
# MermaidTrace: 能画图的 Python 日志工具
|
|
2
2
|
|
|
3
|
-
[
|
|
4
|
-
|
|
3
|
+
🌐 **语言**: [English](README.md) | [中文](README_CN.md)
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/mermaid-trace/)
|
|
6
|
+
[](https://pypi.org/project/mermaid-trace/)
|
|
5
7
|
[](LICENSE)
|
|
6
8
|
[](https://github.com/xt765/mermaid-trace/actions/workflows/ci.yml)
|
|
7
9
|
[](https://codecov.io/gh/xt765/mermaid-trace)
|
|
8
10
|
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 📋 概述
|
|
14
|
+
|
|
9
15
|
**别再干读日志了。开始“看”懂它们吧。**
|
|
10
16
|
|
|
11
17
|
MermaidTrace 是一个专业的日志工具,能从你的代码执行中自动生成 [Mermaid JS](https://mermaid.js.org/) 时序图。它非常适合可视化复杂的业务逻辑、微服务交互或异步流程。
|
|
12
18
|
|
|
13
|
-
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 📚 文档
|
|
22
|
+
|
|
23
|
+
### 主要文档
|
|
24
|
+
|
|
25
|
+
[用户指南](docs/zh/USER_GUIDE.md) · [API 参考](docs/zh/API.md) · [贡献指南](docs/zh/CONTRIBUTING.md) · [更新日志](docs/zh/CHANGELOG.md) · [许可证](docs/zh/LICENSE)
|
|
26
|
+
|
|
27
|
+
### 代码注释文档
|
|
28
|
+
|
|
29
|
+
| 类别 | 链接 |
|
|
30
|
+
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
31
|
+
| **核心模块** | [Context](docs/zh/code_comments/src/mermaid_trace/core/context.md) · [Decorators](docs/zh/code_comments/src/mermaid_trace/core/decorators.md) · [Events](docs/zh/code_comments/src/mermaid_trace/core/events.md) · [Formatter](docs/zh/code_comments/src/mermaid_trace/core/formatter.md) |
|
|
32
|
+
| **处理器** | [Async Handler](docs/zh/code_comments/src/mermaid_trace/handlers/async_handler.md) · [Mermaid Handler](docs/zh/code_comments/src/mermaid_trace/handlers/mermaid_handler.md) |
|
|
33
|
+
| **集成** | [FastAPI](docs/zh/code_comments/src/mermaid_trace/integrations/fastapi.md) |
|
|
34
|
+
| **其他** | [init](docs/zh/code_comments/src/mermaid_trace/__init__.md) · [CLI](docs/zh/code_comments/src/mermaid_trace/cli.md) |
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## ✨ 核心特性
|
|
14
39
|
|
|
15
40
|
- **装饰器驱动**:只需在函数上添加 `@trace` 或 `@trace_interaction` 即可。
|
|
16
41
|
- **自动绘图**:生成 `.mmd` 文件,可在 VS Code、GitHub 或 Mermaid Live Editor 中查看。
|
|
@@ -19,6 +44,8 @@ MermaidTrace 是一个专业的日志工具,能从你的代码执行中自动
|
|
|
19
44
|
- **FastAPI 集成**:内置中间件,实现零配置的 HTTP 请求追踪。
|
|
20
45
|
- **CLI 工具**:内置查看器,可在浏览器中即时预览图表。
|
|
21
46
|
|
|
47
|
+
---
|
|
48
|
+
|
|
22
49
|
## 🚀 快速开始
|
|
23
50
|
|
|
24
51
|
### 安装
|
|
@@ -88,15 +115,14 @@ async def root():
|
|
|
88
115
|
mermaid-trace serve my_flow.mmd
|
|
89
116
|
```
|
|
90
117
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
- [英文文档](docs/en/README.md)
|
|
94
|
-
- [中文文档](README_CN.md)
|
|
118
|
+
---
|
|
95
119
|
|
|
96
120
|
## 🤝 贡献
|
|
97
121
|
|
|
98
122
|
欢迎贡献!详情请参阅 [CONTRIBUTING.md](docs/zh/CONTRIBUTING.md)。
|
|
99
123
|
|
|
124
|
+
---
|
|
125
|
+
|
|
100
126
|
## 📄 许可证
|
|
101
127
|
|
|
102
128
|
MIT
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# API Reference
|
|
2
|
+
|
|
3
|
+
## Table of Contents
|
|
4
|
+
|
|
5
|
+
- [Core](#core)
|
|
6
|
+
- [trace / trace_interaction](#trace--trace_interaction)
|
|
7
|
+
- [configure_flow](#configure_flow)
|
|
8
|
+
- [LogContext](#logcontext)
|
|
9
|
+
- [Event (Abstract Base Class)](#event-abstract-base-class)
|
|
10
|
+
- [FlowEvent](#flowevent)
|
|
11
|
+
- [BaseFormatter (Abstract Base Class)](#baseformatter-abstract-base-class)
|
|
12
|
+
- [MermaidFormatter](#mermaidformatter)
|
|
13
|
+
- [MermaidFileHandler](#mermaidfilehandler)
|
|
14
|
+
- [AsyncMermaidHandler](#asyncmermaidhandler)
|
|
15
|
+
- [Integrations](#integrations)
|
|
16
|
+
- [MermaidTraceMiddleware (FastAPI)](#mermaidtracemiddleware-fastapi)
|
|
17
|
+
|
|
18
|
+
## Core
|
|
19
|
+
|
|
20
|
+
### `trace` / `trace_interaction`
|
|
21
|
+
|
|
22
|
+
Decorator to trace function execution. Can be used with or without arguments.
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
# Simple usage
|
|
26
|
+
@trace
|
|
27
|
+
def my_func(): ...
|
|
28
|
+
|
|
29
|
+
# Detailed usage
|
|
30
|
+
@trace(source="Client", target="Server", action="Login", capture_args=False)
|
|
31
|
+
def login(username): ...
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Arguments:**
|
|
35
|
+
- `source` (Optional[str]): The caller participant name. If `None`, inferred from `contextvars`.
|
|
36
|
+
- `target` (Optional[str]): The callee participant name. If `None`, inferred from class name (if method) or module name.
|
|
37
|
+
- `name` (Optional[str]): Alias for `target`. Explicitly sets the participant name.
|
|
38
|
+
- `action` (Optional[str]): Description of the interaction. If `None`, defaults to formatted function name (e.g., `process_payment` -> "Process Payment").
|
|
39
|
+
- `capture_args` (bool): Whether to log arguments and return values. Defaults to `True`. Set to `False` for sensitive data.
|
|
40
|
+
- `max_arg_length` (int): Maximum length of string representation for arguments. Defaults to 50.
|
|
41
|
+
- `max_arg_depth` (int): Maximum depth for nested structures in argument representation. Defaults to 1.
|
|
42
|
+
|
|
43
|
+
### `configure_flow`
|
|
44
|
+
|
|
45
|
+
Configures the global logger to output to a Mermaid file. This should be called once at application startup.
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
def configure_flow(
|
|
49
|
+
output_file: str = "flow.mmd",
|
|
50
|
+
handlers: Optional[List[logging.Handler]] = None,
|
|
51
|
+
append: bool = False,
|
|
52
|
+
async_mode: bool = False
|
|
53
|
+
) -> logging.Logger
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Arguments:**
|
|
57
|
+
- `output_file` (str): Path to the `.mmd` output file. Defaults to "flow.mmd".
|
|
58
|
+
- `handlers` (List[logging.Handler]): Optional list of custom logging handlers. If provided, `output_file` is ignored unless you include `MermaidFileHandler` manually.
|
|
59
|
+
- `append` (bool): If `True`, adds new handlers without removing existing ones. Defaults to `False`.
|
|
60
|
+
- `async_mode` (bool): If `True`, uses a non-blocking background thread for logging (QueueHandler). Recommended for production. Defaults to `False`.
|
|
61
|
+
|
|
62
|
+
### `LogContext`
|
|
63
|
+
|
|
64
|
+
Manages execution context (like thread-local storage) to track caller/callee relationships and trace IDs across async tasks and threads.
|
|
65
|
+
|
|
66
|
+
**Methods:**
|
|
67
|
+
- `LogContext.current_trace_id() -> str`: Get or generate the current Trace ID.
|
|
68
|
+
- `LogContext.current_participant() -> str`: Get the current active participant.
|
|
69
|
+
- `LogContext.scope(data)`: Synchronous context manager to temporarily update context.
|
|
70
|
+
- `LogContext.ascope(data)`: Asynchronous context manager (`async with`) to temporarily update context.
|
|
71
|
+
|
|
72
|
+
### `Event` (Abstract Base Class)
|
|
73
|
+
|
|
74
|
+
Abstract base class for all event types, providing a common interface for different types of events.
|
|
75
|
+
|
|
76
|
+
**Methods:**
|
|
77
|
+
- `get_source() -> str`: Get the source of the event.
|
|
78
|
+
- `get_target() -> str`: Get the target of the event.
|
|
79
|
+
- `get_action() -> str`: Get the action name of the event.
|
|
80
|
+
- `get_message() -> str`: Get the message text of the event.
|
|
81
|
+
- `get_timestamp() -> float`: Get the timestamp of the event.
|
|
82
|
+
- `get_trace_id() -> str`: Get the trace ID of the event.
|
|
83
|
+
|
|
84
|
+
### `FlowEvent`
|
|
85
|
+
|
|
86
|
+
Represents a single interaction or step in the execution flow, inheriting from `Event`.
|
|
87
|
+
|
|
88
|
+
**Attributes:**
|
|
89
|
+
- `source` (str): The name of the participant initiating the action.
|
|
90
|
+
- `target` (str): The name of the participant receiving the action.
|
|
91
|
+
- `action` (str): A short, human-readable name for the operation.
|
|
92
|
+
- `message` (str): The actual text label displayed on the diagram arrow.
|
|
93
|
+
- `trace_id` (str): Unique identifier for the trace session.
|
|
94
|
+
- `timestamp` (float): Unix timestamp of when the event occurred.
|
|
95
|
+
- `is_return` (bool): Flag indicating if this is a response arrow.
|
|
96
|
+
- `is_error` (bool): Flag indicating if an exception occurred.
|
|
97
|
+
- `error_message` (Optional[str]): Detailed error text if `is_error` is True.
|
|
98
|
+
- `params` (Optional[str]): Stringified representation of function arguments.
|
|
99
|
+
- `result` (Optional[str]): Stringified representation of the return value.
|
|
100
|
+
|
|
101
|
+
### `BaseFormatter` (Abstract Base Class)
|
|
102
|
+
|
|
103
|
+
Abstract base class for all event formatters, providing a common interface for different output formats.
|
|
104
|
+
|
|
105
|
+
**Methods:**
|
|
106
|
+
- `format_event(event: Event) -> str`: Format an Event into the desired output string.
|
|
107
|
+
- `format(record: logging.LogRecord) -> str`: Format a logging record containing an event.
|
|
108
|
+
|
|
109
|
+
### `MermaidFormatter`
|
|
110
|
+
|
|
111
|
+
Custom formatter to convert Events into Mermaid sequence diagram syntax, inheriting from `BaseFormatter`.
|
|
112
|
+
|
|
113
|
+
**Methods:**
|
|
114
|
+
- `format_event(event: Event) -> str`: Converts an Event into a Mermaid syntax string.
|
|
115
|
+
|
|
116
|
+
### `MermaidFileHandler`
|
|
117
|
+
|
|
118
|
+
A custom logging handler that writes `Event` objects to a Mermaid (.mmd) file.
|
|
119
|
+
|
|
120
|
+
**Features:**
|
|
121
|
+
- Thread-safe file writing using locks
|
|
122
|
+
- Automatic Mermaid header management
|
|
123
|
+
- Support for both overwrite and append modes
|
|
124
|
+
- Delay writing support for better performance
|
|
125
|
+
|
|
126
|
+
### `AsyncMermaidHandler`
|
|
127
|
+
|
|
128
|
+
A non-blocking logging handler that uses a background thread to write logs.
|
|
129
|
+
|
|
130
|
+
**Arguments:**
|
|
131
|
+
- `handlers` (List[logging.Handler]): A list of handlers that should receive the logs from the queue.
|
|
132
|
+
- `queue_size` (int): The maximum size of the queue. Default is 1000.
|
|
133
|
+
|
|
134
|
+
**Features:**
|
|
135
|
+
- Queue-based logging with configurable size limit
|
|
136
|
+
- Built-in drop policy for when queue is full
|
|
137
|
+
- Automatic queue flushing on application exit
|
|
138
|
+
|
|
139
|
+
## Integrations
|
|
140
|
+
|
|
141
|
+
### `MermaidTraceMiddleware` (FastAPI)
|
|
142
|
+
|
|
143
|
+
Middleware for automatic HTTP request tracing. Captures request path, method, status code, and timing.
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from mermaid_trace.integrations.fastapi import MermaidTraceMiddleware
|
|
147
|
+
|
|
148
|
+
app.add_middleware(MermaidTraceMiddleware, app_name="MyAPI")
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Arguments:**
|
|
152
|
+
- `app`: The FastAPI/Starlette application.
|
|
153
|
+
- `app_name` (str): The name of the participant representing this application in the diagram.
|
|
154
|
+
|
|
155
|
+
**Headers Support:**
|
|
156
|
+
- `X-Source`: If sent by the client, sets the source participant name.
|
|
157
|
+
- `X-Trace-ID`: If sent, uses this ID for the trace session; otherwise generates a new UUID.
|
|
@@ -5,12 +5,42 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.4.1] - 2026-01-26
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **Abstract Event Model**: Introduced `Event` abstract base class and `BaseFormatter` interface for better extensibility and support for multiple output formats.
|
|
12
|
+
- **Enhanced Async Handler**: Added queue size limit (`queue_size=1000`) with drop policy to prevent memory overflow in high-traffic scenarios.
|
|
13
|
+
- **Improved Exception Handling**: Enhanced exception logging to include full stack traces and error details.
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
- **Context Loss Issue**: Fixed `LogContext._get_store()` method to properly initialize `contextvar` when no context exists, preventing subsequent `LookupError` exceptions.
|
|
17
|
+
- **Concurrency Safety**: Added thread locks in `MermaidFileHandler._write_header()` to prevent race conditions when writing file headers with `delay=True`.
|
|
18
|
+
|
|
19
|
+
### Improved
|
|
20
|
+
- **Architecture Design**: Decoupled components by introducing abstract interfaces, reducing tight coupling between `FlowEvent` and Mermaid-specific formatting.
|
|
21
|
+
- **Test Coverage**: Increased test coverage to 90.17% by adding comprehensive test cases for the new abstract classes.
|
|
22
|
+
- **Code Maintainability**: Added detailed English annotations to all code files, improving readability and developer experience.
|
|
23
|
+
|
|
24
|
+
## [0.4.0] - 2026-01-26
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
- **Async Mode**: Introduced `async_mode=True` in `configure_flow` to offload log writing to a background thread, eliminating I/O blocking in the main application loop.
|
|
28
|
+
- **Data Privacy**: Added `capture_args=False` to `@trace` to prevent sensitive arguments from being logged.
|
|
29
|
+
- **Argument Truncation**: Added `max_arg_length` and `max_arg_depth` to `@trace` to control the size of logged data structures.
|
|
30
|
+
- **Explicit Naming**: Added `name` (or `target` alias) parameter to `@trace` for explicitly setting the participant name, overriding automatic inference.
|
|
31
|
+
- **Flexible Configuration**: Updated `configure_flow` to accept a list of custom handlers and an `append` flag, allowing better integration with existing logging setups.
|
|
32
|
+
|
|
33
|
+
### Improved
|
|
34
|
+
- **Test Coverage**: Achieved >90% test coverage with a comprehensive new test suite covering unit, integration, and concurrency scenarios.
|
|
35
|
+
- **PyPI Compliance**: Switched to dynamic versioning via `hatch-vcs` and improved package metadata and artifact inclusion.
|
|
36
|
+
|
|
8
37
|
## [0.3.1] - 2026-01-26
|
|
9
38
|
|
|
10
39
|
### Fixed
|
|
11
40
|
- **CI/CD**: Resolved test coverage reporting issues in GitHub Actions by standardizing on editable installs (`pip install -e .[dev]`) across all workflows.
|
|
12
41
|
- **CI/CD**: Aligned coverage configuration in `pyproject.toml` to correctly target the source directory (`src/mermaid_trace`).
|
|
13
42
|
- **Docs**: Fixed badge links in README to use consistent style and valid sources.
|
|
43
|
+
- **Compatibility**: Officially added support for Python 3.13 and 3.14 in project classifiers and CI workflows.
|
|
14
44
|
|
|
15
45
|
## [0.3.0] - 2026-01-26
|
|
16
46
|
|
|
@@ -29,7 +29,12 @@ The following is a set of guidelines for contributing to MermaidTrace and its pa
|
|
|
29
29
|
|
|
30
30
|
4. **Run tests**:
|
|
31
31
|
```bash
|
|
32
|
+
# Run all tests
|
|
32
33
|
pytest
|
|
34
|
+
|
|
35
|
+
# Run tests across multiple Python versions (requires tox)
|
|
36
|
+
pip install tox
|
|
37
|
+
tox
|
|
33
38
|
```
|
|
34
39
|
|
|
35
40
|
## Styleguides
|
|
@@ -38,12 +43,17 @@ The following is a set of guidelines for contributing to MermaidTrace and its pa
|
|
|
38
43
|
|
|
39
44
|
- All Python code is linted with `ruff`.
|
|
40
45
|
- All Python code is type-checked with `mypy`.
|
|
46
|
+
- We use `hatch` for build management and `hatch-vcs` for dynamic versioning.
|
|
41
47
|
|
|
42
48
|
To run checks locally:
|
|
43
49
|
|
|
44
50
|
```bash
|
|
51
|
+
# Using tox (recommended)
|
|
52
|
+
tox -e lint
|
|
53
|
+
|
|
54
|
+
# Or manually
|
|
45
55
|
ruff check src tests
|
|
46
|
-
mypy src
|
|
56
|
+
mypy src/mermaid_trace
|
|
47
57
|
```
|
|
48
58
|
|
|
49
59
|
## Pull Requests
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# User Guide
|
|
2
2
|
|
|
3
|
+
## Table of Contents
|
|
4
|
+
|
|
5
|
+
- [Introduction](#introduction)
|
|
6
|
+
- [How It Works](#how-it-works)
|
|
7
|
+
- [Concurrency & Trace IDs](#concurrency--trace-ids)
|
|
8
|
+
- [Context Inference](#context-inference)
|
|
9
|
+
- [Advanced Configuration](#advanced-configuration)
|
|
10
|
+
- [Async Mode (Performance)](#async-mode-performance)
|
|
11
|
+
- [Data Capture Control](#data-capture-control)
|
|
12
|
+
- [Explicit Naming](#explicit-naming)
|
|
13
|
+
- [Flexible Handler Configuration](#flexible-handler-configuration)
|
|
14
|
+
- [CLI Viewer](#cli-viewer)
|
|
15
|
+
|
|
3
16
|
## Introduction
|
|
4
17
|
|
|
5
18
|
MermaidTrace bridges the gap between code execution and architectural visualization. Unlike static analysis tools, it traces *actual* runtime calls, giving you a true picture of your system's behavior.
|
|
@@ -41,6 +54,47 @@ MermaidTrace uses Python's `contextvars` to track the "Current Participant".
|
|
|
41
54
|
|
|
42
55
|
This means you usually only need to set the `source` on the *entry point* (the first function).
|
|
43
56
|
|
|
57
|
+
## Advanced Configuration
|
|
58
|
+
|
|
59
|
+
### Async Mode (Performance)
|
|
60
|
+
For high-throughput production environments, enable `async_mode` to offload file writing to a background thread. This ensures your application's main thread is never blocked by disk I/O.
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
configure_flow("flow.mmd", async_mode=True)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Data Capture Control
|
|
67
|
+
You can control how function arguments and return values are recorded to keep diagrams clean and secure.
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
# Hide sensitive data
|
|
71
|
+
@trace(capture_args=False)
|
|
72
|
+
def login(password):
|
|
73
|
+
pass
|
|
74
|
+
|
|
75
|
+
# Truncate long strings (default: 50 chars)
|
|
76
|
+
@trace(max_arg_length=10)
|
|
77
|
+
def process_large_data(data):
|
|
78
|
+
pass
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Explicit Naming
|
|
82
|
+
If the automatic class/function name inference isn't what you want, you can explicitly name the participant.
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
@trace(name="AuthService") # "AuthService" will appear in the diagram
|
|
86
|
+
def login():
|
|
87
|
+
pass
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Flexible Handler Configuration
|
|
91
|
+
You can add MermaidTrace to an existing logging setup or append multiple handlers.
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
# Append to existing handlers instead of clearing them
|
|
95
|
+
configure_flow("flow.mmd", append=True)
|
|
96
|
+
```
|
|
97
|
+
|
|
44
98
|
## CLI Viewer
|
|
45
99
|
|
|
46
100
|
To view your diagrams, use the CLI:
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# API 参考文档
|
|
2
|
+
|
|
3
|
+
## 目录
|
|
4
|
+
|
|
5
|
+
- [核心功能 (Core)](#核心功能-core)
|
|
6
|
+
- [trace / trace_interaction](#trace--trace_interaction)
|
|
7
|
+
- [configure_flow](#configure_flow)
|
|
8
|
+
- [LogContext](#logcontext)
|
|
9
|
+
- [Event(抽象基类)](#event抽象基类)
|
|
10
|
+
- [FlowEvent](#flowevent)
|
|
11
|
+
- [BaseFormatter(抽象基类)](#baseformatter抽象基类)
|
|
12
|
+
- [MermaidFormatter](#mermaidformatter)
|
|
13
|
+
- [MermaidFileHandler](#mermaidfilehandler)
|
|
14
|
+
- [AsyncMermaidHandler](#asyncmermaidhandler)
|
|
15
|
+
- [集成 (Integrations)](#集成-integrations)
|
|
16
|
+
- [MermaidTraceMiddleware (FastAPI)](#mermaidtracemiddleware-fastapi)
|
|
17
|
+
|
|
18
|
+
## 核心功能 (Core)
|
|
19
|
+
|
|
20
|
+
### `trace` / `trace_interaction`
|
|
21
|
+
|
|
22
|
+
用于追踪函数执行的装饰器。可以带参数使用,也可以不带参数使用。
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
# 简单用法
|
|
26
|
+
@trace
|
|
27
|
+
def my_func(): ...
|
|
28
|
+
|
|
29
|
+
# 详细用法
|
|
30
|
+
@trace(source="Client", target="Server", action="Login", capture_args=False)
|
|
31
|
+
def login(username): ...
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**参数:**
|
|
35
|
+
- `source` (Optional[str]): 调用方参与者名称。如果为 `None`,则从 `contextvars` 推断。
|
|
36
|
+
- `target` (Optional[str]): 被调用方参与者名称。如果为 `None`,则从类名(如果是方法)或模块名推断。
|
|
37
|
+
- `name` (Optional[str]): `target` 的别名。显式设置参与者名称。
|
|
38
|
+
- `action` (Optional[str]): 交互描述。如果为 `None`,默认为格式化后的函数名(例如 `process_payment` -> "Process Payment")。
|
|
39
|
+
- `capture_args` (bool): 是否记录参数和返回值。默认为 `True`。对于敏感数据可设置为 `False`。
|
|
40
|
+
- `max_arg_length` (int): 参数字符串表示的最大长度。默认为 50。
|
|
41
|
+
- `max_arg_depth` (int): 参数嵌套结构表示的最大深度。默认为 1。
|
|
42
|
+
|
|
43
|
+
### `configure_flow`
|
|
44
|
+
|
|
45
|
+
配置全局日志记录器以输出到 Mermaid 文件。应在应用程序启动时调用一次。
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
def configure_flow(
|
|
49
|
+
output_file: str = "flow.mmd",
|
|
50
|
+
handlers: Optional[List[logging.Handler]] = None,
|
|
51
|
+
append: bool = False,
|
|
52
|
+
async_mode: bool = False
|
|
53
|
+
) -> logging.Logger
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**参数:**
|
|
57
|
+
- `output_file` (str): `.mmd` 输出文件的路径。默认为 "flow.mmd"。
|
|
58
|
+
- `handlers` (List[logging.Handler]): 可选的自定义日志处理器列表。如果提供,`output_file` 将被忽略,除非您手动包含了 `MermaidFileHandler`。
|
|
59
|
+
- `append` (bool): 如果为 `True`,则添加新的处理器而不移除现有的。默认为 `False`。
|
|
60
|
+
- `async_mode` (bool): 如果为 `True`,使用非阻塞后台线程进行日志记录 (QueueHandler)。推荐用于生产环境。默认为 `False`。
|
|
61
|
+
|
|
62
|
+
### `LogContext`
|
|
63
|
+
|
|
64
|
+
管理执行上下文(类似线程本地存储),用于在异步任务和线程之间追踪调用方/被调用方关系和 Trace ID。
|
|
65
|
+
|
|
66
|
+
**方法:**
|
|
67
|
+
- `LogContext.current_trace_id() -> str`: 获取或生成当前的 Trace ID。
|
|
68
|
+
- `LogContext.current_participant() -> str`: 获取当前活跃的参与者。
|
|
69
|
+
- `LogContext.scope(data)`: 同步上下文管理器,用于临时更新上下文。
|
|
70
|
+
- `LogContext.ascope(data)`: 异步上下文管理器 (`async with`),用于临时更新上下文。
|
|
71
|
+
|
|
72
|
+
### `Event`(抽象基类)
|
|
73
|
+
|
|
74
|
+
所有事件类型的抽象基类,为不同类型的事件提供通用接口。
|
|
75
|
+
|
|
76
|
+
**方法:**
|
|
77
|
+
- `get_source() -> str`: 获取事件的来源。
|
|
78
|
+
- `get_target() -> str`: 获取事件的目标。
|
|
79
|
+
- `get_action() -> str`: 获取事件的动作名称。
|
|
80
|
+
- `get_message() -> str`: 获取事件的消息文本。
|
|
81
|
+
- `get_timestamp() -> float`: 获取事件的时间戳。
|
|
82
|
+
- `get_trace_id() -> str`: 获取事件的追踪 ID。
|
|
83
|
+
|
|
84
|
+
### `FlowEvent`
|
|
85
|
+
|
|
86
|
+
表示执行流程中的单个交互或步骤,继承自 `Event`。
|
|
87
|
+
|
|
88
|
+
**属性:**
|
|
89
|
+
- `source` (str): 发起动作的参与者名称。
|
|
90
|
+
- `target` (str): 接收动作的参与者名称。
|
|
91
|
+
- `action` (str): 操作的简短可读名称。
|
|
92
|
+
- `message` (str): 显示在图表箭头上的实际文本标签。
|
|
93
|
+
- `trace_id` (str): 追踪会话的唯一标识符。
|
|
94
|
+
- `timestamp` (float): 事件发生时的 Unix 时间戳。
|
|
95
|
+
- `is_return` (bool): 指示这是否为响应箭头的标志。
|
|
96
|
+
- `is_error` (bool): 指示是否发生异常的标志。
|
|
97
|
+
- `error_message` (Optional[str]): 如果 `is_error` 为 True,则包含详细的错误文本。
|
|
98
|
+
- `params` (Optional[str]): 函数参数的字符串表示。
|
|
99
|
+
- `result` (Optional[str]): 返回值的字符串表示。
|
|
100
|
+
|
|
101
|
+
### `BaseFormatter`(抽象基类)
|
|
102
|
+
|
|
103
|
+
所有事件格式化器的抽象基类,为不同的输出格式提供通用接口。
|
|
104
|
+
|
|
105
|
+
**方法:**
|
|
106
|
+
- `format_event(event: Event) -> str`: 将事件格式化为所需的输出字符串。
|
|
107
|
+
- `format(record: logging.LogRecord) -> str`: 格式化包含事件的日志记录。
|
|
108
|
+
|
|
109
|
+
### `MermaidFormatter`
|
|
110
|
+
|
|
111
|
+
将事件转换为 Mermaid 时序图语法的自定义格式化器,继承自 `BaseFormatter`。
|
|
112
|
+
|
|
113
|
+
**方法:**
|
|
114
|
+
- `format_event(event: Event) -> str`: 将事件转换为 Mermaid 语法字符串。
|
|
115
|
+
|
|
116
|
+
### `MermaidFileHandler`
|
|
117
|
+
|
|
118
|
+
将 `Event` 对象写入 Mermaid (.mmd) 文件的自定义日志处理器。
|
|
119
|
+
|
|
120
|
+
**特性:**
|
|
121
|
+
- 使用锁确保线程安全的文件写入
|
|
122
|
+
- 自动管理 Mermaid 文件头
|
|
123
|
+
- 支持覆盖和追加两种模式
|
|
124
|
+
- 支持延迟写入以提高性能
|
|
125
|
+
|
|
126
|
+
### `AsyncMermaidHandler`
|
|
127
|
+
|
|
128
|
+
使用后台线程写入日志的非阻塞日志处理器。
|
|
129
|
+
|
|
130
|
+
**参数:**
|
|
131
|
+
- `handlers` (List[logging.Handler]): 应该从队列接收日志的处理器列表。
|
|
132
|
+
- `queue_size` (int): 队列的最大大小。默认为 1000。
|
|
133
|
+
|
|
134
|
+
**特性:**
|
|
135
|
+
- 基于队列的日志记录,具有可配置的大小限制
|
|
136
|
+
- 队列已满时的内置丢弃策略
|
|
137
|
+
- 应用程序退出时自动刷新队列
|
|
138
|
+
|
|
139
|
+
## 集成 (Integrations)
|
|
140
|
+
|
|
141
|
+
### `MermaidTraceMiddleware` (FastAPI)
|
|
142
|
+
|
|
143
|
+
用于自动 HTTP 请求追踪的中间件。捕获请求路径、方法、状态码和耗时。
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from mermaid_trace.integrations.fastapi import MermaidTraceMiddleware
|
|
147
|
+
|
|
148
|
+
app.add_middleware(MermaidTraceMiddleware, app_name="MyAPI")
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**参数:**
|
|
152
|
+
- `app`: FastAPI/Starlette 应用程序实例。
|
|
153
|
+
- `app_name` (str): 在图表中代表此应用程序的参与者名称。
|
|
154
|
+
|
|
155
|
+
**Headers 支持:**
|
|
156
|
+
- `X-Source`: 如果客户端发送此 Header,则设置源参与者名称。
|
|
157
|
+
- `X-Trace-ID`: 如果发送此 Header,则使用此 ID 进行追踪会话;否则生成一个新的 UUID。
|