add observability: LiveDashboard in prod, error tracking, JSON logging
- Move LiveDashboard to /admin/dashboard behind session auth (all envs) - Add ErrorTracker at /admin/errors for auto-captured exceptions - Add Oban job and LiveView metrics to telemetry module - Add logger_json for structured JSON logs in production - Enable os_mon for CPU/disk/memory in LiveDashboard OS Data tab - Extend logger metadata with oban_worker and oban_queue fields Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,8 @@ defmodule SimpleshopThemeWeb.Router do
|
||||
use SimpleshopThemeWeb, :router
|
||||
|
||||
import SimpleshopThemeWeb.UserAuth
|
||||
import Phoenix.LiveDashboard.Router
|
||||
import ErrorTracker.Web.Router
|
||||
|
||||
pipeline :browser do
|
||||
plug :accepts, ["html"]
|
||||
@@ -89,19 +91,19 @@ defmodule SimpleshopThemeWeb.Router do
|
||||
post "/stripe", StripeWebhookController, :handle
|
||||
end
|
||||
|
||||
# Enable LiveDashboard and Swoosh mailbox preview in development
|
||||
if Application.compile_env(:simpleshop_theme, :dev_routes) do
|
||||
# If you want to use the LiveDashboard in production, you should put
|
||||
# it behind authentication and allow only admins to access it.
|
||||
# If your application does not have an admins-only section yet,
|
||||
# you can use Plug.BasicAuth to set up some basic authentication
|
||||
# as long as you are also using SSL (which you should anyway).
|
||||
import Phoenix.LiveDashboard.Router
|
||||
# LiveDashboard and ErrorTracker behind admin auth (available in all environments)
|
||||
scope "/admin" do
|
||||
pipe_through [:browser, :require_authenticated_user]
|
||||
|
||||
live_dashboard "/dashboard", metrics: SimpleshopThemeWeb.Telemetry
|
||||
error_tracker_dashboard("/errors")
|
||||
end
|
||||
|
||||
# Dev-only routes (mailbox preview, error previews)
|
||||
if Application.compile_env(:simpleshop_theme, :dev_routes) do
|
||||
scope "/dev" do
|
||||
pipe_through :browser
|
||||
|
||||
live_dashboard "/dashboard", metrics: SimpleshopThemeWeb.Telemetry
|
||||
forward "/mailbox", Plug.Swoosh.MailboxPreview
|
||||
|
||||
# Preview error pages
|
||||
|
||||
@@ -75,6 +75,24 @@ defmodule SimpleshopThemeWeb.Telemetry do
|
||||
"The time the connection spent waiting before being checked out for the query"
|
||||
),
|
||||
|
||||
# Oban job metrics
|
||||
summary("oban.job.stop.duration",
|
||||
tags: [:worker],
|
||||
unit: {:native, :millisecond}
|
||||
),
|
||||
counter("oban.job.stop.duration", tags: [:worker]),
|
||||
counter("oban.job.exception.duration", tags: [:worker]),
|
||||
|
||||
# LiveView metrics
|
||||
summary("phoenix.live_view.mount.stop.duration",
|
||||
tags: [:view],
|
||||
unit: {:native, :millisecond}
|
||||
),
|
||||
summary("phoenix.live_view.handle_event.stop.duration",
|
||||
tags: [:event],
|
||||
unit: {:native, :millisecond}
|
||||
),
|
||||
|
||||
# VM Metrics
|
||||
summary("vm.memory.total", unit: {:byte, :kilobyte}),
|
||||
summary("vm.total_run_queue_lengths.total"),
|
||||
|
||||
Reference in New Issue
Block a user