Created
January 11, 2020 07:00
-
-
Save packrat386/d9bf90f3732e3830354eed6d5e1eb338 to your computer and use it in GitHub Desktop.
melian example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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