Usage statistics & metrics
The Go SDK can optionally batch and send:
- usage statistics (feature checks + usage)
- metrics (measurements / counters / observations)
This is done via gRPC.
Enable usage statistics
client, err := toggly.NewClient(toggly.Config{
AppKey: "YOUR_APP_KEY",
Environment: "Production",
EnableUsage: true,
})
Record usage
Checks are automatically recorded when EnableUsage=true.
If you want to separately record “used” events (e.g. a button click), call:
client.RecordUsage("MyFeature", true, toggly.Context{Identity: "user-123"})
Enable metrics
client, err := toggly.NewClient(toggly.Config{
AppKey: "YOUR_APP_KEY",
Environment: "Production",
EnableMetrics: true,
})
Emit metrics
The final argument is the variant name; use an empty string for a boolean feature.
m := client.MetricsClient()
if m != nil {
featureKey := "MyFeature"
m.Increment("MyFeature.Counter", 1, &featureKey, "")
m.Measure("MyFeature.LatencyMs", 12.3, &featureKey, "")
m.Observe("MyFeature.PayloadSize", 2048, &featureKey, "")
}
Flushing
Both usage and metrics are flushed periodically (defaults to 1 minute). You can set:
UsageFlushIntervalMetricsFlushInterval
The underlying clients also expose a Flush(ctx) method if you need a manual flush.