This repository was archived by the owner on Jan 2, 2026. It is now read-only.
Commit 1d2e988
feat: Observability instrumentation and distributed tracing (#24)
* feat: initialize observability instrumentation implementation
- Create PROGRESS.md with 29 tasks across 6 phases
- Update README.md with started timestamp
- Spec approved and ready for implementation
Implements: SPEC-2025-12-25-001
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat(observability): implement Phase 1 core infrastructure
Complete observability foundation with:
Core Modules:
- config.py: ObservabilityConfig with env-based configuration
- metrics.py: Thread-safe MetricsCollector (counters, histograms, gauges)
- tracing.py: Span context with contextvars-based propagation
- session.py: SessionIdentifier with privacy-preserving hashes
- decorators.py: measure_duration decorator (sync/async support)
- logging.py: StructuredLogger with JSON/text formatters
Exporters:
- prometheus.py: Prometheus text format (no external deps)
- json_exporter.py: Full JSON export for metrics and traces
Key Features:
- Lazy imports via __getattr__ for hook performance (<5ms import)
- Thread-safe operations with threading.Lock
- Privacy-preserving SHA256 hashes (8 char truncated)
- Histogram buckets aligned with hook timeouts (2s, 5s, 15s, 30s)
- Rolling window for bounded memory in histograms
Tests:
- 115 new tests across 8 test modules
- Coverage: 87.76% (above 80% threshold)
- All quality gates passing
Closes Phase 1 of SPEC-2025-12-25-001 (Observability Instrumentation)
Ref: #10
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat: Complete observability instrumentation (Phases 1-4)
Implement comprehensive observability for git-notes-memory plugin:
Phase 1 - Core Infrastructure:
- MetricsCollector with counters, histograms, gauges (thread-safe)
- SpanContext and trace_operation for distributed tracing
- StructuredLogger with JSON/text formatters
- SessionIdentifier for multi-tenant distinguishability
- measure_duration decorator and timed_context
Phase 2 - Service Instrumentation:
- Instrument CaptureService, RecallService, EmbeddingService
- Instrument IndexService, GitOps, Hook Handlers
- Fix silent failure points with explicit logging and metrics
- Add timed_hook_execution context manager
Phase 3 - Structured Logging:
- Add *args support to StructuredLogger for backwards compatibility
- Migrate all 5 hook handlers to get_logger()
- Migrate 7 hook support modules to structured logging
Phase 4 - CLI & Export:
- /memory:metrics command with text/json/prometheus formats
- /memory:traces command with filtering options
- /memory:health command with --timing for latency percentiles
- PrometheusExporter class for Prometheus text format
Phases 5-6 (OpenTelemetry, Docker stack) skipped as optional Tier 3.
Closes #10
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: add exponential backoff and observability documentation
MAXALL deep-clean remediation:
- CRIT-001: Add exponential backoff with jitter to lock acquisition
- Replaces fixed 100ms retry with 50ms→2s exponential backoff
- Adds 0-10% jitter to prevent thundering herd
- Reduces resource exhaustion risk under high concurrency
- HIGH-004: Add composite index on (namespace, timestamp DESC)
- Improves range query performance for get_by_namespace()
- HIGH-014: Create docs/observability.md documentation
- Metrics collection and Prometheus export
- Tracing with span hierarchies
- Structured logging configuration
- Health checks and performance characteristics
Code review artifacts in docs/code-review/2025/12/25/:
- CODE_REVIEW.md: 90 findings from 9 specialist agents
- REVIEW_SUMMARY.md: Executive summary
- REMEDIATION_TASKS.md: Actionable checklist
- REMEDIATION_REPORT.md: Final status with false positives
All 1949 tests passing, 87.70% coverage.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat(observability): add Docker Compose local observability stack
Phase 6 implementation (tasks 6.1-6.2):
- docker-compose.yml with OTEL Collector, Prometheus, Tempo, Loki, Grafana
- OpenTelemetry Collector config with OTLP receivers and exporters
- Prometheus scrape configuration for OTEL metrics
- Tempo distributed tracing backend configuration
- Loki log aggregation configuration
- Grafana datasource provisioning (Prometheus, Tempo, Loki)
- Grafana dashboard provisioning with auto-discovery
- memory-operations.json dashboard (captures, searches, latency)
- hook-performance.json dashboard (executions, timeouts, p95 latency)
Exposed ports:
- 3000: Grafana UI
- 9090: Prometheus UI
- 4317/4318: OTEL gRPC/HTTP
- 3100: Loki
- 3200: Tempo
Usage: cd docker && docker-compose up -d
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix(security): divest inline Python from command files into scripts
Addresses PR #24 review comments:
- SECURITY: Moved inline Python code from commands/*.md to scripts/*.py
to prevent command injection via $ARGUMENTS string interpolation
- scripts/metrics.py: Safe argument parsing via argparse/sys.argv
- scripts/traces.py: Safe argument parsing via argparse/sys.argv
- scripts/health.py: Safe argument parsing via argparse/sys.argv
- Updated commands/metrics.md, traces.md, health.md to call scripts
- Fixed exporters/__init__.py: explicit imports instead of lazy loading
to resolve Copilot undefined export warnings
The previous implementation embedded $ARGUMENTS directly into Python
string literals, allowing code injection via crafted arguments.
The new scripts pass arguments safely via command line.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat(observability): implement OTLP HTTP exporter for telemetry push
Completes Phase 5 of the observability spec by adding OTLP HTTP export
capability so telemetry can be pushed to OpenTelemetry Collector and the
Docker Compose observability stack.
Changes:
- New `exporters/otlp.py` with OTLPExporter class using stdlib only
- Converts internal Span/metrics to OTLP JSON format
- Pushes to {endpoint}/v1/traces and {endpoint}/v1/metrics
- Configurable via MEMORY_PLUGIN_OTLP_ENDPOINT env var
- Updated Stop handler to flush telemetry at session end
- Updated observability.md with OTLP configuration section
- Added comprehensive tests for OTLP exporter
- pyproject.toml: added S310 per-file-ignore for OTLP file
The exporter uses urllib.request (stdlib) to avoid adding dependencies.
When MEMORY_PLUGIN_OTLP_ENDPOINT is set, traces and metrics are
automatically exported when the Claude Code session ends.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>1 parent c9f358e commit 1d2e988
69 files changed
Lines changed: 11147 additions & 1986 deletions
File tree
- commands
- docker
- grafana
- dashboards
- provisioning
- dashboards
- datasources
- docs
- code-review/2025/12/25
- spec/active/2025-12-25-observability-instrumentation
- scripts
- src/git_notes_memory
- hooks
- observability
- exporters
- tests/test_observability
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
289 | 298 | | |
290 | 299 | | |
291 | 300 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
0 commit comments