forked from SierraSoftworks/sentry-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
41 lines (32 loc) · 948 Bytes
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package sentry
import (
"fmt"
"net/http"
"github.com/pkg/errors"
)
func Example() {
cl := NewClient(
// Your DSN is fetched from the $SENTRY_DSN environment
// variable automatically. But you can override it if you
// prefer...
DSN("https://key:[email protected]/sentry/1"),
Release("v1.0.0"),
// Your environment is fetched from $ENV/$ENVIRONMENT automatically,
// but you can override it here if you prefer.
Environment("example"),
Logger("example"),
)
err := errors.New("something went wrong")
// The HTTP request that was being handled when this error occurred
var req *http.Request
e := cl.Capture(
Culprit("GET /api/v1/explode"),
ExceptionForError(err),
HTTPRequest(req).WithHeaders().WithCookies(),
)
if err := e.Error(); err != nil {
fmt.Printf("Failed to send event: %s", err.Error())
} else {
fmt.Printf("Sent event (id: %s)\n", e.EventID())
}
}