Go Integration
The Atatus Go Agent helps you monitor Go applications in production to determine which applications are slower than normal or producing a lot of errors. It also provides tools for troubleshooting application problems so that you can take action before poor performance becomes apparent to your users.
Create a free account to start monitoring your Go apps.
Installation & Setup
1. Install the Atatus Go agent
go get github.com/atatus/atatus-go-agent
2. Import the github.com/atatus/atatus-go-agent package in your application. Create a config and application in your main function or in an init block.
app, _ = atatus.NewApp(atatus.NewConfiguration("{{ project.apikey }}"))
3. Instrument your transactions using app.HandleFunc for requests handled by the http standard library package. Lets say, change the following transactions to
app, _ = http.HandleFunc("/version", VersionHandler)
To
app, _ = http.HandleFunc(app.HandleFunc("/version", VersionHandler))
// VersionHandler implementation
func VersionHandler(w http.ResponseWriter, r *http.Request) {
txn, ok := resp.(*atatus.Transaction)
if !ok {
app.NotifyError(errors.New("VersionHandler: Transaction not found"), atatus.CustomData{"plan": "monthly"}, atatus.Tags{"prod-server"}, atatus.User{ID: "matt@example.com"})
} else {
txn.NotifyError(errors.New("VersionHandler: Found an error"))
}
}
Alternatively, you can use BeginTransaction method to monitor transactions.
func ReadHandler(w http.ResponseWriter, r *http.Request) {
txn := app.BeginTransaction(":kill", w, r)
defer txn.End()
...code...
}
// You can measure database, external HTTP layers as follows
// Measure Database
layer := atatus.BeginDatabaseLayer(txn, atatus.MySQL, "select *")
...code...
layer.End()
// Measure external HTTP calls
layer := atatus.BeginRemoteHTTPLayer(txn, request.URL.Path)
...code...
layer.End()
// Other components
layer := atatus.BeginLayer(txn, "first layer")
...code...
layer.End()
4. Compile and deploy your application
In a few minutes, you'll see the metrics in Atatus dashboard and can start monitoring your application's performance.
Send custom exceptions
Atatus automatically captures all unhandled exceptions and HTTP errors from your Go app. If you want to send error manually, you can do it by atatus.NotifyError
function. The accepts an error as either a string or an Error object as the first argument,. The second parameter and third parameter are tags,and user id respectively.
app.NotifyError(errors.New("VersionHandler: Transaction not found"), atatus.CustomData{"plan": "monthly"}, atatus.Tags{"prod-server"}, atatus.User{ID: "matt@example.com"})