Skip to content

Instantly share code, notes, and snippets.

@packrat386
Created January 11, 2020 07:00
Show Gist options
  • Save packrat386/d9bf90f3732e3830354eed6d5e1eb338 to your computer and use it in GitHub Desktop.
Save packrat386/d9bf90f3732e3830354eed6d5e1eb338 to your computer and use it in GitHub Desktop.
melian example
package main
import (
"crypto/tls"
"fmt"
"net/http"
"os"
"github.com/packrat386/melian"
)
var mc *melian.Client
func main() {
mc = &melian.Client{
DSN: os.Getenv("SENTRY_DSN"),
HTTPClient: &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{},
},
},
}
http.HandleFunc("/error", handler)
http.ListenAndServe(os.Getenv("ADDR"), nil)
}
func handler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = melian.AddRequest(ctx, r)
ctx = melian.AddTransaction(ctx, "error_handler")
err := thingThatErrors()
if err != nil {
ctx = melian.AddTag(ctx, "thing", "errored again")
mc.Capture(ctx, err)
}
w.WriteHeader(200)
}
func thingThatErrors() error {
return fmt.Errorf("oh no!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment