TraceHawk // browser, PHP, Python, and Go errors Group · Count · File the ticket Ingest operational

Go

Go exception monitoring.

The TraceHawk module is a small Go 1.21 client. You point it at a project, capture the error, and it keeps the stack, the cause, and a trace id.

What it does

A plain Go service calls the client itself. tracehawk.Init reads the DSN. tracehawk.Capture sends one error. tracehawk.TrackRequest sends the HTTP request that just finished. tracehawk.Handler does both for net/http.

The report includes the error type and message, up to 40 frames, up to five causes from Unwrap, the release, the environment, a user id if you set one, and up to 30 breadcrumbs. Frames in the module cache and the standard library are marked outside the application so grouping can prefer your code.

Install

go get tracehawk.net/sdk/go@v1.0.0
TRACEHAWK_DSN=https://tracehawk.net/api/<key>
import (
    "net/http"
    "os"

    "tracehawk.net/sdk/go"
)

func main() {
    tracehawk.Init(os.Getenv("TRACEHAWK_DSN"))
    tracehawk.Ignore([]string{"/ping", "/health*"})
    tracehawk.SetEnvironment("production")
    tracehawk.SetRelease("app@1.0.0")

    mux := http.NewServeMux()
    mux.HandleFunc("/checkout", checkout)
    http.ListenAndServe(":8080", tracehawk.Handler(mux))
}

Call Init where the process boots, before it serves traffic. Ignore lists paths that are not sent. * is a wildcard. /ping matches that path only. Handler reports a panic and the request, then re-panics. A 404 written by the next handler is not an exception. chi can use the same wrapper.

A handled error

if err := payment.Charge(); err != nil {
    tracehawk.AddBreadcrumb("payment", "Charge failed")
    tracehawk.Capture(err)
    return err
}

Supported features

The Go client does not collect SQL or cache spans on its own. A Go stack does not include argument values.

Troubleshooting

Questions

Do I have to use a web framework?

No. The same module works from plain Go if you call Init, Capture, and TrackRequest yourself. Handler is a shortcut around net/http, and chi can use that same wrapper.

What Go version does the client require?

Go 1.21 or newer, as declared by tracehawk.net/sdk/go v1.0.0.

Will secrets in local variables be stored?

Go stacks do not include argument values, so the client does not store them. Do not put secrets in the error string, tags, or user id.

Related

Ready to turn error noise into actionable issues?