modaltrace 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.
- modaltrace-0.1.0/.github/workflows/ci.yml +45 -0
- modaltrace-0.1.0/.gitignore +21 -0
- modaltrace-0.1.0/LICENSE +15 -0
- modaltrace-0.1.0/PKG-INFO +32 -0
- modaltrace-0.1.0/README.md +224 -0
- modaltrace-0.1.0/plan.md +1024 -0
- modaltrace-0.1.0/pyproject.toml +61 -0
- modaltrace-0.1.0/src/modaltrace/__init__.py +244 -0
- modaltrace-0.1.0/src/modaltrace/_registry.py +25 -0
- modaltrace-0.1.0/src/modaltrace/_version.py +2 -0
- modaltrace-0.1.0/src/modaltrace/config.py +92 -0
- modaltrace-0.1.0/src/modaltrace/conventions/__init__.py +19 -0
- modaltrace-0.1.0/src/modaltrace/conventions/attributes.py +66 -0
- modaltrace-0.1.0/src/modaltrace/exporters/__init__.py +0 -0
- modaltrace-0.1.0/src/modaltrace/exporters/setup.py +126 -0
- modaltrace-0.1.0/src/modaltrace/instrumentation/__init__.py +0 -0
- modaltrace-0.1.0/src/modaltrace/instrumentation/eventloop.py +47 -0
- modaltrace-0.1.0/src/modaltrace/instrumentation/gpu.py +170 -0
- modaltrace-0.1.0/src/modaltrace/instrumentation/pytorch.py +153 -0
- modaltrace-0.1.0/src/modaltrace/instrumentation/transport.py +82 -0
- modaltrace-0.1.0/src/modaltrace/logging/__init__.py +0 -0
- modaltrace-0.1.0/src/modaltrace/logging/api.py +217 -0
- modaltrace-0.1.0/src/modaltrace/logging/scrubber.py +107 -0
- modaltrace-0.1.0/src/modaltrace/metrics/__init__.py +0 -0
- modaltrace-0.1.0/src/modaltrace/metrics/aggregator.py +122 -0
- modaltrace-0.1.0/src/modaltrace/metrics/av_sync.py +108 -0
- modaltrace-0.1.0/src/modaltrace/metrics/instruments.py +67 -0
- modaltrace-0.1.0/src/modaltrace/tracing/__init__.py +0 -0
- modaltrace-0.1.0/src/modaltrace/tracing/pending.py +124 -0
- modaltrace-0.1.0/src/modaltrace/tracing/pipeline.py +210 -0
- modaltrace-0.1.0/src/modaltrace/tracing/propagation.py +132 -0
- modaltrace-0.1.0/src/modaltrace/tracing/sampler.py +57 -0
- modaltrace-0.1.0/tests/__init__.py +0 -0
- modaltrace-0.1.0/tests/conftest.py +1 -0
- modaltrace-0.1.0/tests/test_aggregator.py +98 -0
- modaltrace-0.1.0/tests/test_av_sync.py +112 -0
- modaltrace-0.1.0/tests/test_eventloop.py +131 -0
- modaltrace-0.1.0/tests/test_gpu_monitor.py +68 -0
- modaltrace-0.1.0/tests/test_logging_api.py +339 -0
- modaltrace-0.1.0/tests/test_pending_spans.py +294 -0
- modaltrace-0.1.0/tests/test_pipeline.py +156 -0
- modaltrace-0.1.0/tests/test_propagation.py +220 -0
- modaltrace-0.1.0/tests/test_pytorch_instrumentation.py +117 -0
- modaltrace-0.1.0/tests/test_sampler.py +45 -0
- modaltrace-0.1.0/tests/test_scrubber.py +293 -0
- modaltrace-0.1.0/tests/test_transport.py +336 -0
- modaltrace-0.1.0/uv.lock +2062 -0
|
@@ -0,0 +1,45 @@
|
|
|
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"]
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Install uv
|
|
19
|
+
uses: astral-sh/setup-uv@v4
|
|
20
|
+
|
|
21
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
22
|
+
uses: actions/setup-python@v5
|
|
23
|
+
with:
|
|
24
|
+
python-version: ${{ matrix.python-version }}
|
|
25
|
+
|
|
26
|
+
- name: Install dependencies
|
|
27
|
+
run: uv pip install -e ".[dev]" --system
|
|
28
|
+
|
|
29
|
+
- name: Lint
|
|
30
|
+
run: ruff check src/ tests/
|
|
31
|
+
|
|
32
|
+
- name: Test
|
|
33
|
+
run: pytest tests/ -v --tb=short
|
|
34
|
+
|
|
35
|
+
lint:
|
|
36
|
+
runs-on: ubuntu-latest
|
|
37
|
+
steps:
|
|
38
|
+
- uses: actions/checkout@v4
|
|
39
|
+
- uses: astral-sh/setup-uv@v4
|
|
40
|
+
- uses: actions/setup-python@v5
|
|
41
|
+
with:
|
|
42
|
+
python-version: "3.12"
|
|
43
|
+
- run: uv pip install -e ".[dev]" --system
|
|
44
|
+
- run: ruff check src/ tests/
|
|
45
|
+
- run: ruff format --check src/ tests/
|
modaltrace-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: modaltrace
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: OpenTelemetry observability library for real-time AI applications
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Requires-Dist: opentelemetry-api>=1.24.0
|
|
9
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-grpc>=1.24.0
|
|
10
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.24.0
|
|
11
|
+
Requires-Dist: opentelemetry-sdk>=1.24.0
|
|
12
|
+
Requires-Dist: pydantic-settings>=2.2.0
|
|
13
|
+
Requires-Dist: pydantic>=2.6.0
|
|
14
|
+
Requires-Dist: wrapt>=1.16.0
|
|
15
|
+
Provides-Extra: all
|
|
16
|
+
Requires-Dist: aiortc>=1.9.0; extra == 'all'
|
|
17
|
+
Requires-Dist: pynvml>=11.5.0; extra == 'all'
|
|
18
|
+
Requires-Dist: torch>=2.0.0; extra == 'all'
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: mypy>=1.9.0; extra == 'dev'
|
|
21
|
+
Requires-Dist: pre-commit>=3.7.0; extra == 'dev'
|
|
22
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
|
|
23
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
|
|
24
|
+
Requires-Dist: pytest-mock>=3.12.0; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
26
|
+
Requires-Dist: ruff>=0.4.0; extra == 'dev'
|
|
27
|
+
Provides-Extra: gpu
|
|
28
|
+
Requires-Dist: pynvml>=11.5.0; extra == 'gpu'
|
|
29
|
+
Provides-Extra: pytorch
|
|
30
|
+
Requires-Dist: torch>=2.0.0; extra == 'pytorch'
|
|
31
|
+
Provides-Extra: webrtc
|
|
32
|
+
Requires-Dist: aiortc>=1.9.0; extra == 'webrtc'
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# ModalTrace
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
6
|
+
[](https://pypi.org/project/modaltrace/)
|
|
7
|
+
[](https://www.python.org/downloads/)
|
|
8
|
+
[](https://github.com/arnabdeypolimi/video-ai-telemetry/actions)
|
|
9
|
+
|
|
10
|
+
**OpenTelemetry observability for real-time AI video applications**
|
|
11
|
+
|
|
12
|
+
[Documentation](https://github.com/arnabdeypolimi/video-ai-telemetry/wiki) • [Issues](https://github.com/arnabdeypolimi/video-ai-telemetry/issues) • [Contributing](./CONTRIBUTING.md)
|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 🚀 What is ModalTrace?
|
|
19
|
+
|
|
20
|
+
ModalTrace is an open-source OpenTelemetry library that provides production-grade observability for real-time AI video applications. It captures traces, metrics, and logs across your entire ML pipeline—from GPU operations and neural network inference to video rendering and transport layer performance.
|
|
21
|
+
|
|
22
|
+
Built for **production AI systems**, ModalTrace helps you understand latency bottlenecks, monitor resource utilization, and debug performance issues in complex distributed video AI pipelines.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## ✨ Features
|
|
27
|
+
|
|
28
|
+
**📊 Comprehensive Observability**
|
|
29
|
+
Trace execution paths across your entire pipeline with automatic span generation for each processing stage. Correlate traces with structured logging and metrics for complete visibility.
|
|
30
|
+
|
|
31
|
+
**⚡ Real-time Metrics**
|
|
32
|
+
Monitor frame rates, GPU memory allocation, inference latency, and synchronization drift with sub-millisecond precision. Built-in ring buffer aggregation for efficient metric collection.
|
|
33
|
+
|
|
34
|
+
**🔍 Semantic Conventions**
|
|
35
|
+
All telemetry uses standardized attribute keys (`modaltrace.*`) eliminating magic strings and enabling consistent instrumentation across teams.
|
|
36
|
+
|
|
37
|
+
**🧠 PyTorch & GPU Instrumentation**
|
|
38
|
+
Automatic instrumentation of PyTorch operations, GPU memory tracking, and device utilization metrics. Understand exactly where your model is spending time.
|
|
39
|
+
|
|
40
|
+
**🎬 Audio/Video Synchronization Tracking**
|
|
41
|
+
Detect and monitor A/V sync drift with configurable thresholds. Automatically log chunk mismatches and jitter metrics.
|
|
42
|
+
|
|
43
|
+
**🎯 Adaptive Sampling**
|
|
44
|
+
Intelligent span sampling based on anomaly detection. Automatically capture high-latency frames and unusual execution patterns without overwhelming your backend.
|
|
45
|
+
|
|
46
|
+
**🛡️ PII Scrubbing**
|
|
47
|
+
Built-in scrubbing pipeline removes sensitive data from logs and attributes. Customizable patterns for your specific compliance needs.
|
|
48
|
+
|
|
49
|
+
**📡 OpenTelemetry Export**
|
|
50
|
+
Native support for OTLP over HTTP and gRPC. Export to any OpenTelemetry-compatible backend: Jaeger, Datadog, New Relic, Honeycomb, or on-prem observability stacks.
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 🚀 Quick Start
|
|
55
|
+
|
|
56
|
+
### 1. Install
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install modaltrace
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
For optional features:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install modaltrace[pytorch,gpu,webrtc]
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 2. Configure & Initialize
|
|
69
|
+
|
|
70
|
+
Create a `.env` file or set environment variables:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
MODALTRACE_SERVICE_NAME=my-video-pipeline
|
|
74
|
+
MODALTRACE_OTLP_ENDPOINT=http://localhost:4318
|
|
75
|
+
MODALTRACE_PYTORCH_INSTRUMENTATION=true
|
|
76
|
+
MODALTRACE_GPU_MONITORING=true
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Initialize the SDK in your application:
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from modaltrace import ModalTraceSDK
|
|
83
|
+
|
|
84
|
+
sdk = ModalTraceSDK()
|
|
85
|
+
sdk.start()
|
|
86
|
+
|
|
87
|
+
# Your ML pipeline code here
|
|
88
|
+
# Spans are automatically created for instrumented operations
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### 3. View Telemetry
|
|
92
|
+
|
|
93
|
+
Access your traces at your observability backend (e.g., `http://localhost:16686` for Jaeger):
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
# Start a pipeline span
|
|
97
|
+
from modaltrace import get_tracer
|
|
98
|
+
tracer = get_tracer(__name__)
|
|
99
|
+
|
|
100
|
+
with tracer.start_as_current_span("process_frame") as span:
|
|
101
|
+
span.set_attribute("modaltrace.pipeline.frame.sequence_number", frame_id)
|
|
102
|
+
# Your frame processing logic here
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## ⚙️ Configuration
|
|
108
|
+
|
|
109
|
+
All configuration is available via environment variables (prefix: `MODALTRACE_`) or Python kwargs to `ModalTraceConfig`:
|
|
110
|
+
|
|
111
|
+
| Setting | Env Variable | Type | Default | Description |
|
|
112
|
+
|---------|-------------|------|---------|-------------|
|
|
113
|
+
| **Service Identity** |
|
|
114
|
+
| `service_name` | `MODALTRACE_SERVICE_NAME` | str | `modaltrace-pipeline` | Service identifier in telemetry |
|
|
115
|
+
| `service_version` | `MODALTRACE_SERVICE_VERSION` | str | `0.0.0` | Semantic version of your service |
|
|
116
|
+
| `deployment_environment` | `MODALTRACE_DEPLOYMENT_ENVIRONMENT` | str | `development` | Environment (dev/staging/prod) |
|
|
117
|
+
| **OTLP Export** |
|
|
118
|
+
| `otlp_endpoint` | `MODALTRACE_OTLP_ENDPOINT` | URL | `http://localhost:4318` | OpenTelemetry collector endpoint |
|
|
119
|
+
| `otlp_protocol` | `MODALTRACE_OTLP_PROTOCOL` | str | `http` | Protocol: `http` or `grpc` |
|
|
120
|
+
| `otlp_timeout_ms` | `MODALTRACE_OTLP_TIMEOUT_MS` | int | `10000` | Export timeout in milliseconds |
|
|
121
|
+
| **Feature Flags** |
|
|
122
|
+
| `pytorch_instrumentation` | `MODALTRACE_PYTORCH_INSTRUMENTATION` | bool | `true` | Auto-instrument PyTorch ops |
|
|
123
|
+
| `gpu_monitoring` | `MODALTRACE_GPU_MONITORING` | bool | `true` | Track GPU metrics |
|
|
124
|
+
| `webrtc_monitoring` | `MODALTRACE_WEBRTC_MONITORING` | bool | `false` | Monitor WebRTC transports |
|
|
125
|
+
| `eventloop_monitoring` | `MODALTRACE_EVENTLOOP_MONITORING` | bool | `true` | Track event loop blocks |
|
|
126
|
+
| **Sampler** |
|
|
127
|
+
| `pytorch_sample_rate` | `MODALTRACE_PYTORCH_SAMPLE_RATE` | float (0-1) | `0.01` | Fraction of PyTorch ops to sample |
|
|
128
|
+
| `anomaly_threshold_ms` | `MODALTRACE_ANOMALY_THRESHOLD_MS` | float | `50.0` | Latency threshold for anomaly capture |
|
|
129
|
+
| **Metrics** |
|
|
130
|
+
| `metrics_flush_interval_ms` | `MODALTRACE_METRICS_FLUSH_INTERVAL_MS` | int | `1000` | Metric aggregation window |
|
|
131
|
+
| `ring_buffer_size` | `MODALTRACE_RING_BUFFER_SIZE` | int | `512` | Must be power of 2 |
|
|
132
|
+
| **A/V Sync** |
|
|
133
|
+
| `av_drift_warning_ms` | `MODALTRACE_AV_DRIFT_WARNING_MS` | float | `40.0` | Warn if drift exceeds this |
|
|
134
|
+
| `av_chunk_ttl_s` | `MODALTRACE_AV_CHUNK_TTL_S` | float | `5.0` | Chunk retention period |
|
|
135
|
+
| **PII Scrubbing** |
|
|
136
|
+
| `scrubbing_enabled` | `MODALTRACE_SCRUBBING_ENABLED` | bool | `true` | Enable PII removal |
|
|
137
|
+
| `scrubbing_patterns` | `MODALTRACE_SCRUBBING_PATTERNS` | list[str] | `[]` | Regex patterns to scrub |
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## 📁 Architecture
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
modaltrace/
|
|
145
|
+
├── config.py # Pydantic configuration model
|
|
146
|
+
├── _registry.py # Global SDK registry
|
|
147
|
+
├── conventions/
|
|
148
|
+
│ └── attributes.py # Semantic convention constants
|
|
149
|
+
├── tracing/
|
|
150
|
+
│ ├── pipeline.py # Main trace pipeline
|
|
151
|
+
│ ├── sampler.py # Adaptive sampling logic
|
|
152
|
+
│ ├── pending.py # Pending spans management
|
|
153
|
+
│ └── propagation.py # Context propagation
|
|
154
|
+
├── metrics/
|
|
155
|
+
│ ├── instruments.py # Metric instrument definitions
|
|
156
|
+
│ ├── aggregator.py # Ring buffer aggregation
|
|
157
|
+
│ └── av_sync.py # A/V sync metrics
|
|
158
|
+
├── instrumentation/
|
|
159
|
+
│ ├── pytorch.py # PyTorch auto-instrumentation
|
|
160
|
+
│ ├── gpu.py # GPU monitoring
|
|
161
|
+
│ ├── eventloop.py # Event loop tracking
|
|
162
|
+
│ └── transport.py # Network transport metrics
|
|
163
|
+
├── logging/
|
|
164
|
+
│ ├── api.py # Structured logging API
|
|
165
|
+
│ └── scrubber.py # PII scrubbing pipeline
|
|
166
|
+
└── exporters/
|
|
167
|
+
└── setup.py # OTLP exporter initialization
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## 🔧 Development
|
|
173
|
+
|
|
174
|
+
### Setup
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
git clone https://github.com/arnabdeypolimi/video-ai-telemetry.git
|
|
178
|
+
cd video-ai-telemetry
|
|
179
|
+
python -m venv .venv
|
|
180
|
+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
|
181
|
+
pip install -e ".[dev,all]"
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Run Tests
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
pytest tests/ -v
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Lint & Format
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
ruff check src/ tests/
|
|
194
|
+
ruff format src/ tests/
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Type Check
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
mypy src/
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## 🤝 Contributing
|
|
206
|
+
|
|
207
|
+
Contributions are welcome! Please:
|
|
208
|
+
|
|
209
|
+
1. Open an [issue](https://github.com/arnabdeypolimi/video-ai-telemetry/issues) to discuss changes
|
|
210
|
+
2. Fork the repository and create a feature branch
|
|
211
|
+
3. Submit a pull request with tests for new functionality
|
|
212
|
+
4. Ensure all tests pass and code is linted
|
|
213
|
+
|
|
214
|
+
For detailed guidelines, see [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## 📄 License
|
|
219
|
+
|
|
220
|
+
ModalTrace is licensed under the Apache License 2.0. See [LICENSE](./LICENSE) for details.
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
**Questions?** Open an [issue](https://github.com/arnabdeypolimi/video-ai-telemetry/issues) or check the [documentation](https://github.com/arnabdeypolimi/video-ai-telemetry/wiki).
|