Skip to content

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.

EvidenceOwnershipRetention
MetricsEach running process exposes its registry.Your scraper and metrics backend retain history. Process counters reset on restart.
InspectsSource processes capture executions and publish finished records to Lighthouse.Lighthouse keeps a bounded window in memory. Restarting Lighthouse clears it.
Exported spansThe 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.

bash
curl --fail http://127.0.0.1:3000/metrics
# HELP http_requests_total Total HTTP requests served by the application.
# TYPE http_requests_total counter

A 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 layoutDefault app scrape URL
Combined app with HTTPhttp://127.0.0.1:3000/metrics
Combined app without HTTPhttp://127.0.0.1:10000/metrics
Direct HTTP runtimehttp://127.0.0.1:10000/metrics, plus its HTTP /metrics route
Direct schedulerhttp://127.0.0.1:10001/metrics
Direct workershttp://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.

dotenv
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=true

Disabling 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.

LabelMeaningExample
appApp that emits the metricadmin
sourceLogical runtime that performs the workhttp, jobs, scheduler, cli, app
processScrape target's process roleapp for the combined runtime, jobs for separate workers
Resource labelsStable configured or registered namesroute, 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.

dotenv
APP_VERSION=v1.8.0
APP_REVISION=8d5c20f

Build the artifact from the Project root.

bash
forj build

The 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.

text
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 ​

SourceExecution boundaryDetail available when captured
HTTPRequest handlingRegistered route, status, request and response exchange, and contextual logs
JobsJob handler executionJob identity, the job's input payload, queued child work, and contextual logs
SchedulerScheduled task invocationSchedule identity, status, duration, and timeline events
CLIApp command executionCommand 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.

dotenv
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
ControlBound
MAX_INFLIGHTConcurrent source captures
MAX_EVENTSTimeline events retained per record
SAMPLE_RATEProbability of capturing an eligible execution
BUFFER_SIZEFinished records waiting for delivery
FLUSH_INTERVAL, FLUSH_BATCH_SIZEFlush timing and batch size
MAX_TOTALRecent 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.

FieldUse
trace_idUnique inspect lookup ID retained for compatibility
otel_trace_idDistributed trace shared by related execution spans
span_id, parent_span_idExecution 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 ​

SymptomCheckAction
Missing metric seriesComponent, toggle, actual observations, and scraper targetScrape the owning process directly and check its startup logs.
Missing recent inspectCapture enablement, browser console connection, SDK sampling, and capsReproduce a safe request while the console is connected.
Rising publisher depth or flush errorsLighthouse connection and authentication warningsRestore delivery, then watch the buffer recover.
Dropped recordsBuffer pressure and payload volumeReduce capture volume or sampling before increasing memory limits.
History disappearsLighthouse restart or oldest-record evictionUse retained logs and your metrics or tracing backend for older evidence.
Sensitive captureSource capture and redaction policyRestrict 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.

Next Steps ​