Purpose
Implement metrics collection, logging, error tracking, health checks, and profiling for pipeline observability.
When To Use
- Adding monitoring/observability to a data pipeline framework
- Tracking pipeline execution metrics
- Implementing structured logging
- Setting up health checks
- Adding performance profiling
Preconditions
- Existing
src/vibe_piper/ package structure
- Python 3.12+ environment
- UV package manager
Steps
1. Create monitoring module structure
mkdir -p src/vibe_piper/monitoring
2. Implement metrics collection (metrics.py)
- Create
MetricType enum (COUNTER, GAUGE, HISTOGRAM, TIMER, SUMMARY)
- Create
Metric dataclass (name, value, type, timestamp, labels, unit)
- Create
MetricsSnapshot dataclass with filtering methods
- Create
MetricsCollector class with:
start_execution() / end_execution() for pipeline-level metrics
record_metric() for custom metrics
record_asset_execution() for AssetResult integration
record_execution_result() for ExecutionResult integration
get_snapshot() / to_dict() for export
- Thread-safe implementation with
_lock
3. Implement structured logging (logging.py)
- Create
LogLevel enum (TRACE, DEBUG, INFO, WARNING, ERROR, CRITICAL)
- Create
JSONFormatter for machine-parsable logs
- Create
ColoredFormatter for console output
- Create
StructuredLogger wrapper with context support
- Create
log_execution() context manager for pipeline tracing
- Create
configure_logging() for setup
4. Implement health checks (health.py)
- Create
HealthStatus enum (HEALTHY, DEGRADED, UNHEALTHY, UNKNOWN)
- Create
HealthCheckResult dataclass
- Create
HealthChecker class with:
register_check() / unregister_check() for dynamic checks
run_check() / run_all_checks() for execution
get_overall_health() for aggregate status
- Create factory functions:
create_disk_space_check(), create_memory_check()
5. Implement error aggregation (errors.py)
- Create
ErrorSeverity enum (LOW, MEDIUM, HIGH, CRITICAL)
- Create
ErrorCategory enum (VALIDATION, CONNECTION, TRANSFORMATION, IO, TIMEOUT, SYSTEM, UNKNOWN)
- Create
ErrorRecord dataclass with aggregation support
- Create
ErrorAggregator class with:
add_error() for recording errors
- Aggregation window for similar errors
- Filtering methods (by severity, category, asset)
get_summary() for analytics
6. Implement profiling (profiling.py)
- Create
ProfileData dataclass
- Create
Profiler class with:
@profile decorator
get_stats() / get_history() for analysis
- Optional psutil integration for memory tracking
- Create
profile_execution() context manager
7. Update package exports
# Edit src/vibe_piper/__init__.py
# Add monitoring imports to __all__
8. Type checking and linting
uv run mypy src/vibe_piper/monitoring/
uv run ruff check src/vibe_piper/monitoring/ --fix
uv run ruff format src/vibe_piper/monitoring/
9. Create test suite
mkdir -p tests/monitoring
Create tests for:
test_metrics.py: MetricsCollector, MetricsSnapshot, Metric
test_logging.py: LogLevel, formatters, StructuredLogger, log_execution
test_health.py: HealthChecker, health check functions
test_errors.py: ErrorAggregator, ErrorRecord
test_profiling.py: Profiler, ProfileData
10. Integration points
- MetricsCollector integrates with ExecutionEngine via
record_execution_result()
- StructuredLogger can be used throughout codebase via
get_logger()
- HealthChecker for system/resource health monitoring
- ErrorAggregator for tracking and alerting on errors
Examples
from vibe_piper.monitoring import (
MetricsCollector,
StructuredLogger,
HealthChecker,
ErrorAggregator,
configure_logging,
)
# Configure logging
configure_logging(level=LogLevel.INFO, format_type="json")
# Collect metrics
metrics = MetricsCollector()
metrics.start_execution("my_pipeline", "run_123")
metrics.record_metric("custom_metric", 42)
metrics.end_execution()
# Health checks
health_checker = HealthChecker()
health_checker.register_check("disk", create_disk_space_check("/tmp"))
results = health_checker.run_all_checks()
Gotchas
- Optional psutil dependency: handle ImportError gracefully
- Thread-safety: use threading.Lock for shared state
- Type safety: use Optional[T] with proper None handling
- MyPy errors: use
type: ignore[import-untyped] for untyped deps
- Formatter type mismatch: use separate variables for each formatter type
- Datetime arithmetic: coalesce None with
datetime.utcnow()
Verification
uv run pytest tests/monitoring/ -v
uv run mypy src/vibe_piper/monitoring/ strict
Manual notes
This section is preserved when the skill is updated. Put human notes, caveats, and exceptions here.
1---2name: monitoring-implementation3description: Implement comprehensive monitoring and observability features for Vibe Piper pipelines4license: MIT5---6<!-- BEGIN:compound:skill-managed -->
7# Purpose
8Implement metrics collection, logging, error tracking, health checks, and profiling for pipeline observability.
9
10# When To Use
11- Adding monitoring/observability to a data pipeline framework
12- Tracking pipeline execution metrics
13- Implementing structured logging
14- Setting up health checks
15- Adding performance profiling
16
17# Preconditions
18- Existing `src/vibe_piper/` package structure
19- Python 3.12+ environment
20- UV package manager
21
22# Steps
23
24## 1. Create monitoring module structure
25```bash
26mkdir -p src/vibe_piper/monitoring
27```
28
29## 2. Implement metrics collection (metrics.py)
30- Create `MetricType` enum (COUNTER, GAUGE, HISTOGRAM, TIMER, SUMMARY)
31- Create `Metric` dataclass (name, value, type, timestamp, labels, unit)
32- Create `MetricsSnapshot` dataclass with filtering methods
33- Create `MetricsCollector` class with:
34 - `start_execution()` / `end_execution()` for pipeline-level metrics
35 - `record_metric()` for custom metrics
36 - `record_asset_execution()` for AssetResult integration
37 - `record_execution_result()` for ExecutionResult integration
38 - `get_snapshot()` / `to_dict()` for export
39 - Thread-safe implementation with `_lock`
40
41## 3. Implement structured logging (logging.py)
42- Create `LogLevel` enum (TRACE, DEBUG, INFO, WARNING, ERROR, CRITICAL)
43- Create `JSONFormatter` for machine-parsable logs
44- Create `ColoredFormatter` for console output
45- Create `StructuredLogger` wrapper with context support
46- Create `log_execution()` context manager for pipeline tracing
47- Create `configure_logging()` for setup
48
49## 4. Implement health checks (health.py)
50- Create `HealthStatus` enum (HEALTHY, DEGRADED, UNHEALTHY, UNKNOWN)
51- Create `HealthCheckResult` dataclass
52- Create `HealthChecker` class with:
53 - `register_check()` / `unregister_check()` for dynamic checks
54 - `run_check()` / `run_all_checks()` for execution
55 - `get_overall_health()` for aggregate status
56- Create factory functions: `create_disk_space_check()`, `create_memory_check()`
57
58## 5. Implement error aggregation (errors.py)
59- Create `ErrorSeverity` enum (LOW, MEDIUM, HIGH, CRITICAL)
60- Create `ErrorCategory` enum (VALIDATION, CONNECTION, TRANSFORMATION, IO, TIMEOUT, SYSTEM, UNKNOWN)
61- Create `ErrorRecord` dataclass with aggregation support
62- Create `ErrorAggregator` class with:
63 - `add_error()` for recording errors
64 - Aggregation window for similar errors
65 - Filtering methods (by severity, category, asset)
66 - `get_summary()` for analytics
67
68## 6. Implement profiling (profiling.py)
69- Create `ProfileData` dataclass
70- Create `Profiler` class with:
71 - `@profile` decorator
72 - `get_stats()` / `get_history()` for analysis
73 - Optional psutil integration for memory tracking
74- Create `profile_execution()` context manager
75
76## 7. Update package exports
77```bash
78# Edit src/vibe_piper/__init__.py
79# Add monitoring imports to __all__
80```
81
82## 8. Type checking and linting
83```bash
84uv run mypy src/vibe_piper/monitoring/
85uv run ruff check src/vibe_piper/monitoring/ --fix
86uv run ruff format src/vibe_piper/monitoring/
87```
88
89## 9. Create test suite
90```bash
91mkdir -p tests/monitoring
92```
93
94Create tests for:
95- `test_metrics.py`: MetricsCollector, MetricsSnapshot, Metric
96- `test_logging.py`: LogLevel, formatters, StructuredLogger, log_execution
97- `test_health.py`: HealthChecker, health check functions
98- `test_errors.py`: ErrorAggregator, ErrorRecord
99- `test_profiling.py`: Profiler, ProfileData
100
101## 10. Integration points
102- MetricsCollector integrates with ExecutionEngine via `record_execution_result()`
103- StructuredLogger can be used throughout codebase via `get_logger()`
104- HealthChecker for system/resource health monitoring
105- ErrorAggregator for tracking and alerting on errors
106
107# Examples
108```python
109from vibe_piper.monitoring import (
110 MetricsCollector,
111 StructuredLogger,
112 HealthChecker,
113 ErrorAggregator,
114 configure_logging,
115)
116
117# Configure logging
118configure_logging(level=LogLevel.INFO, format_type="json")
119
120# Collect metrics
121metrics = MetricsCollector()
122metrics.start_execution("my_pipeline", "run_123")
123metrics.record_metric("custom_metric", 42)
124metrics.end_execution()
125
126# Health checks
127health_checker = HealthChecker()
128health_checker.register_check("disk", create_disk_space_check("/tmp"))
129results = health_checker.run_all_checks()
130```
131
132# Gotchas
133- Optional psutil dependency: handle ImportError gracefully
134- Thread-safety: use threading.Lock for shared state
135- Type safety: use Optional[T] with proper None handling
136- MyPy errors: use `type: ignore[import-untyped]` for untyped deps
137- Formatter type mismatch: use separate variables for each formatter type
138- Datetime arithmetic: coalesce None with `datetime.utcnow()`
139
140# Verification
141```bash
142uv run pytest tests/monitoring/ -v
143uv run mypy src/vibe_piper/monitoring/ strict
144```
145<!-- END:compound:skill-managed -->
146
147## Manual notes
148
149_This section is preserved when the skill is updated. Put human notes, caveats, and exceptions here._