Files
tasks/common/metrics/metrics_test.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
Full module path rebrand from Temporal to Hanzo Tasks:
- go.mod module: github.com/hanzoai/tasks
- All internal Go imports updated (1906 files)
- cmd/server renamed to cmd/tasksd
- Binary name: tasksd (was temporal-server)
- Docker images: hanzoai/tasks (was temporalio/server)
- README rewritten with Hanzo Tasks branding
- LLM.md created with integration notes
- Makefile, goreleaser, CI workflows updated
- go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos)

Fork of Temporal.io (MIT license).
2026-03-19 10:36:40 -07:00

54 lines
1.4 KiB
Go

package metrics_test
import (
"fmt"
"slices"
"time"
"github.com/hanzoai/tasks/common/metrics"
"github.com/hanzoai/tasks/common/metrics/metricstest"
expmaps "golang.org/x/exp/maps"
)
var (
bytesHist = metrics.NewBytesHistogramDef("test-bytes-histogram")
counter = metrics.NewCounterDef("test-counter")
gauge = metrics.NewGaugeDef("test-gauge")
hist = metrics.NewDimensionlessHistogramDef("test-histogram")
timer = metrics.NewTimerDef("test-timer")
)
func ExampleHandler() {
handler := metricstest.NewCaptureHandler()
capture := handler.StartCapture()
// Instead of calling handler.Histogram(bytesHist.Name(), bytesHist.Unit()).Record(1), you should use the With
// method of the metric definition instead.
bytesHist.With(handler).Record(1)
counter.With(handler).Record(2)
gauge.With(handler).Record(3)
hist.With(handler).Record(4)
timer.With(handler).Record(5 * time.Second)
snapshot := capture.Snapshot()
keys := expmaps.Keys(snapshot)
slices.Sort(keys)
for _, key := range keys {
fmt.Printf("%s:", key)
for _, rec := range snapshot[key] {
fmt.Printf(" %v (%v)", rec.Value, rec.Unit)
}
fmt.Println()
}
// Notice that the output includes the proper units without having to specify them in the call to Record.
// Output:
// test-bytes-histogram: 1 (By)
// test-counter: 2 ()
// test-gauge: 3 ()
// test-histogram: 4 (1)
// test-timer: 5s ()
}