# Observability

## Logging

Structured JSON logs via `slog`.

### Startup and health

| Field | When |
| --- | --- |
| `service` | All log lines |
| `address`, `environment` | Startup |

### Sync lifecycle (`internal/service/sync.go`)

| Field | When |
| --- | --- |
| `job_id` | Sync start, completion, failure |
| `repo_id` | Sync completion, failure, publish errors |
| `ref` | Sync completion, failure |
| `snapshot_id` | Sync completion, publish errors |
| `commit_sha` | Sync completion |
| `file_changes` | Sync completion |
| `is_first_sync` | Sync completion |
| `duration_ms` | Sync completion and failure |
| `error` | Sync failure |

### Event publishing

| Field | When |
| --- | --- |
| `event_id` | Snapshot-ready summary (`publish.go`), Redis publish (`publisher.go`) |
| `stream` | Redis publish success/failure |
| `entry_id` | Redis publish success |
| `publish_duration_ms` | Redis publish success |

Partial file publish failures also log `published_files` and `total_files`.

### Git commands (`internal/git/runner.go`)

| Field | When |
| --- | --- |
| `dir` | Git command success/failure |
| `args` | Git command success/failure (secrets redacted) |
| `duration_ms` | Successful git commands |
| `stderr` | Failed git commands (redacted) |

## Health endpoints

- `/healthz` — process liveness
- `/readyz` — Redis + Mongo connectivity
- `/version` — build metadata

## Future work

- OpenTelemetry traces and metrics
- Prometheus counters for sync duration, publish latency, and git failures
