lightrace 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lightrace-0.1.1/.editorconfig +15 -0
- lightrace-0.1.1/.env.example +3 -0
- lightrace-0.1.1/.github/ISSUE_TEMPLATE/config.yml +8 -0
- lightrace-0.1.1/.github/dependabot.yml +9 -0
- lightrace-0.1.1/.github/pull_request_template.md +13 -0
- lightrace-0.1.1/.github/workflows/ci.yml +63 -0
- lightrace-0.1.1/.github/workflows/release.yml +88 -0
- lightrace-0.1.1/.gitignore +15 -0
- lightrace-0.1.1/.pre-commit-config.yaml +9 -0
- lightrace-0.1.1/CHANGELOG.md +10 -0
- lightrace-0.1.1/CONTRIBUTING.md +78 -0
- lightrace-0.1.1/LICENSE +21 -0
- lightrace-0.1.1/PKG-INFO +122 -0
- lightrace-0.1.1/README.md +88 -0
- lightrace-0.1.1/pyproject.toml +84 -0
- lightrace-0.1.1/src/lightrace/__init__.py +8 -0
- lightrace-0.1.1/src/lightrace/client.py +207 -0
- lightrace-0.1.1/src/lightrace/exporter.py +106 -0
- lightrace-0.1.1/src/lightrace/integrations/__init__.py +1 -0
- lightrace-0.1.1/src/lightrace/integrations/langchain.py +579 -0
- lightrace-0.1.1/src/lightrace/observation.py +149 -0
- lightrace-0.1.1/src/lightrace/py.typed +0 -0
- lightrace-0.1.1/src/lightrace/security.py +48 -0
- lightrace-0.1.1/src/lightrace/tool_client.py +240 -0
- lightrace-0.1.1/src/lightrace/trace.py +355 -0
- lightrace-0.1.1/src/lightrace/types.py +58 -0
- lightrace-0.1.1/src/lightrace/utils.py +77 -0
- lightrace-0.1.1/src/lightrace/version.py +1 -0
- lightrace-0.1.1/tests/__init__.py +0 -0
- lightrace-0.1.1/tests/test_exporter.py +72 -0
- lightrace-0.1.1/tests/test_langchain.py +676 -0
- lightrace-0.1.1/tests/test_observation.py +201 -0
- lightrace-0.1.1/tests/test_security.py +50 -0
- lightrace-0.1.1/tests/test_trace.py +289 -0
- lightrace-0.1.1/uv.lock +1361 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
root = true
|
|
2
|
+
|
|
3
|
+
[*]
|
|
4
|
+
indent_style = space
|
|
5
|
+
indent_size = 4
|
|
6
|
+
end_of_line = lf
|
|
7
|
+
charset = utf-8
|
|
8
|
+
trim_trailing_whitespace = true
|
|
9
|
+
insert_final_newline = true
|
|
10
|
+
|
|
11
|
+
[*.md]
|
|
12
|
+
trim_trailing_whitespace = false
|
|
13
|
+
|
|
14
|
+
[*.{yml,yaml,toml,json}]
|
|
15
|
+
indent_size = 2
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
blank_issues_enabled: true
|
|
2
|
+
contact_links:
|
|
3
|
+
- name: Feature Request
|
|
4
|
+
url: https://github.com/SKE-Labs/lightrace-python/discussions/categories/ideas
|
|
5
|
+
about: Suggest a feature or improvement
|
|
6
|
+
- name: Get Help
|
|
7
|
+
url: https://github.com/SKE-Labs/lightrace-python/discussions/categories/q-a
|
|
8
|
+
about: Ask questions and get help from the community
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
|
|
10
|
+
concurrency:
|
|
11
|
+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
|
12
|
+
cancel-in-progress: true
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
lint:
|
|
16
|
+
name: Lint
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
timeout-minutes: 5
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
- uses: astral-sh/ruff-action@v3
|
|
22
|
+
|
|
23
|
+
typecheck:
|
|
24
|
+
name: Type Check
|
|
25
|
+
runs-on: ubuntu-latest
|
|
26
|
+
timeout-minutes: 5
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/checkout@v4
|
|
29
|
+
- uses: astral-sh/setup-uv@v6
|
|
30
|
+
- uses: actions/setup-python@v5
|
|
31
|
+
with:
|
|
32
|
+
python-version: "3.12"
|
|
33
|
+
- run: uv sync --extra dev
|
|
34
|
+
- run: uv run mypy src/lightrace --no-error-summary
|
|
35
|
+
|
|
36
|
+
test:
|
|
37
|
+
name: Test (Python ${{ matrix.python-version }})
|
|
38
|
+
runs-on: ubuntu-latest
|
|
39
|
+
timeout-minutes: 10
|
|
40
|
+
strategy:
|
|
41
|
+
matrix:
|
|
42
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
43
|
+
steps:
|
|
44
|
+
- uses: actions/checkout@v4
|
|
45
|
+
- uses: astral-sh/setup-uv@v6
|
|
46
|
+
- uses: actions/setup-python@v5
|
|
47
|
+
with:
|
|
48
|
+
python-version: ${{ matrix.python-version }}
|
|
49
|
+
- run: uv sync --extra dev
|
|
50
|
+
- run: uv run pytest -s -v tests/
|
|
51
|
+
|
|
52
|
+
all-checks-passed:
|
|
53
|
+
name: All Checks Passed
|
|
54
|
+
runs-on: ubuntu-latest
|
|
55
|
+
needs: [lint, typecheck, test]
|
|
56
|
+
if: always()
|
|
57
|
+
steps:
|
|
58
|
+
- run: |
|
|
59
|
+
if [ "${{ needs.lint.result }}" != "success" ] || \
|
|
60
|
+
[ "${{ needs.typecheck.result }}" != "success" ] || \
|
|
61
|
+
[ "${{ needs.test.result }}" != "success" ]; then
|
|
62
|
+
exit 1
|
|
63
|
+
fi
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
inputs:
|
|
6
|
+
version:
|
|
7
|
+
description: "Version bump type"
|
|
8
|
+
required: true
|
|
9
|
+
type: choice
|
|
10
|
+
options:
|
|
11
|
+
- patch
|
|
12
|
+
- minor
|
|
13
|
+
- major
|
|
14
|
+
dry-run:
|
|
15
|
+
description: "Dry run (no publish)"
|
|
16
|
+
required: false
|
|
17
|
+
type: boolean
|
|
18
|
+
default: false
|
|
19
|
+
|
|
20
|
+
concurrency:
|
|
21
|
+
group: release
|
|
22
|
+
cancel-in-progress: false
|
|
23
|
+
|
|
24
|
+
permissions:
|
|
25
|
+
contents: write
|
|
26
|
+
id-token: write
|
|
27
|
+
|
|
28
|
+
jobs:
|
|
29
|
+
release:
|
|
30
|
+
name: Release
|
|
31
|
+
runs-on: ubuntu-latest
|
|
32
|
+
if: github.ref == 'refs/heads/main'
|
|
33
|
+
steps:
|
|
34
|
+
- uses: actions/checkout@v4
|
|
35
|
+
with:
|
|
36
|
+
fetch-depth: 0
|
|
37
|
+
token: ${{ secrets.RELEASE_TOKEN }}
|
|
38
|
+
|
|
39
|
+
- uses: astral-sh/setup-uv@v6
|
|
40
|
+
|
|
41
|
+
- uses: actions/setup-python@v5
|
|
42
|
+
with:
|
|
43
|
+
python-version: "3.12"
|
|
44
|
+
|
|
45
|
+
- name: Install dependencies
|
|
46
|
+
run: uv sync --extra dev
|
|
47
|
+
|
|
48
|
+
- name: Run tests
|
|
49
|
+
run: uv run pytest -s -v tests/
|
|
50
|
+
|
|
51
|
+
- name: Bump version
|
|
52
|
+
run: |
|
|
53
|
+
CURRENT=$(uv run python -c "from lightrace.version import __version__; print(__version__)")
|
|
54
|
+
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
|
|
55
|
+
case "${{ inputs.version }}" in
|
|
56
|
+
major) NEW="$((MAJOR+1)).0.0" ;;
|
|
57
|
+
minor) NEW="${MAJOR}.$((MINOR+1)).0" ;;
|
|
58
|
+
patch) NEW="${MAJOR}.${MINOR}.$((PATCH+1))" ;;
|
|
59
|
+
esac
|
|
60
|
+
echo "NEW_VERSION=$NEW" >> $GITHUB_ENV
|
|
61
|
+
sed -i "s/version = \"$CURRENT\"/version = \"$NEW\"/" pyproject.toml
|
|
62
|
+
sed -i "s/__version__ = \"$CURRENT\"/__version__ = \"$NEW\"/" src/lightrace/version.py
|
|
63
|
+
|
|
64
|
+
- name: Build
|
|
65
|
+
run: uv build
|
|
66
|
+
|
|
67
|
+
- name: Publish to PyPI
|
|
68
|
+
if: ${{ !inputs.dry-run }}
|
|
69
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
70
|
+
with:
|
|
71
|
+
password: ${{ secrets.PYPI_API_TOKEN }}
|
|
72
|
+
|
|
73
|
+
- name: Commit & tag
|
|
74
|
+
if: ${{ !inputs.dry-run }}
|
|
75
|
+
run: |
|
|
76
|
+
git config user.name "github-actions[bot]"
|
|
77
|
+
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
78
|
+
git add pyproject.toml src/lightrace/version.py
|
|
79
|
+
git commit -m "chore: release v${{ env.NEW_VERSION }}"
|
|
80
|
+
git tag "v${{ env.NEW_VERSION }}"
|
|
81
|
+
git push && git push --tags
|
|
82
|
+
|
|
83
|
+
- name: Create GitHub Release
|
|
84
|
+
if: ${{ !inputs.dry-run }}
|
|
85
|
+
uses: softprops/action-gh-release@v2
|
|
86
|
+
with:
|
|
87
|
+
tag_name: v${{ env.NEW_VERSION }}
|
|
88
|
+
generate_release_notes: true
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
- Initial release
|
|
6
|
+
- Unified `@trace` decorator for all observation types (span, generation, tool, chain, event)
|
|
7
|
+
- Batch exporter compatible with Langfuse v3 ingestion format
|
|
8
|
+
- Remote tool invocation via WebSocket (HMAC-SHA256 signed)
|
|
9
|
+
- Context propagation via `contextvars` (thread-safe, async-safe)
|
|
10
|
+
- Auto-generated JSON Schema from function type hints
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Contributing to lightrace-python
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing!
|
|
4
|
+
|
|
5
|
+
## Development Setup
|
|
6
|
+
|
|
7
|
+
### Prerequisites
|
|
8
|
+
|
|
9
|
+
- Python 3.10+
|
|
10
|
+
- [uv](https://docs.astral.sh/uv/) (recommended) or pip
|
|
11
|
+
|
|
12
|
+
### Quick Start
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
git clone https://github.com/SKE-Labs/lightrace-python.git
|
|
16
|
+
cd lightrace-python
|
|
17
|
+
uv sync --extra dev
|
|
18
|
+
uv run pre-commit install
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Commands
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Testing
|
|
25
|
+
uv run pytest -s -v tests/
|
|
26
|
+
|
|
27
|
+
# Linting & formatting
|
|
28
|
+
uv run ruff check .
|
|
29
|
+
uv run ruff format .
|
|
30
|
+
|
|
31
|
+
# Type checking
|
|
32
|
+
uv run mypy src/lightrace
|
|
33
|
+
|
|
34
|
+
# Pre-commit (all checks)
|
|
35
|
+
uv run pre-commit run --all-files
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Code Quality
|
|
39
|
+
|
|
40
|
+
### Pre-commit Hooks
|
|
41
|
+
|
|
42
|
+
After `pre-commit install`, hooks run automatically on commit:
|
|
43
|
+
- **ruff-check**: Linter with auto-fix
|
|
44
|
+
- **ruff-format**: Code formatter
|
|
45
|
+
|
|
46
|
+
### Style Guide
|
|
47
|
+
|
|
48
|
+
- **Ruff** for linting and formatting (100 char line length)
|
|
49
|
+
- **MyPy** with strict mode for type checking
|
|
50
|
+
- Type hints required on all function definitions
|
|
51
|
+
- Use `from __future__ import annotations` for modern type syntax
|
|
52
|
+
|
|
53
|
+
### Testing
|
|
54
|
+
|
|
55
|
+
We use **pytest** for testing. Tests live in `tests/`.
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# Run all tests
|
|
59
|
+
pytest -s -v tests/
|
|
60
|
+
|
|
61
|
+
# Run specific test
|
|
62
|
+
pytest -s -v tests/test_trace.py::TestTraceDecorator::test_root_trace
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Pull Requests
|
|
66
|
+
|
|
67
|
+
1. Fork the repo and create a feature branch
|
|
68
|
+
2. Write tests for new functionality
|
|
69
|
+
3. Ensure `pytest`, `ruff check .`, and `mypy src/lightrace` pass
|
|
70
|
+
4. Submit a PR with a clear description
|
|
71
|
+
|
|
72
|
+
## Release Process
|
|
73
|
+
|
|
74
|
+
Releases are automated via GitHub Actions. Maintainers trigger the release workflow which handles versioning, building, and PyPI publishing via OIDC.
|
|
75
|
+
|
|
76
|
+
## License
|
|
77
|
+
|
|
78
|
+
MIT
|
lightrace-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Lightrace Contributors
|
|
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.
|
lightrace-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lightrace
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Lightweight LLM tracing SDK with remote tool invocation
|
|
5
|
+
Project-URL: Repository, https://github.com/SKE-Labs/lightrace-python
|
|
6
|
+
Project-URL: Changelog, https://github.com/SKE-Labs/lightrace-python/blob/main/CHANGELOG.md
|
|
7
|
+
Author: Lightrace Contributors
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: langfuse,llm,observability,opentelemetry,tool-invocation,tracing
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: httpx<1,>=0.27
|
|
22
|
+
Requires-Dist: pydantic<3,>=2
|
|
23
|
+
Requires-Dist: websockets<17,>=13
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: mypy>=1.0; extra == 'dev'
|
|
26
|
+
Requires-Dist: pre-commit>=3.2; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
29
|
+
Requires-Dist: respx>=0.22; extra == 'dev'
|
|
30
|
+
Requires-Dist: ruff>=0.15; extra == 'dev'
|
|
31
|
+
Provides-Extra: langchain
|
|
32
|
+
Requires-Dist: langchain-core>=0.2; extra == 'langchain'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# lightrace-python
|
|
36
|
+
|
|
37
|
+
Lightweight LLM tracing SDK for Python with remote tool invocation.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install lightrace
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Quick Start
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from lightrace import Lightrace, trace
|
|
49
|
+
|
|
50
|
+
lt = Lightrace(
|
|
51
|
+
public_key="pk-lt-demo",
|
|
52
|
+
secret_key="sk-lt-demo",
|
|
53
|
+
host="http://localhost:3002",
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
# Root trace
|
|
57
|
+
@trace()
|
|
58
|
+
def run_agent(query: str):
|
|
59
|
+
return search(query)
|
|
60
|
+
|
|
61
|
+
# Span
|
|
62
|
+
@trace(type="span")
|
|
63
|
+
def search(query: str) -> list:
|
|
64
|
+
return ["result1", "result2"]
|
|
65
|
+
|
|
66
|
+
# Generation (LLM call)
|
|
67
|
+
@trace(type="generation", model="gpt-4o")
|
|
68
|
+
def generate(prompt: str) -> str:
|
|
69
|
+
return "LLM response"
|
|
70
|
+
|
|
71
|
+
# Tool — remotely invocable from the Lightrace UI
|
|
72
|
+
@trace(type="tool")
|
|
73
|
+
def weather_lookup(city: str) -> dict:
|
|
74
|
+
return {"temp": 72, "unit": "F"}
|
|
75
|
+
|
|
76
|
+
# Tool — traced but NOT remotely invocable
|
|
77
|
+
@trace(type="tool", invoke=False)
|
|
78
|
+
def read_file(path: str) -> str:
|
|
79
|
+
return open(path).read()
|
|
80
|
+
|
|
81
|
+
run_agent("hello")
|
|
82
|
+
lt.flush()
|
|
83
|
+
lt.shutdown()
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## `@trace` API
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
@trace() # Root trace
|
|
90
|
+
@trace(type="span") # Span observation
|
|
91
|
+
@trace(type="generation", model="gpt-4o") # LLM generation
|
|
92
|
+
@trace(type="tool") # Tool (remotely invocable)
|
|
93
|
+
@trace(type="tool", invoke=False) # Tool (trace only)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Parameters
|
|
97
|
+
|
|
98
|
+
| Parameter | Type | Default | Description |
|
|
99
|
+
| ---------- | ------ | ------- | -------------------------------------------------------- |
|
|
100
|
+
| `type` | `str` | `None` | `"span"`, `"generation"`, `"tool"`, `"chain"`, `"event"` |
|
|
101
|
+
| `name` | `str` | `None` | Override name (defaults to function name) |
|
|
102
|
+
| `invoke` | `bool` | `True` | For `type="tool"`: register for remote invocation |
|
|
103
|
+
| `model` | `str` | `None` | For `type="generation"`: LLM model name |
|
|
104
|
+
| `metadata` | `dict` | `None` | Static metadata attached to every call |
|
|
105
|
+
|
|
106
|
+
## Compatibility
|
|
107
|
+
|
|
108
|
+
Lightrace server also accepts traces from Langfuse Python/JS SDKs.
|
|
109
|
+
|
|
110
|
+
## Development
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
uv sync --extra dev
|
|
114
|
+
uv run pre-commit install
|
|
115
|
+
uv run pytest -s -v tests/
|
|
116
|
+
uv run ruff check .
|
|
117
|
+
uv run mypy src/lightrace
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
MIT
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# lightrace-python
|
|
2
|
+
|
|
3
|
+
Lightweight LLM tracing SDK for Python with remote tool invocation.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install lightrace
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from lightrace import Lightrace, trace
|
|
15
|
+
|
|
16
|
+
lt = Lightrace(
|
|
17
|
+
public_key="pk-lt-demo",
|
|
18
|
+
secret_key="sk-lt-demo",
|
|
19
|
+
host="http://localhost:3002",
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
# Root trace
|
|
23
|
+
@trace()
|
|
24
|
+
def run_agent(query: str):
|
|
25
|
+
return search(query)
|
|
26
|
+
|
|
27
|
+
# Span
|
|
28
|
+
@trace(type="span")
|
|
29
|
+
def search(query: str) -> list:
|
|
30
|
+
return ["result1", "result2"]
|
|
31
|
+
|
|
32
|
+
# Generation (LLM call)
|
|
33
|
+
@trace(type="generation", model="gpt-4o")
|
|
34
|
+
def generate(prompt: str) -> str:
|
|
35
|
+
return "LLM response"
|
|
36
|
+
|
|
37
|
+
# Tool — remotely invocable from the Lightrace UI
|
|
38
|
+
@trace(type="tool")
|
|
39
|
+
def weather_lookup(city: str) -> dict:
|
|
40
|
+
return {"temp": 72, "unit": "F"}
|
|
41
|
+
|
|
42
|
+
# Tool — traced but NOT remotely invocable
|
|
43
|
+
@trace(type="tool", invoke=False)
|
|
44
|
+
def read_file(path: str) -> str:
|
|
45
|
+
return open(path).read()
|
|
46
|
+
|
|
47
|
+
run_agent("hello")
|
|
48
|
+
lt.flush()
|
|
49
|
+
lt.shutdown()
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## `@trace` API
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
@trace() # Root trace
|
|
56
|
+
@trace(type="span") # Span observation
|
|
57
|
+
@trace(type="generation", model="gpt-4o") # LLM generation
|
|
58
|
+
@trace(type="tool") # Tool (remotely invocable)
|
|
59
|
+
@trace(type="tool", invoke=False) # Tool (trace only)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Parameters
|
|
63
|
+
|
|
64
|
+
| Parameter | Type | Default | Description |
|
|
65
|
+
| ---------- | ------ | ------- | -------------------------------------------------------- |
|
|
66
|
+
| `type` | `str` | `None` | `"span"`, `"generation"`, `"tool"`, `"chain"`, `"event"` |
|
|
67
|
+
| `name` | `str` | `None` | Override name (defaults to function name) |
|
|
68
|
+
| `invoke` | `bool` | `True` | For `type="tool"`: register for remote invocation |
|
|
69
|
+
| `model` | `str` | `None` | For `type="generation"`: LLM model name |
|
|
70
|
+
| `metadata` | `dict` | `None` | Static metadata attached to every call |
|
|
71
|
+
|
|
72
|
+
## Compatibility
|
|
73
|
+
|
|
74
|
+
Lightrace server also accepts traces from Langfuse Python/JS SDKs.
|
|
75
|
+
|
|
76
|
+
## Development
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
uv sync --extra dev
|
|
80
|
+
uv run pre-commit install
|
|
81
|
+
uv run pytest -s -v tests/
|
|
82
|
+
uv run ruff check .
|
|
83
|
+
uv run mypy src/lightrace
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
MIT
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "lightrace"
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
description = "Lightweight LLM tracing SDK with remote tool invocation"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [{ name = "Lightrace Contributors" }]
|
|
13
|
+
keywords = ["llm", "tracing", "observability", "langfuse", "opentelemetry", "tool-invocation"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Topic :: Software Development :: Libraries",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"httpx>=0.27,<1",
|
|
27
|
+
"websockets>=13,<17",
|
|
28
|
+
"pydantic>=2,<3",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
Repository = "https://github.com/SKE-Labs/lightrace-python"
|
|
33
|
+
Changelog = "https://github.com/SKE-Labs/lightrace-python/blob/main/CHANGELOG.md"
|
|
34
|
+
|
|
35
|
+
[project.optional-dependencies]
|
|
36
|
+
langchain = ["langchain-core>=0.2"]
|
|
37
|
+
dev = [
|
|
38
|
+
"pytest>=8",
|
|
39
|
+
"pytest-asyncio>=0.24",
|
|
40
|
+
"respx>=0.22",
|
|
41
|
+
"ruff>=0.15",
|
|
42
|
+
"mypy>=1.0",
|
|
43
|
+
"pre-commit>=3.2",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
[tool.hatch.build.targets.wheel]
|
|
47
|
+
packages = ["src/lightrace"]
|
|
48
|
+
|
|
49
|
+
[tool.pytest.ini_options]
|
|
50
|
+
testpaths = ["tests"]
|
|
51
|
+
asyncio_mode = "auto"
|
|
52
|
+
log_cli = true
|
|
53
|
+
|
|
54
|
+
[tool.ruff]
|
|
55
|
+
target-version = "py310"
|
|
56
|
+
line-length = 100
|
|
57
|
+
|
|
58
|
+
[tool.ruff.lint]
|
|
59
|
+
select = ["E", "F", "I", "W"]
|
|
60
|
+
|
|
61
|
+
[tool.ruff.format]
|
|
62
|
+
quote-style = "double"
|
|
63
|
+
|
|
64
|
+
[tool.mypy]
|
|
65
|
+
python_version = "3.12"
|
|
66
|
+
warn_return_any = true
|
|
67
|
+
disallow_untyped_defs = true
|
|
68
|
+
disallow_incomplete_defs = true
|
|
69
|
+
check_untyped_defs = true
|
|
70
|
+
no_implicit_optional = true
|
|
71
|
+
warn_redundant_casts = true
|
|
72
|
+
warn_no_return = true
|
|
73
|
+
warn_unreachable = true
|
|
74
|
+
strict_equality = true
|
|
75
|
+
show_error_codes = true
|
|
76
|
+
show_column_numbers = true
|
|
77
|
+
|
|
78
|
+
[[tool.mypy.overrides]]
|
|
79
|
+
module = ["websockets.*"]
|
|
80
|
+
ignore_missing_imports = true
|
|
81
|
+
|
|
82
|
+
[[tool.mypy.overrides]]
|
|
83
|
+
module = ["langchain_core.*"]
|
|
84
|
+
ignore_missing_imports = true
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""Lightrace — lightweight LLM tracing SDK with remote tool invocation."""
|
|
2
|
+
|
|
3
|
+
from .client import Lightrace
|
|
4
|
+
from .observation import Observation
|
|
5
|
+
from .trace import trace
|
|
6
|
+
from .version import __version__
|
|
7
|
+
|
|
8
|
+
__all__ = ["Lightrace", "Observation", "trace", "__version__"]
|