This example demonstrates how to implement Industry Standard Observability in Trellis applications using:
log/slog: Go’s standard library for structured JSON logging.prometheus: Metrics collection for monitoring.SIGINT (Ctrl+C) to ensure cleanup.Run the example:
go run ./examples/structured-logging
The flow will start and log events to stdout in JSON format.
You can cancel the execution at any time by pressing Ctrl+C. The application handles the intersection signal, cancels the context, and shuts down gracefully.
# JSON Output
{"time":"...","level":"INFO","msg":"received interrupt signal, shutting down..."}
The application exposes a Prometheus metrics endpoint on port :2112.
While the application is running (or after it finishes, as the server stays alive until a second Ctrl+C), check the metrics:
curl http://localhost:2112/metrics | grep trellis
Expected Output:
# HELP trellis_node_visits_total Total number of node visits
# TYPE trellis_node_visits_total counter
trellis_node_visits_total{node_id="start"} 1