traceops 0.5.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.
Files changed (96) hide show
  1. traceops-0.5.0/.github/actions/agent-replay/action.yml +138 -0
  2. traceops-0.5.0/.github/workflows/ci.yml +37 -0
  3. traceops-0.5.0/.gitignore +46 -0
  4. traceops-0.5.0/.pypirc.template +14 -0
  5. traceops-0.5.0/CHANGELOG.md +78 -0
  6. traceops-0.5.0/LICENSE +21 -0
  7. traceops-0.5.0/PKG-INFO +436 -0
  8. traceops-0.5.0/README.md +349 -0
  9. traceops-0.5.0/agent_replay_demo.ipynb +10 -0
  10. traceops-0.5.0/examples/langchain_chat.py +53 -0
  11. traceops-0.5.0/examples/langgraph_react.py +55 -0
  12. traceops-0.5.0/examples/openai_basic.py +43 -0
  13. traceops-0.5.0/examples/pytest_usage.py +74 -0
  14. traceops-0.5.0/pyproject.toml +127 -0
  15. traceops-0.5.0/src/trace_ops/__init__.py +153 -0
  16. traceops-0.5.0/src/trace_ops/_types.py +356 -0
  17. traceops-0.5.0/src/trace_ops/assertions.py +129 -0
  18. traceops-0.5.0/src/trace_ops/cassette.py +154 -0
  19. traceops-0.5.0/src/trace_ops/cli.py +810 -0
  20. traceops-0.5.0/src/trace_ops/diff.py +295 -0
  21. traceops-0.5.0/src/trace_ops/export/__init__.py +20 -0
  22. traceops-0.5.0/src/trace_ops/export/finetune.py +143 -0
  23. traceops-0.5.0/src/trace_ops/interceptors/__init__.py +10 -0
  24. traceops-0.5.0/src/trace_ops/interceptors/crewai.py +200 -0
  25. traceops-0.5.0/src/trace_ops/interceptors/langchain.py +375 -0
  26. traceops-0.5.0/src/trace_ops/interceptors/langgraph.py +319 -0
  27. traceops-0.5.0/src/trace_ops/mcp/__init__.py +31 -0
  28. traceops-0.5.0/src/trace_ops/mcp/diff.py +133 -0
  29. traceops-0.5.0/src/trace_ops/mcp/events.py +42 -0
  30. traceops-0.5.0/src/trace_ops/mcp/interceptor.py +146 -0
  31. traceops-0.5.0/src/trace_ops/normalize.py +238 -0
  32. traceops-0.5.0/src/trace_ops/pytest_plugin.py +314 -0
  33. traceops-0.5.0/src/trace_ops/rag/__init__.py +71 -0
  34. traceops-0.5.0/src/trace_ops/rag/assertions.py +271 -0
  35. traceops-0.5.0/src/trace_ops/rag/context_analysis.py +227 -0
  36. traceops-0.5.0/src/trace_ops/rag/diff.py +231 -0
  37. traceops-0.5.0/src/trace_ops/rag/export.py +269 -0
  38. traceops-0.5.0/src/trace_ops/rag/interceptors/__init__.py +27 -0
  39. traceops-0.5.0/src/trace_ops/rag/interceptors/chromadb_interceptor.py +66 -0
  40. traceops-0.5.0/src/trace_ops/rag/interceptors/embedding_interceptor.py +54 -0
  41. traceops-0.5.0/src/trace_ops/rag/interceptors/langchain_retriever.py +63 -0
  42. traceops-0.5.0/src/trace_ops/rag/interceptors/llamaindex_retriever.py +58 -0
  43. traceops-0.5.0/src/trace_ops/rag/interceptors/pinecone_interceptor.py +54 -0
  44. traceops-0.5.0/src/trace_ops/rag/interceptors/qdrant_interceptor.py +47 -0
  45. traceops-0.5.0/src/trace_ops/rag/recorder.py +93 -0
  46. traceops-0.5.0/src/trace_ops/rag/scorers.py +210 -0
  47. traceops-0.5.0/src/trace_ops/rag/snapshot.py +335 -0
  48. traceops-0.5.0/src/trace_ops/recorder.py +972 -0
  49. traceops-0.5.0/src/trace_ops/replayer.py +626 -0
  50. traceops-0.5.0/src/trace_ops/reporters/__init__.py +6 -0
  51. traceops-0.5.0/src/trace_ops/reporters/cost_dashboard.py +243 -0
  52. traceops-0.5.0/src/trace_ops/reporters/html.py +323 -0
  53. traceops-0.5.0/src/trace_ops/reporters/terminal.py +304 -0
  54. traceops-0.5.0/src/trace_ops/semantic/__init__.py +31 -0
  55. traceops-0.5.0/src/trace_ops/semantic/assertions.py +57 -0
  56. traceops-0.5.0/src/trace_ops/semantic/similarity.py +163 -0
  57. traceops-0.5.0/src/trace_ops/streaming.py +570 -0
  58. traceops-0.5.0/tests/conftest.py +1 -0
  59. traceops-0.5.0/tests/test_assertions.py +164 -0
  60. traceops-0.5.0/tests/test_assertions_extended.py +303 -0
  61. traceops-0.5.0/tests/test_auto_record.py +205 -0
  62. traceops-0.5.0/tests/test_cassette.py +104 -0
  63. traceops-0.5.0/tests/test_cli_deep.py +303 -0
  64. traceops-0.5.0/tests/test_cli_extended.py +211 -0
  65. traceops-0.5.0/tests/test_cost_dashboard.py +322 -0
  66. traceops-0.5.0/tests/test_crewai_interceptor.py +288 -0
  67. traceops-0.5.0/tests/test_diff.py +97 -0
  68. traceops-0.5.0/tests/test_diff_extended.py +333 -0
  69. traceops-0.5.0/tests/test_export_finetune.py +335 -0
  70. traceops-0.5.0/tests/test_integration_anthropic.py +235 -0
  71. traceops-0.5.0/tests/test_integration_langchain.py +278 -0
  72. traceops-0.5.0/tests/test_integration_langgraph.py +457 -0
  73. traceops-0.5.0/tests/test_integration_openai.py +268 -0
  74. traceops-0.5.0/tests/test_mcp.py +223 -0
  75. traceops-0.5.0/tests/test_normalize.py +261 -0
  76. traceops-0.5.0/tests/test_normalize_extended.py +418 -0
  77. traceops-0.5.0/tests/test_pytest_plugin.py +279 -0
  78. traceops-0.5.0/tests/test_rag_assertions.py +187 -0
  79. traceops-0.5.0/tests/test_rag_diff.py +171 -0
  80. traceops-0.5.0/tests/test_rag_export.py +164 -0
  81. traceops-0.5.0/tests/test_rag_recording.py +227 -0
  82. traceops-0.5.0/tests/test_rag_snapshot.py +225 -0
  83. traceops-0.5.0/tests/test_recorder.py +85 -0
  84. traceops-0.5.0/tests/test_recorder_extended.py +486 -0
  85. traceops-0.5.0/tests/test_recorder_patching.py +877 -0
  86. traceops-0.5.0/tests/test_replayer.py +196 -0
  87. traceops-0.5.0/tests/test_replayer_extended.py +344 -0
  88. traceops-0.5.0/tests/test_replayer_patching.py +434 -0
  89. traceops-0.5.0/tests/test_reporters_html.py +101 -0
  90. traceops-0.5.0/tests/test_reporters_html_extended.py +315 -0
  91. traceops-0.5.0/tests/test_reporters_terminal.py +136 -0
  92. traceops-0.5.0/tests/test_reporters_terminal_render.py +429 -0
  93. traceops-0.5.0/tests/test_semantic.py +247 -0
  94. traceops-0.5.0/tests/test_streaming.py +291 -0
  95. traceops-0.5.0/tests/test_types.py +131 -0
  96. traceops-0.5.0/tests/test_types_extended.py +417 -0
@@ -0,0 +1,138 @@
1
+ name: "TraceOps"
2
+ description: "Record and replay LLM agent traces for regression testing in CI"
3
+ branding:
4
+ icon: "refresh-cw"
5
+ color: "blue"
6
+
7
+ inputs:
8
+ cassette-dir:
9
+ description: "Directory containing cassette files"
10
+ required: false
11
+ default: "cassettes"
12
+ record-mode:
13
+ description: "Recording mode: none, once, new, all"
14
+ required: false
15
+ default: "once"
16
+ python-version:
17
+ description: "Python version to use"
18
+ required: false
19
+ default: "3.12"
20
+ requirements:
21
+ description: "Extra pip requirements to install (space-separated or path to requirements.txt)"
22
+ required: false
23
+ default: ""
24
+ pytest-args:
25
+ description: "Additional arguments to pass to pytest"
26
+ required: false
27
+ default: ""
28
+ post-diff-comment:
29
+ description: "Post a PR comment with trace diff on failure (requires GITHUB_TOKEN)"
30
+ required: false
31
+ default: "true"
32
+
33
+ outputs:
34
+ result:
35
+ description: "Test result: passed, failed, or error"
36
+ value: ${{ steps.test.outputs.result }}
37
+ diff-summary:
38
+ description: "Trace diff summary (if regression detected)"
39
+ value: ${{ steps.diff.outputs.summary }}
40
+
41
+ runs:
42
+ using: "composite"
43
+ steps:
44
+ - name: Set up Python
45
+ uses: actions/setup-python@v5
46
+ with:
47
+ python-version: ${{ inputs.python-version }}
48
+
49
+ - name: Install TraceOps
50
+ shell: bash
51
+ run: |
52
+ python -m pip install --upgrade pip
53
+ pip install traceops[all]
54
+
55
+ - name: Install extra requirements
56
+ shell: bash
57
+ if: inputs.requirements != ''
58
+ run: |
59
+ if [ -f "${{ inputs.requirements }}" ]; then
60
+ pip install -r "${{ inputs.requirements }}"
61
+ else
62
+ pip install ${{ inputs.requirements }}
63
+ fi
64
+
65
+ - name: Run tests with TraceOps
66
+ id: test
67
+ shell: bash
68
+ continue-on-error: true
69
+ run: |
70
+ set +e
71
+ pytest --record-mode=${{ inputs.record-mode }} ${{ inputs.pytest-args }} 2>&1 | tee test_output.txt
72
+ EXIT_CODE=${PIPESTATUS[0]}
73
+ if [ $EXIT_CODE -eq 0 ]; then
74
+ echo "result=passed" >> $GITHUB_OUTPUT
75
+ else
76
+ echo "result=failed" >> $GITHUB_OUTPUT
77
+ fi
78
+ exit $EXIT_CODE
79
+
80
+ - name: Generate diff on failure
81
+ id: diff
82
+ shell: bash
83
+ if: steps.test.outputs.result == 'failed'
84
+ run: |
85
+ echo "## 🔁 TraceOps Regression Report" > diff_report.md
86
+ echo "" >> diff_report.md
87
+
88
+ # Find cassettes that have changed
89
+ CASSETTE_DIR="${{ inputs.cassette-dir }}"
90
+ if [ -d "$CASSETTE_DIR" ]; then
91
+ CHANGED=$(git diff --name-only HEAD -- "$CASSETTE_DIR" 2>/dev/null || echo "")
92
+ if [ -n "$CHANGED" ]; then
93
+ echo "### Changed Cassettes" >> diff_report.md
94
+ echo '```' >> diff_report.md
95
+ echo "$CHANGED" >> diff_report.md
96
+ echo '```' >> diff_report.md
97
+ fi
98
+ fi
99
+
100
+ echo "" >> diff_report.md
101
+ echo "### Test Output (last 50 lines)" >> diff_report.md
102
+ echo '```' >> diff_report.md
103
+ tail -50 test_output.txt >> diff_report.md
104
+ echo '```' >> diff_report.md
105
+
106
+ SUMMARY=$(cat diff_report.md)
107
+ # Escape for GitHub output
108
+ SUMMARY="${SUMMARY//'%'/'%25'}"
109
+ SUMMARY="${SUMMARY//$'\n'/'%0A'}"
110
+ SUMMARY="${SUMMARY//$'\r'/'%0D'}"
111
+ echo "summary=$SUMMARY" >> $GITHUB_OUTPUT
112
+
113
+ - name: Post PR comment
114
+ if: >
115
+ steps.test.outputs.result == 'failed' &&
116
+ inputs.post-diff-comment == 'true' &&
117
+ github.event_name == 'pull_request'
118
+ uses: actions/github-script@v7
119
+ with:
120
+ script: |
121
+ const fs = require('fs');
122
+ let body = '## 🔁 TraceOps Regression Detected\n\n';
123
+ try {
124
+ body += fs.readFileSync('diff_report.md', 'utf8');
125
+ } catch (e) {
126
+ body += 'See test output for details.';
127
+ }
128
+ await github.rest.issues.createComment({
129
+ owner: context.repo.owner,
130
+ repo: context.repo.repo,
131
+ issue_number: context.issue.number,
132
+ body: body.slice(0, 65536),
133
+ });
134
+
135
+ - name: Fail if tests failed
136
+ shell: bash
137
+ if: steps.test.outputs.result == 'failed'
138
+ run: exit 1
@@ -0,0 +1,37 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Set up Python ${{ matrix.python-version }}
20
+ uses: actions/setup-python@v5
21
+ with:
22
+ python-version: ${{ matrix.python-version }}
23
+
24
+ - name: Install dependencies
25
+ run: |
26
+ python -m pip install --upgrade pip
27
+ pip install -e ".[dev]"
28
+
29
+ - name: Lint
30
+ run: ruff check src/ tests/
31
+
32
+ - name: Test
33
+ run: pytest --tb=short -q
34
+
35
+ - name: Type check
36
+ run: mypy src/trace_ops/ --ignore-missing-imports
37
+ if: matrix.python-version == '3.12'
@@ -0,0 +1,46 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.pyo
5
+ *.pyd
6
+ *.egg
7
+ *.egg-info/
8
+ dist/
9
+ build/
10
+ .eggs/
11
+ *.whl
12
+
13
+ # Virtual environments
14
+ .venv/
15
+ venv/
16
+ env/
17
+ ENV/
18
+
19
+ # Pytest / coverage
20
+ .pytest_cache/
21
+ .coverage
22
+ htmlcov/
23
+ coverage.xml
24
+
25
+ # Mypy
26
+ .mypy_cache/
27
+
28
+ # Ruff
29
+ .ruff_cache/
30
+
31
+ # IDE
32
+ .vscode/
33
+ .idea/
34
+ *.swp
35
+ *.swo
36
+
37
+ # OS
38
+ .DS_Store
39
+ Thumbs.db
40
+
41
+ # Hatch
42
+ .hatch/
43
+
44
+ # Dist artifacts
45
+ dist/
46
+ *.tar.gz
@@ -0,0 +1,14 @@
1
+ [distutils]
2
+ index-servers =
3
+ pypi
4
+ testpypi
5
+
6
+ [pypi]
7
+ repository = https://upload.pypi.org/legacy/
8
+ username = __token__
9
+ password = pypi-REPLACE_WITH_YOUR_PRODUCTION_TOKEN
10
+
11
+ [testpypi]
12
+ repository = https://test.pypi.org/legacy/
13
+ username = __token__
14
+ password = pypi-REPLACE_WITH_YOUR_TEST_TOKEN
@@ -0,0 +1,78 @@
1
+ # Changelog
2
+
3
+ All notable changes to **TraceOps** will be documented in this file.
4
+
5
+ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ---
9
+
10
+ ## [0.4.0] — 2025-01-27
11
+
12
+ ### Added
13
+ - **Cost Dashboard** — new `replay costs [dir]` CLI command aggregating spend
14
+ across cassettes, with per-model and per-cassette breakdowns. Also available
15
+ programmatically via `CostDashboard` / `CostSummary`.
16
+ - **Enhanced `replay diff`** — `--detailed` flag for per-event side-by-side
17
+ comparison and `--output` flag to write an HTML diff report.
18
+ - **Auto-record mode** — `--record-mode auto` (and `AGENT_REPLAY_RECORD` /
19
+ `AGENT_REPLAY_MODE` environment variables) for zero-config "record if
20
+ missing, replay if exists" workflow.
21
+ - Exported `CostDashboard` and `CostSummary` from the top-level package.
22
+ - 100 new tests (529 total), raising coverage from 75 % → 77 %.
23
+
24
+ ### Changed
25
+ - Harmonised version strings across CLI, HTML reporter, types, and
26
+ `pyproject.toml` (all now `0.4.0`).
27
+
28
+ ### Fixed
29
+ - `replay diff` no longer silently swallows HTML-output errors.
30
+
31
+ ---
32
+
33
+ ## [0.3.0] — 2025-01-26
34
+
35
+ ### Added
36
+ - **Framework interceptors** — first-class LangChain, LangGraph, and CrewAI
37
+ support via `interceptors/` sub-package.
38
+ - **Integration test suite** — end-to-end tests for OpenAI, Anthropic,
39
+ LangChain, and LangGraph recording/replay.
40
+ - **pytest plugin tests** — full coverage of `--record`, `--record-mode`,
41
+ `--replay-strict`, `cassette` fixture, `trace_snapshot` fixture, and the
42
+ `@pytest.mark.budget` marker.
43
+ - Example scripts under `examples/`.
44
+ - README refresh with quick-start, architecture diagram, and badge row.
45
+
46
+ ---
47
+
48
+ ## [0.2.0] — 2025-01-25
49
+
50
+ ### Added
51
+ - **Async & streaming support** — `async with Recorder()` / `Replayer()`,
52
+ plus transparent streaming-response replay.
53
+ - **Normalization engine** — `normalize_response()` and
54
+ `normalize_for_comparison()` for provider-agnostic diffing.
55
+ - **Budget assertions** — `assert_cost_under`, `assert_tokens_under`,
56
+ `assert_max_llm_calls`, `assert_no_loops`.
57
+ - **HTML trace reports** — `generate_html_report()` with inline CSS/JS,
58
+ dark theme, token bar chart, and expandable event details.
59
+ - **Terminal debugger** — interactive time-travel debugger (`replay debug`).
60
+ - **CLI commands** — `replay inspect`, `diff`, `export`, `debug`, `report`,
61
+ `ls`, `prune`, `stats`, `validate`.
62
+ - **Cassette management** — `save_cassette` / `load_cassette` with YAML
63
+ storage, automatic redaction of API keys.
64
+ - **Diff engine** — `diff_traces` / `assert_trace_unchanged` with DeepDiff
65
+ integration.
66
+
67
+ ---
68
+
69
+ ## [0.1.0] — 2025-01-24
70
+
71
+ ### Added
72
+ - Initial release.
73
+ - `Recorder` context-manager with monkey-patching for OpenAI, Anthropic,
74
+ and LiteLLM (sync only).
75
+ - `Replayer` context-manager returning stored responses.
76
+ - Core data model: `Trace`, `TraceEvent`, `TraceMetadata`, `EventType`.
77
+ - YAML cassette serialization.
78
+ - pytest plugin with `--record` flag and `agent_cassette` marker.
traceops-0.5.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Joshua
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.