Go Metrics

Learn how to setup metrics in your Go application.

Setup

Open the Vigilant dashboard and generate an API key.

Install

Install the Vigilant SDK in your Go application.

go get github.com/vigilant-run/vigilant-golang/v2

Initialize

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()
}

Metrics Functions

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"))
}

Optional Setup

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()
}