Learn how to setup metrics in your Go application.
Open the Vigilant dashboard and generate an API key.
Install the Vigilant SDK in your Go application.
go get github.com/vigilant-run/vigilant-golang/v2
Initialize the Vigilant SDK in your Go application. Make sure to shutdown the SDK before your application exits.
package main
import (
"github.com/vigilant-run/vigilant-golang/v2"
)
func main() {
config := vigilant.NewConfigBuilder().
WithName("backend").
WithToken("tk_1234567890"). // Use your API key from the dashboard
Build()
vigilant.Init(config)
defer vigilant.Shutdown()
}
The Vigilant SDK provides a function to emit metrics.
import (
"github.com/vigilant-run/vigilant-golang/v2"
)
func function() {
// Create a metric event
vigilant.MetricEvent("http_request_time", 20.0)
// Create a metric event with a tag
vigilant.MetricEvent("http_request_time", 20.0, vigilant.Tag("env", "production"))
}
The Vigilant SDK exposes a few setup options when you initialize it.
package main
import (
"github.com/vigilant-run/vigilant-golang/v2"
)
func main() {
config := vigilant.NewConfigBuilder().
// Disable all functionality
WithNoop(true).
vigilant.Init(config.Build())
defer vigilant.Shutdown()
}