mermaid-trace 0.4.0__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 (150) hide show
  1. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/.github/workflows/ci.yml +1 -1
  2. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/.github/workflows/release.yml +3 -0
  3. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/PKG-INFO +78 -11
  4. mermaid_trace-0.5.3.post0/README.md +170 -0
  5. mermaid_trace-0.5.3.post0/README_CN.md +172 -0
  6. mermaid_trace-0.5.3.post0/docs/en/API.md +205 -0
  7. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/docs/en/CHANGELOG.md +63 -0
  8. mermaid_trace-0.5.3.post0/docs/en/USER_GUIDE.md +285 -0
  9. mermaid_trace-0.5.3.post0/docs/zh/API.md +205 -0
  10. mermaid_trace-0.5.3.post0/docs/zh/CHANGELOG.md +149 -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/image/context/1769443810901.png +0 -0
  23. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/core/image/context/1769443817389.png +0 -0
  24. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/core/image/context/1769443818915.png +0 -0
  25. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/core/image/context/1769443830665.png +0 -0
  26. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/core/image/context/1769443835553.png +0 -0
  27. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/core/utils.md +103 -0
  28. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/handlers/async_handler.md +115 -0
  29. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/handlers/mermaid_handler.md +217 -0
  30. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/integrations/__init__.md +14 -0
  31. mermaid_trace-0.5.3.post0/docs/zh/code_comments/src/mermaid_trace/integrations/fastapi.md +169 -0
  32. mermaid_trace-0.5.3.post0/examples/01_basic_usage.py +46 -0
  33. mermaid_trace-0.5.3.post0/examples/02_advanced_instrumentation.py +50 -0
  34. mermaid_trace-0.5.3.post0/examples/03_async_concurrency.py +37 -0
  35. mermaid_trace-0.5.3.post0/examples/04_error_handling.py +38 -0
  36. mermaid_trace-0.5.3.post0/examples/05_intelligent_collapsing.py +31 -0
  37. mermaid_trace-0.5.3.post0/examples/06_fastapi_integration.py +46 -0
  38. mermaid_trace-0.5.3.post0/examples/07_full_stack_app.py +126 -0
  39. mermaid_trace-0.5.3.post0/examples/08-log-rotation.py +93 -0
  40. mermaid_trace-0.5.3.post0/examples/README.md +62 -0
  41. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/08-log-rotation.mmd +20 -0
  42. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/08-log-rotation.mmd.1 +28 -0
  43. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/08-log-rotation.mmd.2 +28 -0
  44. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/08-log-rotation.mmd.3 +28 -0
  45. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/08-log-rotation.mmd.4 +28 -0
  46. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/08-log-rotation.mmd.5 +28 -0
  47. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/async_flow.mmd +11 -0
  48. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/basic_flow.mmd +10 -0
  49. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/collapsed_flow.mmd +8 -0
  50. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/error_handling.mmd +12 -0
  51. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/fastapi_trace.mmd +9 -0
  52. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/full_stack_app.mmd +12 -0
  53. mermaid_trace-0.5.3.post0/mermaid_diagrams/examples/instrumentation_demo.mmd +10 -0
  54. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/core/config_override/dummy.mmd +58 -0
  55. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/handlers/handlers/append.mmd +3 -0
  56. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/handlers/handlers/async_flow.mmd +5 -0
  57. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/handlers/handlers/delay.mmd +5 -0
  58. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/handlers/handlers/flush_flow.mmd +5 -0
  59. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/handlers/handlers/test_flow.mmd +5 -0
  60. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/integrations/integration_fastapi/api_flow.mmd +6 -0
  61. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/overwrite_logic/test_overwrite_default.mmd +6 -0
  62. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/overwrite_logic/test_overwrite_false.mmd +6 -0
  63. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/scenarios/basic_flow/basic_flow.mmd +7 -0
  64. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/scenarios/concurrency/concurrency.mmd +6 -0
  65. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/scenarios/concurrency/trace_ids.mmd +6 -0
  66. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/scenarios/edge_cases/edge.mmd +7 -0
  67. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/scenarios/performance/bench_False.mmd +6 -0
  68. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/scenarios/performance/bench_True.mmd +6 -0
  69. mermaid_trace-0.5.3.post0/mermaid_diagrams/tests/scenarios/performance/overhead.mmd +6 -0
  70. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/pyproject.toml +4 -1
  71. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/src/mermaid_trace/__init__.py +55 -21
  72. mermaid_trace-0.5.3.post0/src/mermaid_trace/cli.py +357 -0
  73. mermaid_trace-0.5.3.post0/src/mermaid_trace/core/config.py +55 -0
  74. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/src/mermaid_trace/core/context.py +83 -23
  75. mermaid_trace-0.5.3.post0/src/mermaid_trace/core/decorators.py +675 -0
  76. mermaid_trace-0.5.3.post0/src/mermaid_trace/core/events.py +60 -0
  77. mermaid_trace-0.5.3.post0/src/mermaid_trace/core/formatter.py +309 -0
  78. mermaid_trace-0.5.3.post0/src/mermaid_trace/core/utils.py +96 -0
  79. mermaid_trace-0.5.3.post0/src/mermaid_trace/handlers/async_handler.py +181 -0
  80. mermaid_trace-0.5.3.post0/src/mermaid_trace/handlers/mermaid_handler.py +185 -0
  81. mermaid_trace-0.5.3.post0/src/mermaid_trace/integrations/__init__.py +4 -0
  82. mermaid_trace-0.5.3.post0/src/mermaid_trace/integrations/fastapi.py +221 -0
  83. mermaid_trace-0.5.3.post0/test.db +0 -0
  84. mermaid_trace-0.5.3.post0/tests/conftest.py +37 -0
  85. mermaid_trace-0.5.3.post0/tests/core/test_cli_coverage.py +75 -0
  86. mermaid_trace-0.5.3.post0/tests/core/test_config_coverage.py +35 -0
  87. mermaid_trace-0.5.3.post0/tests/core/test_config_override.py +73 -0
  88. mermaid_trace-0.5.3.post0/tests/core/test_context_extra.py +32 -0
  89. mermaid_trace-0.5.3.post0/tests/core/test_decorators_coverage.py +101 -0
  90. mermaid_trace-0.5.3.post0/tests/core/test_decorators_extra.py +89 -0
  91. mermaid_trace-0.5.3.post0/tests/core/test_events.py +60 -0
  92. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/tests/core/test_formatter.py +10 -5
  93. mermaid_trace-0.5.3.post0/tests/core/test_formatter_coverage.py +211 -0
  94. mermaid_trace-0.5.3.post0/tests/core/test_formatter_extra.py +112 -0
  95. mermaid_trace-0.5.3.post0/tests/core/test_utils.py +71 -0
  96. mermaid_trace-0.5.3.post0/tests/core/test_utils_coverage.py +114 -0
  97. mermaid_trace-0.5.3.post0/tests/handlers/test_async_handler_coverage.py +55 -0
  98. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/tests/handlers/test_handlers.py +68 -21
  99. mermaid_trace-0.5.3.post0/tests/handlers/test_mermaid_handler_coverage.py +28 -0
  100. mermaid_trace-0.5.3.post0/tests/integrations/test_fastapi_coverage.py +29 -0
  101. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/tests/integrations/test_integration_decorators.py +7 -2
  102. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/tests/integrations/test_integration_fastapi.py +42 -24
  103. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/tests/scenarios/test_basic_flow.py +19 -6
  104. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/tests/scenarios/test_concurrency.py +31 -29
  105. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/tests/scenarios/test_edge_cases.py +4 -2
  106. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/tests/scenarios/test_performance.py +15 -7
  107. mermaid_trace-0.4.0/README.md +0 -102
  108. mermaid_trace-0.4.0/README_CN.md +0 -102
  109. mermaid_trace-0.4.0/docs/en/API.md +0 -75
  110. mermaid_trace-0.4.0/docs/en/USER_GUIDE.md +0 -93
  111. mermaid_trace-0.4.0/docs/zh/API.md +0 -75
  112. mermaid_trace-0.4.0/docs/zh/CHANGELOG.md +0 -78
  113. mermaid_trace-0.4.0/docs/zh/USER_GUIDE.md +0 -93
  114. mermaid_trace-0.4.0/docs/zh/code_comments/src/mermaid_trace/__init__.md +0 -122
  115. mermaid_trace-0.4.0/docs/zh/code_comments/src/mermaid_trace/cli.md +0 -262
  116. mermaid_trace-0.4.0/docs/zh/code_comments/src/mermaid_trace/core/context.md +0 -200
  117. mermaid_trace-0.4.0/docs/zh/code_comments/src/mermaid_trace/core/decorators.md +0 -325
  118. mermaid_trace-0.4.0/docs/zh/code_comments/src/mermaid_trace/core/events.md +0 -96
  119. mermaid_trace-0.4.0/docs/zh/code_comments/src/mermaid_trace/core/formatter.md +0 -105
  120. mermaid_trace-0.4.0/docs/zh/code_comments/src/mermaid_trace/handlers/async_handler.md +0 -69
  121. mermaid_trace-0.4.0/docs/zh/code_comments/src/mermaid_trace/handlers/mermaid_handler.md +0 -110
  122. mermaid_trace-0.4.0/docs/zh/code_comments/src/mermaid_trace/integrations/fastapi.md +0 -150
  123. mermaid_trace-0.4.0/examples/concurrency_demo.py +0 -46
  124. mermaid_trace-0.4.0/examples/demo.py +0 -38
  125. mermaid_trace-0.4.0/examples/error_handling_demo.py +0 -50
  126. mermaid_trace-0.4.0/examples/nested_demo.py +0 -45
  127. mermaid_trace-0.4.0/flow.mmd +0 -15
  128. mermaid_trace-0.4.0/src/mermaid_trace/cli.py +0 -261
  129. mermaid_trace-0.4.0/src/mermaid_trace/core/decorators.py +0 -380
  130. mermaid_trace-0.4.0/src/mermaid_trace/core/events.py +0 -77
  131. mermaid_trace-0.4.0/src/mermaid_trace/core/formatter.py +0 -81
  132. mermaid_trace-0.4.0/src/mermaid_trace/handlers/async_handler.py +0 -52
  133. mermaid_trace-0.4.0/src/mermaid_trace/handlers/mermaid_handler.py +0 -99
  134. mermaid_trace-0.4.0/src/mermaid_trace/integrations/fastapi.py +0 -145
  135. mermaid_trace-0.4.0/tests/conftest.py +0 -12
  136. mermaid_trace-0.4.0/tests/core/test_events.py +0 -28
  137. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/.gitignore +0 -0
  138. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/LICENSE +0 -0
  139. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/SECURITY.md +0 -0
  140. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/docs/en/CONTRIBUTING.md +0 -0
  141. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/docs/en/LICENSE +0 -0
  142. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/docs/zh/CONTRIBUTING.md +0 -0
  143. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/docs/zh/LICENSE +0 -0
  144. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/src/mermaid_trace/core/__init__.py +0 -0
  145. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/src/mermaid_trace/py.typed +0 -0
  146. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/tests/__init__.py +0 -0
  147. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/tests/core/__init__.py +0 -0
  148. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/tests/core/test_cli.py +0 -0
  149. {mermaid_trace-0.4.0 → mermaid_trace-0.5.3.post0}/tests/core/test_context.py +0 -0
  150. {mermaid_trace-0.4.0 → 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.0
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
@@ -63,24 +62,57 @@ Description-Content-Type: text/markdown
63
62
 
64
63
  # MermaidTrace: The Python Logger That Draws Diagrams
65
64
 
66
- [![PyPI version](https://img.shields.io/pypi/v/mermaid-trace.svg?style=flat-square)](https://pypi.org/project/mermaid-trace/)
67
- [![Python Versions](https://img.shields.io/pypi/pyversions/mermaid-trace.svg?style=flat-square)](https://pypi.org/project/mermaid-trace/)
65
+ 🌐 **Language**: [English](README.md) | [中文](README_CN.md)
66
+
67
+ [![PyPI version](https://img.shields.io/pypi/v/mermaid-trace.svg?style=flat-square&color=blue)](https://pypi.org/project/mermaid-trace/)
68
+ [![Python Versions](https://img.shields.io/pypi/pyversions/mermaid-trace.svg?style=flat-square&color=blue)](https://pypi.org/project/mermaid-trace/)
68
69
  [![License](https://img.shields.io/github/license/xt765/mermaid-trace?style=flat-square)](LICENSE)
69
70
  [![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)
70
71
  [![Codecov](https://img.shields.io/codecov/c/github/xt765/mermaid-trace?style=flat-square&logo=codecov)](https://codecov.io/gh/xt765/mermaid-trace)
71
72
 
73
+ ---
74
+
75
+ ## 📋 Overview
76
+
72
77
  **Stop reading logs. Start watching them.**
73
78
 
74
79
  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.
75
80
 
76
- ## ✨ Features
81
+ ---
82
+
83
+ ## 📚 Documentation
84
+
85
+ ### Core Documentation
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)
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
+
98
+ ---
99
+
100
+ ## ✨ Key Features
77
101
 
78
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.
79
105
  - **Auto-Diagramming**: Generates `.mmd` files that can be viewed in VS Code, GitHub, or Mermaid Live Editor.
80
106
  - **Async Support**: Works seamlessly with `asyncio` coroutines.
81
107
  - **Context Inference**: Automatically tracks nested calls and infers `source` participants using `contextvars`.
82
- - **FastAPI Integration**: Includes middleware for zero-config HTTP request tracing.
83
- - **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.
114
+
115
+ ---
84
116
 
85
117
  ## 🚀 Quick Start
86
118
 
@@ -97,7 +129,8 @@ from mermaid_trace import trace, configure_flow
97
129
  import time
98
130
 
99
131
  # 1. Configure output
100
- 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)
101
134
 
102
135
  # 2. Add decorators
103
136
  @trace(source="Client", target="PaymentService", action="Process Payment")
@@ -114,6 +147,29 @@ def check_balance(amount):
114
147
  process_payment(100)
115
148
  ```
116
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
+
117
173
  ### Nested Calls (Context Inference)
118
174
 
119
175
  You don't need to specify `source` every time. MermaidTrace infers it from the current context.
@@ -151,15 +207,26 @@ Visualize your generated `.mmd` files instantly:
151
207
  mermaid-trace serve my_flow.mmd
152
208
  ```
153
209
 
154
- ## 📂 Documentation
210
+ ### Examples
155
211
 
156
- - [English Documentation](docs/en/USER_GUIDE.md)
157
- - [中文文档](README_CN.md)
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
+
222
+ ---
158
223
 
159
224
  ## 🤝 Contributing
160
225
 
161
226
  We welcome contributions! Please see [CONTRIBUTING.md](docs/en/CONTRIBUTING.md) for details.
162
227
 
228
+ ---
229
+
163
230
  ## 📄 License
164
231
 
165
232
  MIT
@@ -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
@@ -0,0 +1,172 @@
1
+ # MermaidTrace: 能画图的 Python 日志工具
2
+
3
+ 🌐 **语言**: [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
+ ## 📋 概述
14
+
15
+ **别再干读日志了。开始“看”懂它们吧。**
16
+
17
+ MermaidTrace 是一个专业的日志工具,能从你的代码执行中自动生成 [Mermaid JS](https://mermaid.js.org/) 时序图。它非常适合可视化复杂的业务逻辑、微服务交互或异步流程。
18
+
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
+ ## ✨ 核心特性
39
+
40
+ - **装饰器驱动**:只需在函数上添加 `@trace` 或 `@trace_interaction` 即可。
41
+ - **批量追踪**:使用 `@trace_class` 一次性追踪整个类的方法。
42
+ - **第三方库追踪**:使用 `patch_object` 对外部库方法做 patch 并加入追踪。
43
+ - **自动绘图**:生成 `.mmd` 文件,可在 VS Code、GitHub 或 Mermaid Live Editor 中查看。
44
+ - **异步支持**:无缝支持 `asyncio`协程。
45
+ - **上下文推断**:利用 `contextvars` 自动追踪嵌套调用并推断 `source`(调用方)参与者。
46
+ - **智能折叠**:通过折叠重复的高频调用和识别循环模式(如循环调用),防止时序图过载。
47
+ - **详细异常堆栈**:自动捕获完整的错误堆栈追踪,并在图表中通过 Note 显示。
48
+ - **对象显示优化**:自动清理内存地址(例如 `<__main__.Obj at 0x...>` -> `<Obj>`),并**自动合并列表/元组中连续的相同项**(例如 `[<Obj> x 5]`),使图表更整洁。
49
+ - **日志轮转**:支持 `RotatingMermaidFileHandler`,通过按大小或时间切割日志文件,轻松应对长运行系统的日志膨胀问题。
50
+ - **FastAPI 集成**:内置中间件,实现零配置的 HTTP 请求追踪,支持通过 `X-Trace-ID` 和 `X-Source` 请求头进行分布式追踪。
51
+ - **CLI 工具**:内置带热重载功能的查看器,可在浏览器中即时预览图表。
52
+
53
+ ---
54
+
55
+ ## 🚀 快速开始
56
+
57
+ ### 安装
58
+
59
+ ```bash
60
+ pip install mermaid-trace
61
+ ```
62
+
63
+ ### 基础用法
64
+
65
+ ```python
66
+ from mermaid_trace import trace, configure_flow
67
+ import time
68
+
69
+ # 1. 配置输出文件
70
+ # 建议将图表存放在专门的目录中(如 mermaid_diagrams/)以保持项目整洁。
71
+ configure_flow("mermaid_diagrams/my_flow.mmd", async_mode=True)
72
+
73
+ # 2. 添加装饰器
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. 运行代码
85
+ process_payment(100)
86
+ ```
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
+
112
+ ### 嵌套调用(上下文推断)
113
+
114
+ 你不需要每次都指定 `source`(调用方)。MermaidTrace 会根据当前上下文自动推断。
115
+
116
+ ```python
117
+ @trace(source="Client", target="API")
118
+ def main():
119
+ # 在这里,当前的参与者是 "API"
120
+ service_call()
121
+
122
+ @trace(target="Service") # source 被自动推断为 "API"
123
+ def service_call():
124
+ pass
125
+ ```
126
+
127
+ ### FastAPI 集成
128
+
129
+ ```python
130
+ from fastapi import FastAPI
131
+ from mermaid_trace.integrations.fastapi import MermaidTraceMiddleware
132
+
133
+ app = FastAPI()
134
+ app.add_middleware(MermaidTraceMiddleware, app_name="MyAPI")
135
+
136
+ @app.get("/")
137
+ async def root():
138
+ return {"message": "Hello World"}
139
+ ```
140
+
141
+ ### CLI 查看器
142
+
143
+ 即时可视化生成的 `.mmd` 文件:
144
+
145
+ ```bash
146
+ mermaid-trace serve my_flow.mmd
147
+ ```
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
+
162
+ ---
163
+
164
+ ## 🤝 贡献
165
+
166
+ 欢迎贡献!详情请参阅 [CONTRIBUTING.md](docs/zh/CONTRIBUTING.md)。
167
+
168
+ ---
169
+
170
+ ## 📄 许可证
171
+
172
+ MIT