mermaid-trace 0.4.1__tar.gz → 0.5.3.post0__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.
Files changed (148) hide show
  1. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/.github/workflows/ci.yml +1 -1
  2. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/.github/workflows/release.yml +3 -0
  3. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/PKG-INFO +57 -5
  4. mermaid_trace-0.5.3.post0/README.md +170 -0
  5. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/README_CN.md +55 -11
  6. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/docs/en/API.md +56 -8
  7. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/docs/en/CHANGELOG.md +47 -0
  8. mermaid_trace-0.5.3.post0/docs/en/USER_GUIDE.md +285 -0
  9. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/docs/zh/API.md +56 -8
  10. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/docs/zh/CHANGELOG.md +55 -0
  11. mermaid_trace-0.5.3.post0/docs/zh/UPDATE_LOG.md +106 -0
  12. mermaid_trace-0.5.3.post0/docs/zh/UPDATE_SUMMARY.md +22 -0
  13. mermaid_trace-0.5.3.post0/docs/zh/USER_GUIDE.md +289 -0
  14. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/__init__.md +106 -0
  15. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/cli.md +115 -0
  16. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/core/__init__.md +15 -0
  17. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/core/config.md +79 -0
  18. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/core/context.md +180 -0
  19. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/core/decorators.md +488 -0
  20. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/core/events.md +77 -0
  21. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/core/formatter.md +274 -0
  22. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/core/utils.md +103 -0
  23. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/handlers/async_handler.md +115 -0
  24. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/handlers/mermaid_handler.md +217 -0
  25. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/integrations/__init__.md +14 -0
  26. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/integrations/fastapi.md +169 -0
  27. mermaid_trace-0.5.3.post0/examples/01_basic_usage.py +46 -0
  28. mermaid_trace-0.5.3.post0/examples/02_advanced_instrumentation.py +50 -0
  29. mermaid_trace-0.5.3.post0/examples/03_async_concurrency.py +37 -0
  30. mermaid_trace-0.5.3.post0/examples/04_error_handling.py +38 -0
  31. mermaid_trace-0.5.3.post0/examples/05_intelligent_collapsing.py +31 -0
  32. mermaid_trace-0.5.3.post0/examples/06_fastapi_integration.py +46 -0
  33. mermaid_trace-0.5.3.post0/examples/07_full_stack_app.py +126 -0
  34. mermaid_trace-0.5.3.post0/examples/08-log-rotation.py +93 -0
  35. mermaid_trace-0.5.3.post0/examples/README.md +62 -0
  36. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/08-log-rotation.mmd +20 -0
  37. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/08-log-rotation.mmd.1 +28 -0
  38. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/08-log-rotation.mmd.2 +28 -0
  39. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/08-log-rotation.mmd.3 +28 -0
  40. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/08-log-rotation.mmd.4 +28 -0
  41. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/08-log-rotation.mmd.5 +28 -0
  42. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/async_flow.mmd +11 -0
  43. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/basic_flow.mmd +10 -0
  44. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/collapsed_flow.mmd +8 -0
  45. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/error_handling.mmd +12 -0
  46. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/fastapi_trace.mmd +9 -0
  47. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/full_stack_app.mmd +12 -0
  48. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/instrumentation_demo.mmd +10 -0
  49. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/core/config_override/dummy.mmd +58 -0
  50. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/handlers/handlers/append.mmd +3 -0
  51. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/handlers/handlers/async_flow.mmd +5 -0
  52. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/handlers/handlers/delay.mmd +5 -0
  53. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/handlers/handlers/flush_flow.mmd +5 -0
  54. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/handlers/handlers/test_flow.mmd +5 -0
  55. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/integrations/integration_fastapi/api_flow.mmd +6 -0
  56. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/overwrite_logic/test_overwrite_default.mmd +6 -0
  57. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/overwrite_logic/test_overwrite_false.mmd +6 -0
  58. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/scenarios/basic_flow/basic_flow.mmd +7 -0
  59. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/scenarios/concurrency/concurrency.mmd +6 -0
  60. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/scenarios/concurrency/trace_ids.mmd +6 -0
  61. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/scenarios/edge_cases/edge.mmd +7 -0
  62. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/scenarios/performance/bench_False.mmd +6 -0
  63. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/scenarios/performance/bench_True.mmd +6 -0
  64. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/scenarios/performance/overhead.mmd +6 -0
  65. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/pyproject.toml +4 -1
  66. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/src/mermaid_trace/__init__.py +53 -21
  67. mermaid_trace-0.5.3.post0/src/mermaid_trace/cli.py +357 -0
  68. mermaid_trace-0.5.3.post0/src/mermaid_trace/core/config.py +55 -0
  69. mermaid_trace-0.5.3.post0/src/mermaid_trace/core/decorators.py +675 -0
  70. mermaid_trace-0.5.3.post0/src/mermaid_trace/core/events.py +60 -0
  71. mermaid_trace-0.5.3.post0/src/mermaid_trace/core/formatter.py +309 -0
  72. mermaid_trace-0.5.3.post0/src/mermaid_trace/core/utils.py +96 -0
  73. mermaid_trace-0.5.3.post0/src/mermaid_trace/handlers/async_handler.py +181 -0
  74. mermaid_trace-0.5.3.post0/src/mermaid_trace/handlers/mermaid_handler.py +185 -0
  75. mermaid_trace-0.5.3.post0/src/mermaid_trace/integrations/__init__.py +4 -0
  76. mermaid_trace-0.5.3.post0/src/mermaid_trace/integrations/fastapi.py +221 -0
  77. mermaid_trace-0.5.3.post0/test.db +0 -0
  78. mermaid_trace-0.5.3.post0/tests/conftest.py +37 -0
  79. mermaid_trace-0.5.3.post0/tests/core/test_cli_coverage.py +75 -0
  80. mermaid_trace-0.5.3.post0/tests/core/test_config_coverage.py +35 -0
  81. mermaid_trace-0.5.3.post0/tests/core/test_config_override.py +73 -0
  82. mermaid_trace-0.5.3.post0/tests/core/test_decorators_coverage.py +101 -0
  83. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/tests/core/test_decorators_extra.py +8 -5
  84. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/tests/core/test_events.py +10 -21
  85. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/tests/core/test_formatter.py +10 -5
  86. mermaid_trace-0.5.3.post0/tests/core/test_formatter_coverage.py +211 -0
  87. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/tests/core/test_formatter_extra.py +0 -18
  88. mermaid_trace-0.5.3.post0/tests/core/test_utils.py +71 -0
  89. mermaid_trace-0.5.3.post0/tests/core/test_utils_coverage.py +114 -0
  90. mermaid_trace-0.5.3.post0/tests/handlers/test_async_handler_coverage.py +55 -0
  91. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/tests/handlers/test_handlers.py +68 -21
  92. mermaid_trace-0.5.3.post0/tests/handlers/test_mermaid_handler_coverage.py +28 -0
  93. mermaid_trace-0.5.3.post0/tests/integrations/test_fastapi_coverage.py +29 -0
  94. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/tests/integrations/test_integration_decorators.py +7 -2
  95. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/tests/integrations/test_integration_fastapi.py +6 -2
  96. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/tests/scenarios/test_basic_flow.py +19 -6
  97. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/tests/scenarios/test_concurrency.py +18 -23
  98. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/tests/scenarios/test_edge_cases.py +4 -2
  99. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/tests/scenarios/test_performance.py +15 -7
  100. mermaid_trace-0.4.1/README.md +0 -117
  101. mermaid_trace-0.4.1/docs/en/USER_GUIDE.md +0 -106
  102. mermaid_trace-0.4.1/docs/zh/UPDATE_SUMMARY.md +0 -99
  103. mermaid_trace-0.4.1/docs/zh/USER_GUIDE.md +0 -106
  104. mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/__init__.md +0 -122
  105. mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/cli.md +0 -262
  106. mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/core/context.md +0 -203
  107. mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/core/decorators.md +0 -325
  108. mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/core/events.md +0 -158
  109. mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/core/formatter.md +0 -143
  110. mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/handlers/async_handler.md +0 -124
  111. mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/handlers/mermaid_handler.md +0 -119
  112. mermaid_trace-0.4.1/docs/zh/code_comments/src/mermaid_trace/integrations/fastapi.md +0 -150
  113. mermaid_trace-0.4.1/examples/concurrency_demo.py +0 -46
  114. mermaid_trace-0.4.1/examples/demo.py +0 -38
  115. mermaid_trace-0.4.1/examples/error_handling_demo.py +0 -50
  116. mermaid_trace-0.4.1/examples/nested_demo.py +0 -45
  117. mermaid_trace-0.4.1/flow.mmd +0 -33
  118. mermaid_trace-0.4.1/image/README_CN/1769402097355.png +0 -0
  119. mermaid_trace-0.4.1/improvement_plan.md +0 -253
  120. mermaid_trace-0.4.1/src/mermaid_trace/cli.py +0 -303
  121. mermaid_trace-0.4.1/src/mermaid_trace/core/decorators.py +0 -470
  122. mermaid_trace-0.4.1/src/mermaid_trace/core/events.py +0 -190
  123. mermaid_trace-0.4.1/src/mermaid_trace/core/formatter.py +0 -151
  124. mermaid_trace-0.4.1/src/mermaid_trace/handlers/async_handler.py +0 -105
  125. mermaid_trace-0.4.1/src/mermaid_trace/handlers/mermaid_handler.py +0 -119
  126. mermaid_trace-0.4.1/src/mermaid_trace/integrations/fastapi.py +0 -166
  127. mermaid_trace-0.4.1/tests/conftest.py +0 -12
  128. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/.gitignore +0 -0
  129. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/LICENSE +0 -0
  130. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/SECURITY.md +0 -0
  131. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/docs/en/CONTRIBUTING.md +0 -0
  132. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/docs/en/LICENSE +0 -0
  133. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/docs/zh/CONTRIBUTING.md +0 -0
  134. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/docs/zh/LICENSE +0 -0
  135. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/docs/zh/code_comments/src/mermaid_trace/core/image/context/1769443810901.png +0 -0
  136. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/docs/zh/code_comments/src/mermaid_trace/core/image/context/1769443817389.png +0 -0
  137. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/docs/zh/code_comments/src/mermaid_trace/core/image/context/1769443818915.png +0 -0
  138. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/docs/zh/code_comments/src/mermaid_trace/core/image/context/1769443830665.png +0 -0
  139. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/docs/zh/code_comments/src/mermaid_trace/core/image/context/1769443835553.png +0 -0
  140. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/src/mermaid_trace/core/__init__.py +0 -0
  141. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/src/mermaid_trace/core/context.py +0 -0
  142. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/src/mermaid_trace/py.typed +0 -0
  143. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/tests/__init__.py +0 -0
  144. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/tests/core/__init__.py +0 -0
  145. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/tests/core/test_cli.py +0 -0
  146. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/tests/core/test_context.py +0 -0
  147. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/tests/core/test_context_extra.py +0 -0
  148. {mermaid_trace-0.4.1 → mermaid_trace-0.5.3.post0}/tox.ini +0 -0
@@ -12,7 +12,7 @@ jobs:
12
12
  strategy:
13
13
  fail-fast: true
14
14
  matrix:
15
- python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
15
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
16
16
 
17
17
  steps:
18
18
  - uses: actions/checkout@v4
@@ -9,6 +9,9 @@ jobs:
9
9
  runs-on: ubuntu-latest
10
10
  steps:
11
11
  - uses: actions/checkout@v4
12
+ with:
13
+ fetch-depth: 0
14
+ fetch-tags: true
12
15
  - name: Set up Python
13
16
  uses: actions/setup-python@v5
14
17
  with:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mermaid-trace
3
- Version: 0.4.1
3
+ Version: 0.5.3.post0
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
@@ -39,7 +39,6 @@ Classifier: Programming Language :: Python :: 3.10
39
39
  Classifier: Programming Language :: Python :: 3.11
40
40
  Classifier: Programming Language :: Python :: 3.12
41
41
  Classifier: Programming Language :: Python :: 3.13
42
- Classifier: Programming Language :: Python :: 3.14
43
42
  Classifier: Programming Language :: Python :: Implementation :: CPython
44
43
  Classifier: Programming Language :: Python :: Implementation :: PyPy
45
44
  Classifier: Topic :: Software Development :: Debuggers
@@ -83,18 +82,35 @@ MermaidTrace is a specialized logging tool that automatically generates [Mermaid
83
82
 
84
83
  ## 📚 Documentation
85
84
 
85
+ ### Core Documentation
86
+
86
87
  [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
+ ### Code Comment Documents (Chinese)
90
+
91
+ | Category | Links |
92
+ | :--- | :--- |
93
+ | **Core Modules** | [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) |
94
+ | **Handlers** | [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) |
95
+ | **Integrations** | [FastAPI](docs/zh/code_comments/src/mermaid_trace/integrations/fastapi.md) |
96
+ | **Others** | [init](docs/zh/code_comments/src/mermaid_trace/__init__.md) · [CLI](docs/zh/code_comments/src/mermaid_trace/cli.md) |
97
+
88
98
  ---
89
99
 
90
100
  ## ✨ Key Features
91
101
 
92
102
  - **Decorator-Driven**: Just add `@trace` or `@trace_interaction` to your functions.
103
+ - **Auto-Instrumentation**: Use `@trace_class` to trace a whole class at once.
104
+ - **Third-Party Patching**: Use `patch_object` to trace calls inside external libraries.
93
105
  - **Auto-Diagramming**: Generates `.mmd` files that can be viewed in VS Code, GitHub, or Mermaid Live Editor.
94
106
  - **Async Support**: Works seamlessly with `asyncio` coroutines.
95
107
  - **Context Inference**: Automatically tracks nested calls and infers `source` participants using `contextvars`.
96
- - **FastAPI Integration**: Includes middleware for zero-config HTTP request tracing.
97
- - **CLI Tool**: Built-in viewer to preview diagrams in your browser.
108
+ - **Intelligent Collapsing**: Prevents diagram explosion by collapsing repetitive high-frequency calls and identifying recurring patterns (e.g., loops).
109
+ - **Detailed Exceptions**: Captures full stack traces for errors, displayed in interactive notes.
110
+ - **Simplified Objects**: Automatically cleans up memory addresses (e.g., `<__main__.Obj at 0x...>` -> `<Obj>`) and **groups consecutive identical items** in lists/tuples (e.g., `[<Obj> x 5]`) for cleaner diagrams.
111
+ - **Log Rotation**: Supports `RotatingMermaidFileHandler` for handling long-running systems by splitting logs based on size or time.
112
+ - **FastAPI Integration**: Includes middleware for zero-config HTTP request tracing, supporting distributed tracing via `X-Trace-ID` and `X-Source` headers.
113
+ - **CLI Tool**: Built-in viewer with live-reload to preview diagrams in your browser.
98
114
 
99
115
  ---
100
116
 
@@ -113,7 +129,8 @@ from mermaid_trace import trace, configure_flow
113
129
  import time
114
130
 
115
131
  # 1. Configure output
116
- configure_flow("my_flow.mmd")
132
+ # Recommendation: Store diagrams in a dedicated directory (e.g., mermaid_diagrams/)
133
+ configure_flow("mermaid_diagrams/my_flow.mmd", async_mode=True)
117
134
 
118
135
  # 2. Add decorators
119
136
  @trace(source="Client", target="PaymentService", action="Process Payment")
@@ -130,6 +147,29 @@ def check_balance(amount):
130
147
  process_payment(100)
131
148
  ```
132
149
 
150
+ ### Configuration
151
+
152
+ You can configure global settings via `configure_flow` or environment variables to control performance and behavior.
153
+
154
+ ```python
155
+ configure_flow(
156
+ "flow.mmd",
157
+ overwrite=True, # Overwrite the file on each restart (default: True)
158
+ level=logging.DEBUG,
159
+ queue_size=5000, # Increase buffer for high-throughput
160
+ config_overrides={
161
+ "capture_args": False, # Disable arg capturing for max performance
162
+ "max_string_length": 100 # Increase string truncation limit
163
+ }
164
+ )
165
+ ```
166
+
167
+ **Environment Variables:**
168
+ - `MERMAID_TRACE_CAPTURE_ARGS` (true/false)
169
+ - `MERMAID_TRACE_MAX_STRING_LENGTH` (int)
170
+ - `MERMAID_TRACE_MAX_ARG_DEPTH` (int)
171
+ - `MERMAID_TRACE_QUEUE_SIZE` (int)
172
+
133
173
  ### Nested Calls (Context Inference)
134
174
 
135
175
  You don't need to specify `source` every time. MermaidTrace infers it from the current context.
@@ -167,6 +207,18 @@ Visualize your generated `.mmd` files instantly:
167
207
  mermaid-trace serve my_flow.mmd
168
208
  ```
169
209
 
210
+ ### Examples
211
+
212
+ Check out the [examples/](examples/) directory for a complete set of demos covering all features:
213
+ - **[Basic Usage](examples/01_basic_usage.py)**: Decorators and class methods.
214
+ - **[Advanced Instrumentation](examples/02_advanced_instrumentation.py)**: `@trace_class` and `patch_object` for third-party libraries.
215
+ - **[Async & Concurrency](examples/03_async_concurrency.py)**: Tracing `asyncio` and concurrent tasks.
216
+ - **[Error Handling](examples/04_error_handling.py)**: Stack trace capture and error rendering.
217
+ - **[Intelligent Collapsing](examples/05_intelligent_collapsing.py)**: Keeping diagrams clean in loops.
218
+ - **[FastAPI Integration](examples/06_fastapi_integration.py)**: Middleware for web apps.
219
+ - **[Full Stack App](examples/07_full_stack_app.py)**: Comprehensive example with FastAPI, SQLAlchemy, and Pydantic.
220
+ - **[Log Rotation](examples/08-log-rotation.py)**: Handling long-running processes with file rotation.
221
+
170
222
  ---
171
223
 
172
224
  ## 🤝 Contributing
@@ -0,0 +1,170 @@
1
+ # MermaidTrace: The Python Logger That Draws Diagrams
2
+
3
+ 🌐 **Language**: [English](README.md) | [中文](README_CN.md)
4
+
5
+ [![PyPI version](https://img.shields.io/pypi/v/mermaid-trace.svg?style=flat-square&color=blue)](https://pypi.org/project/mermaid-trace/)
6
+ [![Python Versions](https://img.shields.io/pypi/pyversions/mermaid-trace.svg?style=flat-square&color=blue)](https://pypi.org/project/mermaid-trace/)
7
+ [![License](https://img.shields.io/github/license/xt765/mermaid-trace?style=flat-square)](LICENSE)
8
+ [![CI Status](https://img.shields.io/github/actions/workflow/status/xt765/mermaid-trace/ci.yml?style=flat-square&label=CI)](https://github.com/xt765/mermaid-trace/actions/workflows/ci.yml)
9
+ [![Codecov](https://img.shields.io/codecov/c/github/xt765/mermaid-trace?style=flat-square&logo=codecov)](https://codecov.io/gh/xt765/mermaid-trace)
10
+
11
+ ---
12
+
13
+ ## 📋 Overview
14
+
15
+ **Stop reading logs. Start watching them.**
16
+
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.
18
+
19
+ ---
20
+
21
+ ## 📚 Documentation
22
+
23
+ ### Core Documentation
24
+
25
+ [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)
26
+
27
+ ### Code Comment Documents (Chinese)
28
+
29
+ | Category | Links |
30
+ | :--- | :--- |
31
+ | **Core Modules** | [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
+ | **Handlers** | [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
+ | **Integrations** | [FastAPI](docs/zh/code_comments/src/mermaid_trace/integrations/fastapi.md) |
34
+ | **Others** | [init](docs/zh/code_comments/src/mermaid_trace/__init__.md) · [CLI](docs/zh/code_comments/src/mermaid_trace/cli.md) |
35
+
36
+ ---
37
+
38
+ ## ✨ Key Features
39
+
40
+ - **Decorator-Driven**: Just add `@trace` or `@trace_interaction` to your functions.
41
+ - **Auto-Instrumentation**: Use `@trace_class` to trace a whole class at once.
42
+ - **Third-Party Patching**: Use `patch_object` to trace calls inside external libraries.
43
+ - **Auto-Diagramming**: Generates `.mmd` files that can be viewed in VS Code, GitHub, or Mermaid Live Editor.
44
+ - **Async Support**: Works seamlessly with `asyncio` coroutines.
45
+ - **Context Inference**: Automatically tracks nested calls and infers `source` participants using `contextvars`.
46
+ - **Intelligent Collapsing**: Prevents diagram explosion by collapsing repetitive high-frequency calls and identifying recurring patterns (e.g., loops).
47
+ - **Detailed Exceptions**: Captures full stack traces for errors, displayed in interactive notes.
48
+ - **Simplified Objects**: Automatically cleans up memory addresses (e.g., `<__main__.Obj at 0x...>` -> `<Obj>`) and **groups consecutive identical items** in lists/tuples (e.g., `[<Obj> x 5]`) for cleaner diagrams.
49
+ - **Log Rotation**: Supports `RotatingMermaidFileHandler` for handling long-running systems by splitting logs based on size or time.
50
+ - **FastAPI Integration**: Includes middleware for zero-config HTTP request tracing, supporting distributed tracing via `X-Trace-ID` and `X-Source` headers.
51
+ - **CLI Tool**: Built-in viewer with live-reload to preview diagrams in your browser.
52
+
53
+ ---
54
+
55
+ ## 🚀 Quick Start
56
+
57
+ ### Installation
58
+
59
+ ```bash
60
+ pip install mermaid-trace
61
+ ```
62
+
63
+ ### Basic Usage
64
+
65
+ ```python
66
+ from mermaid_trace import trace, configure_flow
67
+ import time
68
+
69
+ # 1. Configure output
70
+ # Recommendation: Store diagrams in a dedicated directory (e.g., mermaid_diagrams/)
71
+ configure_flow("mermaid_diagrams/my_flow.mmd", async_mode=True)
72
+
73
+ # 2. Add decorators
74
+ @trace(source="Client", target="PaymentService", action="Process Payment")
75
+ def process_payment(amount):
76
+ if check_balance(amount):
77
+ return "Success"
78
+ return "Failed"
79
+
80
+ @trace(source="PaymentService", target="Database", action="Check Balance")
81
+ def check_balance(amount):
82
+ return True
83
+
84
+ # 3. Run your code
85
+ process_payment(100)
86
+ ```
87
+
88
+ ### Configuration
89
+
90
+ You can configure global settings via `configure_flow` or environment variables to control performance and behavior.
91
+
92
+ ```python
93
+ configure_flow(
94
+ "flow.mmd",
95
+ overwrite=True, # Overwrite the file on each restart (default: True)
96
+ level=logging.DEBUG,
97
+ queue_size=5000, # Increase buffer for high-throughput
98
+ config_overrides={
99
+ "capture_args": False, # Disable arg capturing for max performance
100
+ "max_string_length": 100 # Increase string truncation limit
101
+ }
102
+ )
103
+ ```
104
+
105
+ **Environment Variables:**
106
+ - `MERMAID_TRACE_CAPTURE_ARGS` (true/false)
107
+ - `MERMAID_TRACE_MAX_STRING_LENGTH` (int)
108
+ - `MERMAID_TRACE_MAX_ARG_DEPTH` (int)
109
+ - `MERMAID_TRACE_QUEUE_SIZE` (int)
110
+
111
+ ### Nested Calls (Context Inference)
112
+
113
+ You don't need to specify `source` every time. MermaidTrace infers it from the current context.
114
+
115
+ ```python
116
+ @trace(source="Client", target="API")
117
+ def main():
118
+ # Inside here, current participant is "API"
119
+ service_call()
120
+
121
+ @trace(target="Service") # source inferred as "API"
122
+ def service_call():
123
+ pass
124
+ ```
125
+
126
+ ### FastAPI Integration
127
+
128
+ ```python
129
+ from fastapi import FastAPI
130
+ from mermaid_trace.integrations.fastapi import MermaidTraceMiddleware
131
+
132
+ app = FastAPI()
133
+ app.add_middleware(MermaidTraceMiddleware, app_name="MyAPI")
134
+
135
+ @app.get("/")
136
+ async def root():
137
+ return {"message": "Hello World"}
138
+ ```
139
+
140
+ ### CLI Viewer
141
+
142
+ Visualize your generated `.mmd` files instantly:
143
+
144
+ ```bash
145
+ mermaid-trace serve my_flow.mmd
146
+ ```
147
+
148
+ ### Examples
149
+
150
+ Check out the [examples/](examples/) directory for a complete set of demos covering all features:
151
+ - **[Basic Usage](examples/01_basic_usage.py)**: Decorators and class methods.
152
+ - **[Advanced Instrumentation](examples/02_advanced_instrumentation.py)**: `@trace_class` and `patch_object` for third-party libraries.
153
+ - **[Async & Concurrency](examples/03_async_concurrency.py)**: Tracing `asyncio` and concurrent tasks.
154
+ - **[Error Handling](examples/04_error_handling.py)**: Stack trace capture and error rendering.
155
+ - **[Intelligent Collapsing](examples/05_intelligent_collapsing.py)**: Keeping diagrams clean in loops.
156
+ - **[FastAPI Integration](examples/06_fastapi_integration.py)**: Middleware for web apps.
157
+ - **[Full Stack App](examples/07_full_stack_app.py)**: Comprehensive example with FastAPI, SQLAlchemy, and Pydantic.
158
+ - **[Log Rotation](examples/08-log-rotation.py)**: Handling long-running processes with file rotation.
159
+
160
+ ---
161
+
162
+ ## 🤝 Contributing
163
+
164
+ We welcome contributions! Please see [CONTRIBUTING.md](docs/en/CONTRIBUTING.md) for details.
165
+
166
+ ---
167
+
168
+ ## 📄 License
169
+
170
+ MIT
@@ -20,29 +20,35 @@ MermaidTrace 是一个专业的日志工具,能从你的代码执行中自动
20
20
 
21
21
  ## 📚 文档
22
22
 
23
- ### 主要文档
23
+ ### 核心文档
24
24
 
25
25
  [用户指南](docs/zh/USER_GUIDE.md) · [API 参考](docs/zh/API.md) · [贡献指南](docs/zh/CONTRIBUTING.md) · [更新日志](docs/zh/CHANGELOG.md) · [许可证](docs/zh/LICENSE)
26
26
 
27
- ### 代码注释文档
27
+ ### 代码注释文档 (中文)
28
28
 
29
- | 类别 | 链接 |
30
- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
29
+ | 类别 | 链接 |
30
+ | :--- | :--- |
31
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) |
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
35
 
36
36
  ---
37
37
 
38
38
  ## ✨ 核心特性
39
39
 
40
40
  - **装饰器驱动**:只需在函数上添加 `@trace` 或 `@trace_interaction` 即可。
41
+ - **批量追踪**:使用 `@trace_class` 一次性追踪整个类的方法。
42
+ - **第三方库追踪**:使用 `patch_object` 对外部库方法做 patch 并加入追踪。
41
43
  - **自动绘图**:生成 `.mmd` 文件,可在 VS Code、GitHub 或 Mermaid Live Editor 中查看。
42
- - **异步支持**:无缝支持 `asyncio` 协程。
44
+ - **异步支持**:无缝支持 `asyncio`协程。
43
45
  - **上下文推断**:利用 `contextvars` 自动追踪嵌套调用并推断 `source`(调用方)参与者。
44
- - **FastAPI 集成**:内置中间件,实现零配置的 HTTP 请求追踪。
45
- - **CLI 工具**:内置查看器,可在浏览器中即时预览图表。
46
+ - **智能折叠**:通过折叠重复的高频调用和识别循环模式(如循环调用),防止时序图过载。
47
+ - **详细异常堆栈**:自动捕获完整的错误堆栈追踪,并在图表中通过 Note 显示。
48
+ - **对象显示优化**:自动清理内存地址(例如 `<__main__.Obj at 0x...>` -> `<Obj>`),并**自动合并列表/元组中连续的相同项**(例如 `[<Obj> x 5]`),使图表更整洁。
49
+ - **日志轮转**:支持 `RotatingMermaidFileHandler`,通过按大小或时间切割日志文件,轻松应对长运行系统的日志膨胀问题。
50
+ - **FastAPI 集成**:内置中间件,实现零配置的 HTTP 请求追踪,支持通过 `X-Trace-ID` 和 `X-Source` 请求头进行分布式追踪。
51
+ - **CLI 工具**:内置带热重载功能的查看器,可在浏览器中即时预览图表。
46
52
 
47
53
  ---
48
54
 
@@ -61,7 +67,8 @@ from mermaid_trace import trace, configure_flow
61
67
  import time
62
68
 
63
69
  # 1. 配置输出文件
64
- configure_flow("my_flow.mmd")
70
+ # 建议将图表存放在专门的目录中(如 mermaid_diagrams/)以保持项目整洁。
71
+ configure_flow("mermaid_diagrams/my_flow.mmd", async_mode=True)
65
72
 
66
73
  # 2. 添加装饰器
67
74
  @trace(source="Client", target="PaymentService", action="Process Payment")
@@ -78,6 +85,30 @@ def check_balance(amount):
78
85
  process_payment(100)
79
86
  ```
80
87
 
88
+ ### 全局配置
89
+
90
+ 你可以通过 `configure_flow` 或环境变量来配置全局设置,以控制性能和行为。
91
+
92
+ ```python
93
+ configure_flow(
94
+ "flow.mmd",
95
+ overwrite=True, # 每次运行是否覆盖原文件(默认为 True)
96
+ level=logging.DEBUG,
97
+ queue_size=5000, # 增加队列缓冲区以应对高并发
98
+ config_overrides={
99
+ "capture_args": False, # 关闭参数捕获以获得最高性能
100
+ "max_string_length": 100 # 增加字符串截断长度
101
+ }
102
+ )
103
+ ```
104
+
105
+ **环境变量支持:**
106
+
107
+ - `MERMAID_TRACE_CAPTURE_ARGS` (true/false)
108
+ - `MERMAID_TRACE_MAX_STRING_LENGTH` (int)
109
+ - `MERMAID_TRACE_MAX_ARG_DEPTH` (int)
110
+ - `MERMAID_TRACE_QUEUE_SIZE` (int)
111
+
81
112
  ### 嵌套调用(上下文推断)
82
113
 
83
114
  你不需要每次都指定 `source`(调用方)。MermaidTrace 会根据当前上下文自动推断。
@@ -115,6 +146,19 @@ async def root():
115
146
  mermaid-trace serve my_flow.mmd
116
147
  ```
117
148
 
149
+ ### 示例教程
150
+
151
+ 请查看 [examples/](examples/) 目录,了解涵盖所有功能的完整示例集:
152
+
153
+ - **[基础用法](examples/01_basic_usage.py)**:装饰器与类方法追踪。
154
+ - **[高级插桩](examples/02_advanced_instrumentation.py)**:`@trace_class` 与 `patch_object`(针对第三方库)。
155
+ - **[异步与并发](examples/03_async_concurrency.py)**:`asyncio` 追踪与并发上下文隔离。
156
+ - **[错误处理](examples/04_error_handling.py)**:堆栈捕获与错误箭头渲染。
157
+ - **[智能折叠](examples/05_intelligent_collapsing.py)**:在循环中保持图表整洁。
158
+ - **[FastAPI 集成](examples/06_fastapi_integration.py)**:Web 应用中间件集成。
159
+ - **[全栈综合应用](examples/07_full_stack_app.py)**:结合 FastAPI、SQLAlchemy 和 Pydantic 的全链路追踪示例。
160
+ - **[日志轮转](examples/08-log-rotation.py)**:演示如何使用日志轮转处理长运行进程。
161
+
118
162
  ---
119
163
 
120
164
  ## 🤝 贡献
@@ -4,6 +4,8 @@
4
4
 
5
5
  - [Core](#core)
6
6
  - [trace / trace_interaction](#trace--trace_interaction)
7
+ - [trace_class](#trace_class)
8
+ - [patch_object](#patch_object)
7
9
  - [configure_flow](#configure_flow)
8
10
  - [LogContext](#logcontext)
9
11
  - [Event (Abstract Base Class)](#event-abstract-base-class)
@@ -40,6 +42,40 @@ def login(username): ...
40
42
  - `max_arg_length` (int): Maximum length of string representation for arguments. Defaults to 50.
41
43
  - `max_arg_depth` (int): Maximum depth for nested structures in argument representation. Defaults to 1.
42
44
 
45
+ ### `trace_class`
46
+
47
+ Class decorator to automatically apply `@trace` to methods of a class.
48
+
49
+ ```python
50
+ from mermaid_trace import trace_class
51
+
52
+ @trace_class
53
+ class MyService:
54
+ def method_a(self) -> None:
55
+ ...
56
+ ```
57
+
58
+ **Arguments:**
59
+ - `include_private` (bool): If True, traces methods starting with `_`. Defaults to False.
60
+ - `exclude` (Optional[List[str]]): Method names to skip.
61
+ - `**trace_kwargs`: Passed through to `@trace` (e.g., `capture_args=False`).
62
+
63
+ ### `patch_object`
64
+
65
+ Monkey-patches a method on an object/class/module with tracing.
66
+
67
+ ```python
68
+ import requests
69
+ from mermaid_trace import patch_object
70
+
71
+ patch_object(requests, "get", action="HTTP GET", target="requests")
72
+ ```
73
+
74
+ **Arguments:**
75
+ - `target` (Any): Object/class/module that owns the attribute.
76
+ - `method_name` (str): Attribute name to wrap.
77
+ - `**trace_kwargs`: Passed through to `@trace`.
78
+
43
79
  ### `configure_flow`
44
80
 
45
81
  Configures the global logger to output to a Mermaid file. This should be called once at application startup.
@@ -49,7 +85,11 @@ def configure_flow(
49
85
  output_file: str = "flow.mmd",
50
86
  handlers: Optional[List[logging.Handler]] = None,
51
87
  append: bool = False,
52
- async_mode: bool = False
88
+ overwrite: bool = True,
89
+ async_mode: bool = False,
90
+ level: int = logging.INFO,
91
+ config_overrides: Optional[Dict[str, Any]] = None,
92
+ queue_size: Optional[int] = None,
53
93
  ) -> logging.Logger
54
94
  ```
55
95
 
@@ -57,7 +97,11 @@ def configure_flow(
57
97
  - `output_file` (str): Path to the `.mmd` output file. Defaults to "flow.mmd".
58
98
  - `handlers` (List[logging.Handler]): Optional list of custom logging handlers. If provided, `output_file` is ignored unless you include `MermaidFileHandler` manually.
59
99
  - `append` (bool): If `True`, adds new handlers without removing existing ones. Defaults to `False`.
100
+ - `overwrite` (bool): If `True` (default), overwrites the output file on each restart. If `False`, appends to the existing file.
60
101
  - `async_mode` (bool): If `True`, uses a non-blocking background thread for logging (QueueHandler). Recommended for production. Defaults to `False`.
102
+ - `level` (int): Logger level. Defaults to `logging.INFO`.
103
+ - `config_overrides` (Optional[Dict[str, Any]]): Overrides for global config keys (MermaidConfig fields).
104
+ - `queue_size` (Optional[int]): Queue size for async mode; overrides config.
61
105
 
62
106
  ### `LogContext`
63
107
 
@@ -73,13 +117,13 @@ Manages execution context (like thread-local storage) to track caller/callee rel
73
117
 
74
118
  Abstract base class for all event types, providing a common interface for different types of events.
75
119
 
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.
120
+ **Attributes:**
121
+ - `source` (str): Name of the participant that generated the event.
122
+ - `target` (str): Name of the participant that received the event.
123
+ - `action` (str): Short name describing the action performed.
124
+ - `message` (str): Detailed message describing the event.
125
+ - `timestamp` (float): Unix timestamp (seconds) when the event occurred.
126
+ - `trace_id` (str): Unique identifier for the trace session.
83
127
 
84
128
  ### `FlowEvent`
85
129
 
@@ -95,8 +139,10 @@ Represents a single interaction or step in the execution flow, inheriting from `
95
139
  - `is_return` (bool): Flag indicating if this is a response arrow.
96
140
  - `is_error` (bool): Flag indicating if an exception occurred.
97
141
  - `error_message` (Optional[str]): Detailed error text if `is_error` is True.
142
+ - `stack_trace` (Optional[str]): Full stack trace text if available.
98
143
  - `params` (Optional[str]): Stringified representation of function arguments.
99
144
  - `result` (Optional[str]): Stringified representation of the return value.
145
+ - `collapsed` (bool): Flag indicating this interaction should be visually collapsed.
100
146
 
101
147
  ### `BaseFormatter` (Abstract Base Class)
102
148
 
@@ -104,6 +150,7 @@ Abstract base class for all event formatters, providing a common interface for d
104
150
 
105
151
  **Methods:**
106
152
  - `format_event(event: Event) -> str`: Format an Event into the desired output string.
153
+ - `get_header(title: str) -> str`: Get the file header for the diagram format.
107
154
  - `format(record: logging.LogRecord) -> str`: Format a logging record containing an event.
108
155
 
109
156
  ### `MermaidFormatter`
@@ -112,6 +159,7 @@ Custom formatter to convert Events into Mermaid sequence diagram syntax, inherit
112
159
 
113
160
  **Methods:**
114
161
  - `format_event(event: Event) -> str`: Converts an Event into a Mermaid syntax string.
162
+ - `get_header(title: str) -> str`: Returns the Mermaid sequence diagram header.
115
163
 
116
164
  ### `MermaidFileHandler`
117
165
 
@@ -5,6 +5,53 @@ 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.5.3] - 2026-01-27
9
+
10
+ ### Added
11
+ - **Log Rotation**: Introduced `RotatingMermaidFileHandler` and `TimedRotatingMermaidFileHandler` to handle long-running systems by automatically splitting `.mmd` files based on size or time.
12
+ - **Overwrite Support**: Added `overwrite` parameter to `configure_flow` to allow clearing the diagram file on application restart.
13
+
14
+ ### Improved
15
+ - **Documentation**: Comprehensive update of English and Chinese documentation, including User Guide, API Reference, and detailed source code annotations.
16
+ - **Examples**: Added a new example `08-log-rotation.py` demonstrating production-ready log rotation configurations.
17
+
18
+ ## [0.5.2] - 2026-01-27
19
+
20
+ ### Added
21
+ - **List/Tuple Item Grouping**: Consecutive identical items in lists and tuples are now automatically grouped (e.g., `['a', 'a', 'a']` -> `['a' x 3]`), significantly reducing visual noise in diagrams when dealing with large collections of similar objects.
22
+
23
+ ### Improved
24
+ - **Test Coverage**: Increased test coverage to **96.22%** by adding comprehensive test cases for edge cases in CLI, decorators, and handlers.
25
+ - **Robustness**: Improved CLI error handling and live reload stability by fixing mock handling and ensuring proper cleanup.
26
+ - **Documentation**: Synchronized all documentation across languages and updated comprehensive Chinese source code annotations for all modules.
27
+
28
+ ## [0.5.0] - 2026-01-27
29
+
30
+ ### Added
31
+ - **Intelligent Collapsing**: Repetitive high-frequency calls are now automatically collapsed into a single arrow with a counter (e.g., `func (x10)`), preventing diagram bloat.
32
+ - **Auto-Instrumentation**: Added `@trace_class` decorator to automatically trace all public methods in a class.
33
+ - **Third-Party Patching**: Added `patch_object` utility to trace methods in external libraries (e.g., `requests.get`) without modifying their source.
34
+ - **Global Configuration**: Introduced `MermaidConfig` system allowing global control over parameter capture, string limits, and recursion depth via code or environment variables.
35
+ - **Full Stack Trace Capture**: Exceptions now capture the complete Python traceback, displayed as a Note in the Mermaid diagram for easier debugging.
36
+
37
+ ### Changed
38
+ - **`configure_flow` API**: Updated to support `level`, `config_overrides`, and `queue_size` for more flexible initialization.
39
+ - **Enhanced FastAPI Integration**: The middleware now captures and logs full stack traces for unhandled exceptions.
40
+
41
+ ### Improved
42
+ - **Documentation**: Added comprehensive Chinese source code annotations for all modules.
43
+ - **Test Coverage**: Maintained >93% coverage with new tests for collapsing and configuration logic.
44
+
45
+ ## [0.4.2] - 2026-01-27
46
+
47
+ ### Fixed
48
+ - **Lazy Loading**: Fixed `MermaidFileHandler` to respect `delay=True`. File is now only created when the first log event is emitted, preventing empty files from being created unnecessarily.
49
+ - **Naming Collisions**: Fixed `MermaidFormatter._sanitize` to handle naming collisions robustly (e.g., `User A` vs `User-A`) by ensuring unique Mermaid IDs.
50
+
51
+ ### Improved
52
+ - **Code Cleanup**: Removed redundant getter methods in `Event` and `FlowEvent` in favor of Pythonic attribute access.
53
+ - **Handler SRP**: Decoupled Mermaid header generation from `MermaidFileHandler` by moving logic to `MermaidFormatter.get_header()`.
54
+
8
55
  ## [0.4.1] - 2026-01-26
9
56
 
10
57
  ### Added