Metrics and Inspects
Use metrics to find a change in request rate, errors, latency, or resource pressure. Use an inspect to examine one request, job, schedule run, or command behind that change.
The metrics component exposes the app's shared github.com/goforj/metrics registry. internal/inspects owns execution capture and the app's OpenTelemetry SDK. Lighthouse presents recent inspects and connected runtime controls.
| Evidence | Ownership | Retention |
|---|---|---|
| Metrics | Each running process exposes its registry. | Your scraper and metrics backend retain history. Process counters reset on restart. |
| Inspects | Source processes capture executions and publish finished records to Lighthouse. | Lighthouse keeps a bounded window in memory. Restarting Lighthouse clears it. |
| Exported spans | The app SDK sends spans to a configured OTLP collector. | Your tracing backend determines retention. |
Endpoints
For a running combined app with HTTP and metrics enabled, scrape its HTTP route in another terminal.
curl --fail http://127.0.0.1:3000/metrics
# HELP http_requests_total Total HTTP requests served by the application.
# TYPE http_requests_total counterA successful response with Prometheus text verifies exposition. The available series depend on enabled components and the work the process has performed.
The combined runtime disables dedicated runtime listeners. Without an HTTP runtime, it starts a shared listener on METRICS_PORT. Direct runtime commands use separate listeners when their instrumentation is enabled.
| Process layout | Default app scrape URL |
|---|---|
| Combined app with HTTP | http://127.0.0.1:3000/metrics |
| Combined app without HTTP | http://127.0.0.1:10000/metrics |
| Direct HTTP runtime | http://127.0.0.1:10000/metrics, plus its HTTP /metrics route |
| Direct scheduler | http://127.0.0.1:10001/metrics |
| Direct workers | http://127.0.0.1:10002/metrics |
Scrape every independently deployed process. Scraping the HTTP process cannot collect counters held by a separate worker process.
Additional apps receive deterministic local ports. The first additional app uses HTTP port 3001 and metrics ports 10010, 10011, and 10012. App-prefixed settings such as ADMIN_API_HTTP_PORT, ADMIN_METRICS_PORT, ADMIN_SCHEDULER_METRICS_PORT, and ADMIN_WORKER_METRICS_PORT override the admin defaults. See port precedence.
Metrics routes have no authentication by default. Dedicated listeners bind on all interfaces. Restrict scrape access with your deployment network or proxy configuration. A dedicated listener shuts down when its runtime context is cancelled.
Toggles
Set instrumentation controls in the app's environment before startup. The controls default to true for included components.
METRICS_HTTP_ENABLED=true
METRICS_CACHE_ENABLED=true
METRICS_STORAGE_ENABLED=true
METRICS_EVENTS_ENABLED=true
METRICS_MAIL_ENABLED=true
METRICS_QUEUE_ENABLED=true
METRICS_DATABASE_ENABLED=true
METRICS_AUTH_ENABLED=true
METRICS_SCHEDULER_ENABLED=trueDisabling an observer-backed integration prevents its metrics observer from attaching. Direct instrumentation checks its toggle before recording. The metrics component must be selected for the app to expose framework metrics. The demo also has METRICS_MONITORING_ENABLED for its monitoring endpoints.
Labels
Filter by app first, then by the logical source when the metric family has that label. The scrape-time process label describes the process layout.
| Label | Meaning | Example |
|---|---|---|
app | App that emits the metric | admin |
source | Logical runtime that performs the work | http, jobs, scheduler, cli, app |
process | Scrape target's process role | app for the combined runtime, jobs for separate workers |
| Resource labels | Stable configured or registered names | route, queue, job_name, cache, disk |
Use registered route patterns and bounded resource names. Keep user IDs, emails, raw URLs, raw SQL, cache keys, filenames, request IDs, and arbitrary error messages out of labels.
Optional Release Labels
Set APP_VERSION and APP_REVISION in the Project's .env before building when you use framework-managed metrics discovery.
APP_VERSION=v1.8.0
APP_REVISION=8d5c20fBuild the artifact from the Project root.
forj buildThe generated target labels include release="v1.8.0" and revision="8d5c20f". Blank values are omitted. GoForj reads these generation settings from .env.example and .env. Shell exports alone do not change the generated labels, and the build does not infer them from Git. An external production scraper can attach them through its own discovery configuration.
Proving Path
Check the exposed series in your Prometheus-compatible backend before relying on a dashboard. For an HTTP app that has served requests, this query shows request rate by registered route over five minutes.
sum by (app, source, method, route) (
rate(http_requests_by_route_total[5m])
)A route with traffic has a series after scraping. An empty result can mean the route has no observations, the scraper cannot reach the process, or HTTP instrumentation is disabled. Check the process endpoint and scraper target status before changing the query.
The metrics library reference covers registry APIs and metric types. The environment reference lists runtime controls.
Inspects
An inspect captures one execution's timeline, status, duration, and source identity. Capture is off until LIGHTHOUSE_INSPECT_ENABLED=true is set. The Lighthouse agent also gates capture on an active browser console connection. Sampling and event limits further bound what Lighthouse retains.
What Inspects Capture
| Source | Execution boundary | Detail available when captured |
|---|---|---|
| HTTP | Request handling | Registered route, status, request and response exchange, and contextual logs |
| Jobs | Job handler execution | Job identity, the job's input payload, queued child work, and contextual logs |
| Scheduler | Scheduled task invocation | Schedule identity, status, duration, and timeline events |
| CLI | App command execution | Command identity and timeline events |
Enabled integrations can add database, cache, storage, mail, queue, and event observations. Available details follow the selected components and capture policy.
Retention Model
A source process holds running captures in memory. When an execution finishes, the source hands its record to a bounded asynchronous publisher. Lighthouse ingests delivered records into its own bounded in-memory store and evicts the oldest records at capacity.
Delivery is best effort. A full outbound buffer drops new finished records without blocking application execution. A failed flush can hold its current batch while later records accumulate in the bounded buffer. Closing the last browser console connection disables capture and publication. Neither the publisher nor Lighthouse provides a durable incident archive.
During shutdown, the publisher attempts to flush its current batch. It does not guarantee delivery of every buffered record. The OpenTelemetry SDK has a separate shutdown flush within the app's shutdown budget.
When metrics are included, watch lighthouse_inspects_buffer_depth, lighthouse_inspects_dropped_total, lighthouse_inspects_flushes_total, and lighthouse_inspects_flush_errors_total. A drop indicates missing visibility. Check application logs and work outcome separately.
Safe Capture and Sampling
Set limits before starting the source processes and Lighthouse. This example samples 10 percent of eligible executions.
LIGHTHOUSE_INSPECT_ENABLED=true
LIGHTHOUSE_INSPECT_MAX_INFLIGHT=250
LIGHTHOUSE_INSPECT_MAX_EVENTS=300
LIGHTHOUSE_INSPECT_SAMPLE_RATE=0.10
LIGHTHOUSE_INSPECT_BUFFER_SIZE=4096
LIGHTHOUSE_INSPECT_FLUSH_INTERVAL=1s
LIGHTHOUSE_INSPECT_FLUSH_BATCH_SIZE=100
LIGHTHOUSE_INSPECT_MAX_TOTAL=5000| Control | Bound |
|---|---|
MAX_INFLIGHT | Concurrent source captures |
MAX_EVENTS | Timeline events retained per record |
SAMPLE_RATE | Probability of capturing an eligible execution |
BUFFER_SIZE | Finished records waiting for delivery |
FLUSH_INTERVAL, FLUSH_BATCH_SIZE | Flush timing and batch size |
MAX_TOTAL | Recent records retained by Lighthouse |
Size these values for payload size, traffic, and available memory. The sample rate also depends on the SDK's sampling decision. OTEL_SDK_DISABLED=true disables span recording for both Lighthouse and OTLP. Lighthouse capture settings do not disable separately configured OTLP export.
Captured HTTP bodies, headers, job payloads, logs, cache keys, object paths, and raw SQL can contain sensitive data. Review capture and redaction before enabling production capture, and restrict operator access. Framework OTLP instrumentation omits this rich Lighthouse data from automatic export. Application and third-party instrumentation follow their own capture policies. A Lighthouse copy action copies the stored value, including any truncation.
Reading an Inspect
Start with app, runtime source, instance, start time, status, and duration. Read the timeline to identify the operation that failed or consumed time. A job's input payload belongs to that job. Child jobs queued during execution have separate payload evidence.
Use the correct ID when following evidence across tools.
| Field | Use |
|---|---|
trace_id | Unique inspect lookup ID retained for compatibility |
otel_trace_id | Distributed trace shared by related execution spans |
span_id, parent_span_id | Execution and parent identity within that trace |
Several inspect records can share one otel_trace_id. Contextual application logs can carry the trace and span IDs when the logger receives the execution context. Metric labels identify the affected app, runtime, and named resource. Keep individual execution IDs out of metric labels.
For propagation boundaries and log correlation, see Tracing. The OpenTelemetry environment reference covers collector settings.
Failure Modes
| Symptom | Check | Action |
|---|---|---|
| Missing metric series | Component, toggle, actual observations, and scraper target | Scrape the owning process directly and check its startup logs. |
| Missing recent inspect | Capture enablement, browser console connection, SDK sampling, and caps | Reproduce a safe request while the console is connected. |
| Rising publisher depth or flush errors | Lighthouse connection and authentication warnings | Restore delivery, then watch the buffer recover. |
| Dropped records | Buffer pressure and payload volume | Reduce capture volume or sampling before increasing memory limits. |
| History disappears | Lighthouse restart or oldest-record eviction | Use retained logs and your metrics or tracing backend for older evidence. |
| Sensitive capture | Source capture and redaction policy | Restrict access, rotate exposed credentials, and correct capture before resuming. |
Common Mistakes
Keep the execution boundary visible when comparing signals. An HTTP scrape excludes a separate worker's registry. An absent inspect can follow sampling or a disconnected console. A Lighthouse restart clears recent history. Confirm these conditions before interpreting missing evidence as an application failure.
Production Checklist
- Every deployed process has a reachable, access-controlled scrape target.
- Labels identify the app and runtime without unbounded or sensitive values.
- Inspect sampling, memory limits, redaction, and operator access have defined owners.
- Publisher drops and flush failures are monitored.
- Incident history is retained in the configured logging, metrics, or tracing backend.