Observability is crucial when operating a SaaS system because it’s not possible to debug it live. Alongside structured logging and distributed tracing, metrics are one of the pillars of observability.
Microbus supports both push and pull models:
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT or OTEL_EXPORTER_OTLP_ENDPOINT environment variable appropriatelyMICROBUS_PROMETHEUS_EXPORTER environment variable and configure Prometheus to scrape metrics from the metrics core microservice
By default, all microservices produce a standard set of metrics:
OnStartup, OnShutdown, tickers, etc.Custom metrics are defined using the Connector’s DescribeCounter, DescribeGauge or DescribeHistogram. Metrics are incremented or observed using IncrementCounter, RecordGauge or RecordHistogram, depending on their type.
The coding agent can assist in the definition of metrics.
Hey Claude, create a metric that counts the number of likes per post ID.
IncrementCounterLikes (or something similar) will be created by the coding agent in intermediate.go.
func (svc *Intermediate) IncrementCounterLikes(ctx context.Context, num int, postId string) error {
// ...
}
It can then be used to count the number of likes from anywhere in the microservice’s code.
func (svc *Service) Like(ctx context.Context, postId string) error {
// ...
err := svc.IncrementCounterLikes(ctx, 1, postId)
if err != nil {
return errors.Trace(err)
}
return nil
}