Skip to content

Setup Airbrake for your Go application #2

@pyang55

Description

@pyang55

Installing with the CLI

The Airbrake CLI installs the Airbrake Go notifier automatically in your Go project. To install the notifier directly without using the CLI, please scroll down to the Installing manually section.

Install the CLI via Homebrew

brew install airbrake/airbrake-cli/airbrake

Authenticate via config command

Authenticate by setting your user-key with the config command:

airbrake config set user-key YOUR_USER_KEY_HERE

You can find your user key in your profile settings page.

Install command

Invoke the following to have the Airbrake CLI install the Airbrake notifier for your project:

airbrake install --project-id YOUR_PROJECT_ID_HERE

You can find your project ID in your project's settings.

After this, you are set! Check out the Testing your installation section to send a test error to Airbrake.

Installing manually

Install in existing project

Navigate to your project's main directory and install our Go package, gobrake:

go get github.com/airbrake/gobrake/v5

Install in new app

Create a new directory, initialize a new module and go get the library:

mkdir airbrake_example && cd airbrake_example
go mod init airbrake_example
go get github.com/airbrake/gobrake/v5

Configuration

Import and initialize the gobrake package in your application:

(You can find your project ID and project key in your project's settings)

package main

import "github.com/airbrake/gobrake/v5"

var airbrake = gobrake.NewNotifierWithOptions(&gobrake.NotifierOptions{
	ProjectId: <Your project ID>,
	ProjectKey: "<Your project ID>",
	Environment: "production",
})

func main() {
	defer airbrake.Close()
	defer airbrake.NotifyOnPanic()
}

That's it! The airbrake.NotifyOnPanic() call will handle automatic panic reporting.

Testing your installation

You can use airbrake.Notify() to send handled errors. Let's use it now to check if gobrake is installed correctly:

import "errors"

func testAirbrake() {
	airbrake.Notify(errors.New("Error Test from Airbrake"), nil)
}

You should see this dashboard updating with your test error soon after you run that function.

Full documentation

Check out our official GitHub repo for info on advanced features like ignoring errors, setting error severity and more.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions