Skip to content

feat: add structured wide event logging#5

Merged
jordangarrison merged 13 commits intomainfrom
logging
Feb 20, 2026
Merged

feat: add structured wide event logging#5
jordangarrison merged 13 commits intomainfrom
logging

Conversation

@jordangarrison
Copy link
Copy Markdown
Owner

Summary

  • Add structured wide event logging (canonical log lines pattern) across the entire application using LoggerJSON for JSON-formatted output
  • Create Greenlight.WideEvent core module for accumulating context and emitting single context-rich events per logical operation
  • Add Greenlight.GitHub.ReqLogger Req plugin that automatically logs every GitHub API call with endpoint, status, duration, response size, and rate limit info
  • Add Greenlight.RequestLogger telemetry handler for HTTP request logging via [:phoenix, :endpoint, :stop]
  • Instrument Poller GenServer poll cycles with business context (subscriber count, workflow runs, state changes)
  • Instrument LiveView mounts (DashboardLive, RepoLive, PipelineLive) and pipeline updates with relevant context
  • Set global logger metadata (app_version, node, env, git_sha) via :logger.update_primary_config/1 so environment context appears in all process logs

Test Plan

  • All 45 tests pass (0 failures)
  • mix format --check-formatted passes
  • mix compile --warnings-as-errors passes
  • Verify JSON log output in dev with LOG_LEVEL=debug mix phx.server
  • Confirm GitHub API call events include rate limit headers
  • Confirm poller poll cycle events include business context fields

Canonical log line / wide event pattern for structured JSON logging
across GitHub API calls, Poller GenServer, LiveView sessions, and
HTTP requests using LoggerJSON + custom WideEvent module.
8-task TDD implementation plan covering LoggerJSON setup, WideEvent
core module, Req logger plugin, HTTP telemetry handler, Poller
integration, and LiveView logging.
- Add logger_json ~> 7.0 dependency
- Replace default formatter with LoggerJSON.Formatters.Basic
- Suppress default Phoenix request logging (handled via telemetry)
- Set dev log level to :debug for wide event visibility
- Add LOG_LEVEL runtime env var override
Add Greenlight.WideEvent module that wraps Logger.metadata/1 for
accumulating context and provides emit/3 for structured event emission
with automatic timing and error capture via with_context/3.
Req plugin that emits wide events for every GitHub API call with
request/response metadata including endpoint, status, duration,
response size, and rate limit headers. Logs at debug for 2xx,
info for rate limit warnings (<100 remaining), error for 4xx/5xx.
Logger.metadata/1 only sets metadata on the calling process. The
environment context (app_version, node, env, git_sha) was not appearing
in log events from Poller, LiveView, or HTTP request handler processes.

Switch to :logger.update_primary_config/1 which sets metadata globally
for all processes, ensuring environment context appears in every event.
@jordangarrison jordangarrison merged commit 01c3205 into main Feb 20, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant