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
- Error type, message, and stack, with lines around the crashing frame when the file can be read.
- The cause chain, up to five deep, through Unwrap.
- Release, environment, user id, and breadcrumbs.
- A trace id on the event, and the HTTP request when Handler or TrackRequest runs.
- The same issue grouping as PHP, Python, and the browser snippet.
The Go client does not collect SQL or cache spans on its own. A Go stack does not include argument values.
Troubleshooting
- An empty DSN disables the client. Init returns without an endpoint, and later calls do nothing.
- The documented DSN is https://tracehawk.net/api/<key>. A value that already ends in /store is also accepted.
- Calling Capture twice for the same error only sends the first.
- Allowed origins are a browser control. Go is not filtered by that list.
- If the host is down, the HTTP call stops in under half a second. Your process keeps going.
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.