-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: Revamp sentryhttp documentation
The major point is to promote instrumenting higher up in the HTTP handler hierarchy, such that Sentry instrumentation takes only one line, instead of wrapping many individual handlers. - Add go doc example with minimal steps for instrumenting web servers. - Overhaul doc comments. - Replace executable example with something a little bit more realistic, which we can build upon to show tracing instrumentation later.
- Loading branch information
1 parent
a7135ee
commit 3de525b
Showing
3 changed files
with
202 additions
and
48 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package sentryhttp_test | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/getsentry/sentry-go" | ||
sentryhttp "github.com/getsentry/sentry-go/http" | ||
) | ||
|
||
// For a longer and executable example, see | ||
// https://github.com/getsentry/sentry-go/tree/master/example/http. | ||
func Example() { | ||
// Initialize the Sentry SDK once in the main function. | ||
// sentry.Init(...) | ||
|
||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
// Use GetHubFromContext to get a hub associated with the current | ||
// request. Hubs provide data isolation, such that tags, breadcrumbs | ||
// and other attributes are never mixed up across requests. | ||
hub := sentry.GetHubFromContext(r.Context()) | ||
_, err := http.Get("example.com") | ||
if err != nil { | ||
hub.CaptureException(err) | ||
} | ||
}) | ||
|
||
// Wrap the default mux with Sentry to capture panics and report errors. | ||
// | ||
// Alternatively, you can also wrap individual handlers if you need to use | ||
// different options for different parts of your app. | ||
handler := sentryhttp.New(sentryhttp.Options{}).Handle(http.DefaultServeMux) | ||
http.ListenAndServe(":0", handler) | ||
} |
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