tracewise 0.1.0__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.
- tracewise-0.1.0/.dockerignore +12 -0
- tracewise-0.1.0/.gitignore +55 -0
- tracewise-0.1.0/AGENTS.md +106 -0
- tracewise-0.1.0/LICENSE +21 -0
- tracewise-0.1.0/PKG-INFO +171 -0
- tracewise-0.1.0/README.md +142 -0
- tracewise-0.1.0/docker/Dockerfile +28 -0
- tracewise-0.1.0/docker/docker-compose.yml +17 -0
- tracewise-0.1.0/docs/agent-status.md +55 -0
- tracewise-0.1.0/docs/superpowers/plans/2026-03-30-tracewise.md +1828 -0
- tracewise-0.1.0/docs/superpowers/plans/2026-04-01-feature-c-exception-capture.md +519 -0
- tracewise-0.1.0/docs/superpowers/plans/2026-04-01-httpx-client-instrumentation.md +738 -0
- tracewise-0.1.0/docs/superpowers/plans/2026-04-01-httpx-traceparent-propagation.md +598 -0
- tracewise-0.1.0/docs/superpowers/plans/2026-04-01-richer-middleware-request-capture.md +323 -0
- tracewise-0.1.0/docs/superpowers/plans/2026-04-01-span-enrichment-log-correlation.md +658 -0
- tracewise-0.1.0/docs/superpowers/plans/2026-04-02-fastapi-incoming-traceparent.md +572 -0
- tracewise-0.1.0/docs/superpowers/specs/2026-03-30-tracewise-design.md +403 -0
- tracewise-0.1.0/docs/superpowers/specs/2026-04-01-httpx-client-instrumentation-design.md +302 -0
- tracewise-0.1.0/docs/superpowers/specs/2026-04-01-httpx-traceparent-propagation-design.md +314 -0
- tracewise-0.1.0/docs/superpowers/specs/2026-04-01-richer-middleware-request-capture.md +238 -0
- tracewise-0.1.0/docs/superpowers/specs/2026-04-02-fastapi-incoming-traceparent-design.md +333 -0
- tracewise-0.1.0/docs/superpowers/specs/post-mvp-improvements.md +185 -0
- tracewise-0.1.0/pyproject.toml +48 -0
- tracewise-0.1.0/tests/__init__.py +0 -0
- tracewise-0.1.0/tests/conftest.py +47 -0
- tracewise-0.1.0/tests/integration/__init__.py +0 -0
- tracewise-0.1.0/tests/integration/test_api.py +108 -0
- tracewise-0.1.0/tests/testapp/__init__.py +0 -0
- tracewise-0.1.0/tests/testapp/main.py +131 -0
- tracewise-0.1.0/tests/unit/__init__.py +0 -0
- tracewise-0.1.0/tests/unit/test_context.py +64 -0
- tracewise-0.1.0/tests/unit/test_decorators.py +187 -0
- tracewise-0.1.0/tests/unit/test_enrichment.py +75 -0
- tracewise-0.1.0/tests/unit/test_httpx.py +397 -0
- tracewise-0.1.0/tests/unit/test_ids.py +121 -0
- tracewise-0.1.0/tests/unit/test_init.py +334 -0
- tracewise-0.1.0/tests/unit/test_logging_handler.py +102 -0
- tracewise-0.1.0/tests/unit/test_middleware.py +208 -0
- tracewise-0.1.0/tests/unit/test_models.py +73 -0
- tracewise-0.1.0/tests/unit/test_storage.py +108 -0
- tracewise-0.1.0/tests/unit/test_tasks.py +63 -0
- tracewise-0.1.0/tests/unit/test_traceparent.py +40 -0
- tracewise-0.1.0/tracewise/__init__.py +220 -0
- tracewise-0.1.0/tracewise/config.py +16 -0
- tracewise-0.1.0/tracewise/core/__init__.py +0 -0
- tracewise-0.1.0/tracewise/core/context.py +19 -0
- tracewise-0.1.0/tracewise/core/ids.py +15 -0
- tracewise-0.1.0/tracewise/core/models.py +41 -0
- tracewise-0.1.0/tracewise/core/traceparent.py +36 -0
- tracewise-0.1.0/tracewise/instrumentation/__init__.py +0 -0
- tracewise-0.1.0/tracewise/instrumentation/decorators.py +103 -0
- tracewise-0.1.0/tracewise/instrumentation/httpx.py +192 -0
- tracewise-0.1.0/tracewise/instrumentation/logging.py +32 -0
- tracewise-0.1.0/tracewise/instrumentation/middleware.py +102 -0
- tracewise-0.1.0/tracewise/instrumentation/tasks.py +40 -0
- tracewise-0.1.0/tracewise/storage/__init__.py +0 -0
- tracewise-0.1.0/tracewise/storage/base.py +25 -0
- tracewise-0.1.0/tracewise/storage/sqlite.py +190 -0
- tracewise-0.1.0/tracewise/viewer/__init__.py +0 -0
- tracewise-0.1.0/tracewise/viewer/api.py +73 -0
- tracewise-0.1.0/tracewise/viewer/app.py +21 -0
- tracewise-0.1.0/tracewise/viewer/static/.gitkeep +0 -0
- tracewise-0.1.0/tracewise/viewer/static/app.js +88 -0
- tracewise-0.1.0/tracewise/viewer/static/index.html +49 -0
- tracewise-0.1.0/uv.lock +677 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.pyo
|
|
5
|
+
*.pyd
|
|
6
|
+
*.egg
|
|
7
|
+
*.egg-info/
|
|
8
|
+
dist/
|
|
9
|
+
build/
|
|
10
|
+
.eggs/
|
|
11
|
+
|
|
12
|
+
# Virtual environments
|
|
13
|
+
.venv/
|
|
14
|
+
venv/
|
|
15
|
+
env/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# uv
|
|
19
|
+
.uv/
|
|
20
|
+
|
|
21
|
+
# Pytest
|
|
22
|
+
.pytest_cache/
|
|
23
|
+
.coverage
|
|
24
|
+
htmlcov/
|
|
25
|
+
|
|
26
|
+
# Ruff / linters
|
|
27
|
+
.ruff_cache/
|
|
28
|
+
|
|
29
|
+
# Environment files
|
|
30
|
+
.env
|
|
31
|
+
.env.*
|
|
32
|
+
!.env.example
|
|
33
|
+
|
|
34
|
+
# IDE
|
|
35
|
+
.vscode/
|
|
36
|
+
.idea/
|
|
37
|
+
*.swp
|
|
38
|
+
*.swo
|
|
39
|
+
.codex
|
|
40
|
+
|
|
41
|
+
# OS
|
|
42
|
+
.DS_Store
|
|
43
|
+
Thumbs.db
|
|
44
|
+
|
|
45
|
+
# TraceWise local data
|
|
46
|
+
*.db
|
|
47
|
+
*.db-shm
|
|
48
|
+
*.db-wal
|
|
49
|
+
.tracewise/
|
|
50
|
+
/docs
|
|
51
|
+
*.md
|
|
52
|
+
!README.md
|
|
53
|
+
!AGENTS.md
|
|
54
|
+
!/docs/
|
|
55
|
+
!/docs/**/*.md
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Agent Operating Contract
|
|
2
|
+
|
|
3
|
+
This file is the default operating contract for agents working in this repository.
|
|
4
|
+
|
|
5
|
+
## Authority
|
|
6
|
+
|
|
7
|
+
- User instructions take priority.
|
|
8
|
+
- This contract is otherwise strict by default.
|
|
9
|
+
- An agent must not relax, skip, or reinterpret these rules on its own.
|
|
10
|
+
- If an agent believes a rule should be changed for the current task, it must stop, explain the reason, and wait for explicit user permission before proceeding.
|
|
11
|
+
|
|
12
|
+
## Startup Rules
|
|
13
|
+
|
|
14
|
+
- Explore local project context before proposing changes or asking broad questions.
|
|
15
|
+
- Read relevant files, existing docs, recent changes, and established patterns before acting.
|
|
16
|
+
- Read `docs/agent-status.md` at the start of the session if it exists.
|
|
17
|
+
- Do not ask questions that can be answered from the codebase or existing project files.
|
|
18
|
+
- If project-specific instructions exist in additional instruction files, follow them together with this contract.
|
|
19
|
+
|
|
20
|
+
## Mandatory Workflow
|
|
21
|
+
|
|
22
|
+
### Feature work and behavior changes
|
|
23
|
+
|
|
24
|
+
Before implementing a feature or changing behavior, the agent must:
|
|
25
|
+
|
|
26
|
+
1. Explore the current project context.
|
|
27
|
+
2. Write a short spec or design document. (use appropriate skills)
|
|
28
|
+
3. Self-review the spec for ambiguity, contradictions, and scope issues. (use appropriate skills)
|
|
29
|
+
4. Ask the user to review the spec and update it until approved.
|
|
30
|
+
5. Write an implementation plan. (use appropriate skills)
|
|
31
|
+
6. Self-review the plan for sequencing, scope, and verification coverage. (use appropriate skills)
|
|
32
|
+
7. Ask the user to review the plan and update it until approved.
|
|
33
|
+
8. Only then start implementation. (use appropriate skills)
|
|
34
|
+
9. Project should be docker first. Agent tests locally, give manual steps to user to test in docker by themselves
|
|
35
|
+
|
|
36
|
+
Recommended document locations:
|
|
37
|
+
|
|
38
|
+
- `docs/specs/YYYY-MM-DD-<topic>.md`
|
|
39
|
+
- `docs/plans/YYYY-MM-DD-<topic>.md`
|
|
40
|
+
|
|
41
|
+
### Bug fixes and regressions
|
|
42
|
+
|
|
43
|
+
Before fixing a bug, the agent must:
|
|
44
|
+
|
|
45
|
+
1. Reproduce the issue or otherwise confirm the failure mode. (use appropriate skills)
|
|
46
|
+
2. Investigate root cause before proposing a fix.
|
|
47
|
+
3. Create a minimal failing test or minimal reproducible verification first, unless the user explicitly waives that requirement.
|
|
48
|
+
4. Apply the smallest fix that addresses the root cause.
|
|
49
|
+
|
|
50
|
+
No guessing, no stacked fixes, and no implementation before understanding the problem.
|
|
51
|
+
|
|
52
|
+
### Code changes in general
|
|
53
|
+
|
|
54
|
+
- Default to test-first development unless the user explicitly waives it for the current task.
|
|
55
|
+
- Use the environment's formal workflows for design, planning, debugging, testing, code review, delegation, and verification when those workflows exist.
|
|
56
|
+
- For larger work, break the task into isolated steps and stop after each meaningful step for user review instead of batching unrelated changes together.
|
|
57
|
+
- If delegation is available, use separate workers or reviewers for independent subtasks, but keep integration and final judgment centralized.
|
|
58
|
+
- never do git add, commit, push on your own. after each meaningful step completed stop with manual test steps and a commit message (feat:, chore: style), write docker test steps as well for the user to check.
|
|
59
|
+
|
|
60
|
+
## Editing and Safety
|
|
61
|
+
|
|
62
|
+
- State what you are about to change before editing files.
|
|
63
|
+
- Follow existing project patterns before introducing new ones.
|
|
64
|
+
- Do not perform unrelated refactoring while working on the current task unless the user approves it.
|
|
65
|
+
- Do not revert unrelated user changes.
|
|
66
|
+
- Do not use destructive commands or irreversible operations without explicit permission.
|
|
67
|
+
- Do not silently change architecture, dependencies, project direction, or workflow expectations.
|
|
68
|
+
|
|
69
|
+
## Verification and Review
|
|
70
|
+
|
|
71
|
+
- Do not claim success without fresh verification evidence from the current session.
|
|
72
|
+
- Run the smallest relevant verification that proves the change.
|
|
73
|
+
- Report what was verified, what was inferred, and what was not verified in the current environment.
|
|
74
|
+
- After implementation, perform an independent review pass before calling the work complete.
|
|
75
|
+
- If multi-agent or reviewer support is available, use a separate reviewer for that pass when practical.
|
|
76
|
+
- If asked for a review, prioritize bugs, regressions, risks, and missing verification ahead of summaries or suggestions.
|
|
77
|
+
- When receiving review feedback, analyze it technically before applying it. Do not accept or reject feedback mechanically.
|
|
78
|
+
|
|
79
|
+
## Communication
|
|
80
|
+
|
|
81
|
+
- Keep progress updates short, direct, and factual.
|
|
82
|
+
- Ask questions only when a real decision is required or the risk of assumption is high.
|
|
83
|
+
- Ask one question at a time when possible.
|
|
84
|
+
- Make blockers, assumptions, and tradeoffs explicit.
|
|
85
|
+
- By default, do one isolated change at a time and stop for user review before moving to the next step.
|
|
86
|
+
|
|
87
|
+
## Session Continuity
|
|
88
|
+
|
|
89
|
+
- `docs/agent-status.md` is the persistent handoff file for this repository.
|
|
90
|
+
- Read it at session start if it exists.
|
|
91
|
+
- Update it after each meaningful step and before ending a session.
|
|
92
|
+
- Keep it factual, compact, and current.
|
|
93
|
+
- Do not rely on hidden conversation context when a durable project status can be written down.
|
|
94
|
+
- If context becomes long or fragmented, prefer updating the status file over relying on memory.
|
|
95
|
+
- If `docs/agent-status.md` is missing and the work is non-trivial, create it before proceeding far into the task.
|
|
96
|
+
|
|
97
|
+
## Default Expectations for `docs/agent-status.md`
|
|
98
|
+
|
|
99
|
+
The status file should always answer these questions:
|
|
100
|
+
|
|
101
|
+
- What is the current objective?
|
|
102
|
+
- What has already been done?
|
|
103
|
+
- What was verified?
|
|
104
|
+
- What remains pending?
|
|
105
|
+
- What risks or blockers exist?
|
|
106
|
+
- What is the next recommended step?
|
tracewise-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tanmoy Sarkar Pranto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
tracewise-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tracewise
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Local tracing and debugging for FastAPI apps
|
|
5
|
+
Project-URL: Homepage, https://github.com/Tanmoy-Sarkar-Pranto/tracewise
|
|
6
|
+
Project-URL: Repository, https://github.com/Tanmoy-Sarkar-Pranto/tracewise
|
|
7
|
+
Author: Tanmoy Sarkar Pranto
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: debugging,fastapi,observability,tracing
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Framework :: FastAPI
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Software Development :: Debuggers
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Requires-Dist: fastapi<1.0,>=0.100.0
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: anyio; extra == 'dev'
|
|
22
|
+
Requires-Dist: httpx; extra == 'dev'
|
|
23
|
+
Requires-Dist: pytest; extra == 'dev'
|
|
24
|
+
Requires-Dist: pytest-asyncio; extra == 'dev'
|
|
25
|
+
Requires-Dist: uvicorn[standard]; extra == 'dev'
|
|
26
|
+
Provides-Extra: httpx
|
|
27
|
+
Requires-Dist: httpx; extra == 'httpx'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# TraceWise
|
|
31
|
+
|
|
32
|
+
TraceWise is a small tracing and debugging tool for FastAPI apps.
|
|
33
|
+
|
|
34
|
+
It records request spans to a local SQLite database and mounts a built-in viewer
|
|
35
|
+
at `/tracewise` so you can inspect traces while developing.
|
|
36
|
+
|
|
37
|
+
Current scope:
|
|
38
|
+
|
|
39
|
+
- inbound FastAPI request tracing
|
|
40
|
+
- manual spans with `tracewise.start_span(...)`
|
|
41
|
+
- decorator-based spans with `@tracewise.trace_span(...)`
|
|
42
|
+
- span attributes and events
|
|
43
|
+
- optional log capture
|
|
44
|
+
- optional `httpx` client tracing with `traceparent` propagation
|
|
45
|
+
- local SQLite storage and a minimal embedded UI
|
|
46
|
+
|
|
47
|
+
This is aimed at local development and debugging. It is not trying to be a full
|
|
48
|
+
APM or a hosted tracing backend.
|
|
49
|
+
|
|
50
|
+
## Install
|
|
51
|
+
|
|
52
|
+
For local development in this repo:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
uv sync --extra dev
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Or with `pip`:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pip install -e .
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
If you want `instrument_httpx=True`, install the optional extra:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install -e ".[httpx]"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
For a published package install, the same extra would be:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install "tracewise[httpx]"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Quick Start
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from fastapi import FastAPI
|
|
80
|
+
import tracewise
|
|
81
|
+
|
|
82
|
+
app = FastAPI()
|
|
83
|
+
|
|
84
|
+
tracewise.init(
|
|
85
|
+
app,
|
|
86
|
+
capture_logs=True,
|
|
87
|
+
instrument_httpx=True,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@app.get("/users")
|
|
92
|
+
async def list_users():
|
|
93
|
+
async with tracewise.start_span("db.query", table="users", operation="SELECT"):
|
|
94
|
+
pass
|
|
95
|
+
|
|
96
|
+
tracewise.set_attribute("result.count", 2)
|
|
97
|
+
tracewise.add_event("users.loaded")
|
|
98
|
+
|
|
99
|
+
return {"users": []}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Once the app is running:
|
|
103
|
+
|
|
104
|
+
- make a request to one of your routes
|
|
105
|
+
- open `/tracewise`
|
|
106
|
+
- inspect the recorded trace tree
|
|
107
|
+
|
|
108
|
+
## API Surface
|
|
109
|
+
|
|
110
|
+
Top-level helpers currently exposed by the package:
|
|
111
|
+
|
|
112
|
+
- `tracewise.init(app, ...)`
|
|
113
|
+
- `tracewise.get_current_span()`
|
|
114
|
+
- `tracewise.start_span(name, **attributes)`
|
|
115
|
+
- `tracewise.trace_span(name, attributes=...)`
|
|
116
|
+
- `tracewise.set_attribute(key, value)`
|
|
117
|
+
- `tracewise.set_attributes({...})`
|
|
118
|
+
- `tracewise.add_event(name, **attributes)`
|
|
119
|
+
|
|
120
|
+
Main `init()` options:
|
|
121
|
+
|
|
122
|
+
- `db_path`: path to the SQLite database file
|
|
123
|
+
- `max_traces`: max number of traces to keep
|
|
124
|
+
- `enabled`: turn tracing on or off
|
|
125
|
+
- `capture_logs`: attach a logging handler that records log events on the
|
|
126
|
+
active span
|
|
127
|
+
- `instrument_httpx`: record outbound `httpx` requests and inject
|
|
128
|
+
`traceparent` headers
|
|
129
|
+
|
|
130
|
+
If `db_path` is not provided, TraceWise stores data under
|
|
131
|
+
`~/.tracewise/traces.db`.
|
|
132
|
+
|
|
133
|
+
You can also disable tracing with:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
TRACEWISE_ENABLED=false
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Example App
|
|
140
|
+
|
|
141
|
+
A small example app lives in `tests/testapp/main.py`.
|
|
142
|
+
|
|
143
|
+
To run it with Docker:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
docker compose -f docker/docker-compose.yml up --build
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Then open:
|
|
150
|
+
|
|
151
|
+
- `http://localhost:8000/health`
|
|
152
|
+
- `http://localhost:8000/users`
|
|
153
|
+
- `http://localhost:8000/orders`
|
|
154
|
+
- `http://localhost:8000/error`
|
|
155
|
+
- `http://localhost:8000/tracewise`
|
|
156
|
+
|
|
157
|
+
## Current Limitations
|
|
158
|
+
|
|
159
|
+
- FastAPI-specific for now
|
|
160
|
+
- local SQLite storage only
|
|
161
|
+
- viewer UI is intentionally minimal
|
|
162
|
+
- `httpx` tracing is optional and only applies if your app uses `httpx`
|
|
163
|
+
- not a replacement for OpenTelemetry or a hosted tracing stack
|
|
164
|
+
|
|
165
|
+
## Development
|
|
166
|
+
|
|
167
|
+
Run the tests with:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
uv run pytest
|
|
171
|
+
```
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# TraceWise
|
|
2
|
+
|
|
3
|
+
TraceWise is a small tracing and debugging tool for FastAPI apps.
|
|
4
|
+
|
|
5
|
+
It records request spans to a local SQLite database and mounts a built-in viewer
|
|
6
|
+
at `/tracewise` so you can inspect traces while developing.
|
|
7
|
+
|
|
8
|
+
Current scope:
|
|
9
|
+
|
|
10
|
+
- inbound FastAPI request tracing
|
|
11
|
+
- manual spans with `tracewise.start_span(...)`
|
|
12
|
+
- decorator-based spans with `@tracewise.trace_span(...)`
|
|
13
|
+
- span attributes and events
|
|
14
|
+
- optional log capture
|
|
15
|
+
- optional `httpx` client tracing with `traceparent` propagation
|
|
16
|
+
- local SQLite storage and a minimal embedded UI
|
|
17
|
+
|
|
18
|
+
This is aimed at local development and debugging. It is not trying to be a full
|
|
19
|
+
APM or a hosted tracing backend.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
For local development in this repo:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
uv sync --extra dev
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or with `pip`:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install -e .
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
If you want `instrument_httpx=True`, install the optional extra:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install -e ".[httpx]"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
For a published package install, the same extra would be:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install "tracewise[httpx]"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from fastapi import FastAPI
|
|
51
|
+
import tracewise
|
|
52
|
+
|
|
53
|
+
app = FastAPI()
|
|
54
|
+
|
|
55
|
+
tracewise.init(
|
|
56
|
+
app,
|
|
57
|
+
capture_logs=True,
|
|
58
|
+
instrument_httpx=True,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@app.get("/users")
|
|
63
|
+
async def list_users():
|
|
64
|
+
async with tracewise.start_span("db.query", table="users", operation="SELECT"):
|
|
65
|
+
pass
|
|
66
|
+
|
|
67
|
+
tracewise.set_attribute("result.count", 2)
|
|
68
|
+
tracewise.add_event("users.loaded")
|
|
69
|
+
|
|
70
|
+
return {"users": []}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Once the app is running:
|
|
74
|
+
|
|
75
|
+
- make a request to one of your routes
|
|
76
|
+
- open `/tracewise`
|
|
77
|
+
- inspect the recorded trace tree
|
|
78
|
+
|
|
79
|
+
## API Surface
|
|
80
|
+
|
|
81
|
+
Top-level helpers currently exposed by the package:
|
|
82
|
+
|
|
83
|
+
- `tracewise.init(app, ...)`
|
|
84
|
+
- `tracewise.get_current_span()`
|
|
85
|
+
- `tracewise.start_span(name, **attributes)`
|
|
86
|
+
- `tracewise.trace_span(name, attributes=...)`
|
|
87
|
+
- `tracewise.set_attribute(key, value)`
|
|
88
|
+
- `tracewise.set_attributes({...})`
|
|
89
|
+
- `tracewise.add_event(name, **attributes)`
|
|
90
|
+
|
|
91
|
+
Main `init()` options:
|
|
92
|
+
|
|
93
|
+
- `db_path`: path to the SQLite database file
|
|
94
|
+
- `max_traces`: max number of traces to keep
|
|
95
|
+
- `enabled`: turn tracing on or off
|
|
96
|
+
- `capture_logs`: attach a logging handler that records log events on the
|
|
97
|
+
active span
|
|
98
|
+
- `instrument_httpx`: record outbound `httpx` requests and inject
|
|
99
|
+
`traceparent` headers
|
|
100
|
+
|
|
101
|
+
If `db_path` is not provided, TraceWise stores data under
|
|
102
|
+
`~/.tracewise/traces.db`.
|
|
103
|
+
|
|
104
|
+
You can also disable tracing with:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
TRACEWISE_ENABLED=false
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Example App
|
|
111
|
+
|
|
112
|
+
A small example app lives in `tests/testapp/main.py`.
|
|
113
|
+
|
|
114
|
+
To run it with Docker:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
docker compose -f docker/docker-compose.yml up --build
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Then open:
|
|
121
|
+
|
|
122
|
+
- `http://localhost:8000/health`
|
|
123
|
+
- `http://localhost:8000/users`
|
|
124
|
+
- `http://localhost:8000/orders`
|
|
125
|
+
- `http://localhost:8000/error`
|
|
126
|
+
- `http://localhost:8000/tracewise`
|
|
127
|
+
|
|
128
|
+
## Current Limitations
|
|
129
|
+
|
|
130
|
+
- FastAPI-specific for now
|
|
131
|
+
- local SQLite storage only
|
|
132
|
+
- viewer UI is intentionally minimal
|
|
133
|
+
- `httpx` tracing is optional and only applies if your app uses `httpx`
|
|
134
|
+
- not a replacement for OpenTelemetry or a hosted tracing stack
|
|
135
|
+
|
|
136
|
+
## Development
|
|
137
|
+
|
|
138
|
+
Run the tests with:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
uv run pytest
|
|
142
|
+
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
FROM python:3.12-slim
|
|
2
|
+
|
|
3
|
+
RUN pip install uv
|
|
4
|
+
|
|
5
|
+
# Keep venv outside /app so the dev volume mount doesn't overwrite it
|
|
6
|
+
ENV UV_PROJECT_ENVIRONMENT=/opt/venv
|
|
7
|
+
ENV UV_LINK_MODE=copy
|
|
8
|
+
|
|
9
|
+
# Create non-root user, /app, and /opt/venv — all as root, then hand over
|
|
10
|
+
RUN useradd -m -u 1000 appuser \
|
|
11
|
+
&& mkdir -p /app /opt/venv /home/appuser/.tracewise \
|
|
12
|
+
&& chown -R appuser:appuser /app /opt/venv /home/appuser
|
|
13
|
+
|
|
14
|
+
USER appuser
|
|
15
|
+
WORKDIR /app
|
|
16
|
+
|
|
17
|
+
# Install dependencies first (without the project itself) for layer caching
|
|
18
|
+
COPY --chown=appuser:appuser pyproject.toml ./
|
|
19
|
+
RUN uv sync --extra dev --no-install-project
|
|
20
|
+
|
|
21
|
+
# Copy source, then install the project itself
|
|
22
|
+
COPY --chown=appuser:appuser . .
|
|
23
|
+
RUN uv sync --extra dev
|
|
24
|
+
|
|
25
|
+
EXPOSE 8000
|
|
26
|
+
|
|
27
|
+
# No --reload here: use docker-compose command override for dev
|
|
28
|
+
CMD ["uv", "run", "uvicorn", "tests.testapp.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
services:
|
|
2
|
+
app:
|
|
3
|
+
build:
|
|
4
|
+
context: ..
|
|
5
|
+
dockerfile: docker/Dockerfile
|
|
6
|
+
ports:
|
|
7
|
+
- "127.0.0.1:8000:8000"
|
|
8
|
+
volumes:
|
|
9
|
+
- ..:/app
|
|
10
|
+
- tracewise-data:/home/appuser/.tracewise
|
|
11
|
+
environment:
|
|
12
|
+
- TRACEWISE_ENABLED=true
|
|
13
|
+
command: ["uv", "run", "uvicorn", "tests.testapp.main:app",
|
|
14
|
+
"--host", "0.0.0.0", "--port", "8000", "--reload"]
|
|
15
|
+
|
|
16
|
+
volumes:
|
|
17
|
+
tracewise-data:
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Agent Status
|
|
2
|
+
|
|
3
|
+
Update this file after each meaningful step and before ending a session.
|
|
4
|
+
|
|
5
|
+
This file is the durable handoff point for future sessions. Keep it factual, compact, and current. Remove stale detail when it stops being useful.
|
|
6
|
+
|
|
7
|
+
## Current Objective
|
|
8
|
+
|
|
9
|
+
- Prepare TraceWise for the first real PyPI release.
|
|
10
|
+
|
|
11
|
+
## Current Step
|
|
12
|
+
|
|
13
|
+
- Reusable agent contract files were added. The next operational step is the real PyPI upload with a valid PyPI API token.
|
|
14
|
+
|
|
15
|
+
## Done
|
|
16
|
+
|
|
17
|
+
- Added project README, license, author metadata, URLs, and packaging metadata.
|
|
18
|
+
- Added a real optional `httpx` extra for outbound client instrumentation.
|
|
19
|
+
- Fixed `tracewise.init()` so it does not require `httpx` unless `instrument_httpx=True`.
|
|
20
|
+
- Fixed `tracewise.init()` idempotency on the same FastAPI app.
|
|
21
|
+
- Fixed same-app disable and re-enable behavior for `enabled=False`.
|
|
22
|
+
- Verified wheel and source-distribution install paths from isolated targets under `/tmp`.
|
|
23
|
+
- Verified the TestPyPI publish path with a dry run, and the user confirmed TestPyPI upload worked.
|
|
24
|
+
|
|
25
|
+
## Verification
|
|
26
|
+
|
|
27
|
+
- Command: `uv build --out-dir /tmp/tracewise-dist`
|
|
28
|
+
Result: built both `tracewise-0.1.0.tar.gz` and `tracewise-0.1.0-py3-none-any.whl`.
|
|
29
|
+
- Command: isolated wheel and sdist smoke tests from `/tmp`
|
|
30
|
+
Result: package imported from installed artifacts, request tracing worked, and `/tracewise` mounted successfully.
|
|
31
|
+
- Command: `uv publish --dry-run --trusted-publishing never --publish-url https://test.pypi.org/legacy/ --check-url https://test.pypi.org/simple/ /tmp/tracewise-dist/*`
|
|
32
|
+
Result: live TestPyPI dry run succeeded.
|
|
33
|
+
- Not verified: real PyPI upload from this machine, and post-upload install smoke tests from real PyPI.
|
|
34
|
+
|
|
35
|
+
## Pending
|
|
36
|
+
|
|
37
|
+
- Create or export a real PyPI API token in the shell.
|
|
38
|
+
- Upload the built artifacts to real PyPI.
|
|
39
|
+
- Install `tracewise` from real PyPI in a clean environment and run a smoke test.
|
|
40
|
+
|
|
41
|
+
## Risks or Blockers
|
|
42
|
+
|
|
43
|
+
- A valid PyPI API token and 2FA-enabled PyPI account are required for the real upload.
|
|
44
|
+
- PyPI filenames are immutable. If `0.1.0` is already present or a partial upload consumes the filenames, the version must be bumped before retrying.
|
|
45
|
+
- If tracked packaging files change again before release, the distribution artifacts in `/tmp/tracewise-dist` should be rebuilt.
|
|
46
|
+
|
|
47
|
+
## Next Recommended Step
|
|
48
|
+
|
|
49
|
+
- Export `UV_PUBLISH_TOKEN` and run the real `uv publish` command against `https://upload.pypi.org/legacy/`, then verify install from PyPI.
|
|
50
|
+
|
|
51
|
+
## Notes for Next Session
|
|
52
|
+
|
|
53
|
+
- Read `AGENTS.md` first, then this file.
|
|
54
|
+
- If the repo is not clean or if packaging files changed, rebuild artifacts before publishing.
|
|
55
|
+
- After PyPI upload, verify both `tracewise` and `tracewise[httpx]` installs from PyPI in a clean environment.
|