Skip to content

Commit 109fca1

Browse files
ribicecleptric
andauthored
Fix typos / add comments for integrations (#939)
* minor improvements for integrations * Update echo/sentryecho.go Co-authored-by: Michi Hoffmann <[email protected]> * Update echo/sentryecho.go Co-authored-by: Michi Hoffmann <[email protected]> * Update gin/sentrygin.go Co-authored-by: Michi Hoffmann <[email protected]> * Update gin/sentrygin.go Co-authored-by: Michi Hoffmann <[email protected]> * Update fiber/sentryfiber.go Co-authored-by: Michi Hoffmann <[email protected]> * Update fiber/sentryfiber.go Co-authored-by: Michi Hoffmann <[email protected]> * Update echo/sentryecho.go Co-authored-by: Michi Hoffmann <[email protected]> * Update fiber/sentryfiber.go Co-authored-by: Michi Hoffmann <[email protected]> * Update fiber/sentryfiber.go Co-authored-by: Michi Hoffmann <[email protected]> * add comment for sentryfiber.New * Update iris/sentryiris.go Co-authored-by: Michi Hoffmann <[email protected]> * Update iris/sentryiris.go Co-authored-by: Michi Hoffmann <[email protected]> * Update logrus/logrusentry.go Co-authored-by: Michi Hoffmann <[email protected]> * Update fasthttp/sentryfasthttp.go Co-authored-by: Michi Hoffmann <[email protected]> * Update fiber/sentryfiber.go Co-authored-by: Michi Hoffmann <[email protected]> * Update fasthttp/sentryfasthttp.go Co-authored-by: Michi Hoffmann <[email protected]> * Update fasthttp/sentryfasthttp.go Co-authored-by: Michi Hoffmann <[email protected]> --------- Co-authored-by: Michi Hoffmann <[email protected]>
1 parent ade504d commit 109fca1

File tree

8 files changed

+94
-61
lines changed

8 files changed

+94
-61
lines changed

echo/sentryecho.go

+20-11
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@ import (
1010
"github.com/labstack/echo/v4"
1111
)
1212

13-
// The identifier of the Echo SDK.
14-
const sdkIdentifier = "sentry.go.echo"
13+
const (
14+
// sdkIdentifier is the identifier of the Echo SDK.
15+
sdkIdentifier = "sentry.go.echo"
1516

16-
const valuesKey = "sentry"
17-
const transactionKey = "sentry_transaction"
17+
// valuesKey is used as a key to store the Sentry Hub instance on the echo.Context.
18+
valuesKey = "sentry"
19+
20+
// transactionKey is used as a key to store the Sentry transaction on the echo.Context.
21+
transactionKey = "sentry_transaction"
22+
23+
// errorKey is used as a key to store the error on the echo.Context.
24+
errorKey = "error"
25+
)
1826

1927
type handler struct {
2028
repanic bool
@@ -24,7 +32,7 @@ type handler struct {
2432

2533
type Options struct {
2634
// Repanic configures whether Sentry should repanic after recovery, in most cases it should be set to true,
27-
// as echo includes its own Recover middleware what handles http responses.
35+
// as Echo includes its own Recover middleware that handles HTTP responses.
2836
Repanic bool
2937
// WaitForDelivery configures whether you want to block the request before moving forward with the response.
3038
// Because Echo's Recover handler doesn't restart the application,
@@ -37,13 +45,13 @@ type Options struct {
3745
// New returns a function that satisfies echo.HandlerFunc interface
3846
// It can be used with Use() methods.
3947
func New(options Options) echo.MiddlewareFunc {
40-
timeout := options.Timeout
41-
if timeout == 0 {
42-
timeout = 2 * time.Second
48+
if options.Timeout == 0 {
49+
options.Timeout = 2 * time.Second
4350
}
51+
4452
return (&handler{
4553
repanic: options.Repanic,
46-
timeout: timeout,
54+
timeout: options.Timeout,
4755
waitForDelivery: options.WaitForDelivery,
4856
}).handle
4957
}
@@ -86,7 +94,7 @@ func (h *handler) handle(next echo.HandlerFunc) echo.HandlerFunc {
8694

8795
defer func() {
8896
status := ctx.Response().Status
89-
if err := ctx.Get("error"); err != nil {
97+
if err := ctx.Get(errorKey); err != nil {
9098
if httpError, ok := err.(*echo.HTTPError); ok {
9199
status = httpError.Code
92100
}
@@ -105,7 +113,7 @@ func (h *handler) handle(next echo.HandlerFunc) echo.HandlerFunc {
105113
err := next(ctx)
106114
if err != nil {
107115
// Store the error so it can be used in the deferred function
108-
ctx.Set("error", err)
116+
ctx.Set(errorKey, err)
109117
}
110118

111119
return err
@@ -135,6 +143,7 @@ func GetHubFromContext(ctx echo.Context) *sentry.Hub {
135143
return nil
136144
}
137145

146+
// SetHubOnContext attaches *sentry.Hub instance to echo.Context.
138147
func SetHubOnContext(ctx echo.Context, hub *sentry.Hub) {
139148
ctx.Set(valuesKey, hub)
140149
}

fasthttp/sentryfasthttp.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ import (
1414
)
1515

1616
const (
17-
sdkIdentifier = "sentry.go.fasthttp"
18-
valuesKey = "sentry"
17+
// sdkIdentifier is the identifier of the FastHTTP SDK.
18+
sdkIdentifier = "sentry.go.fasthttp"
19+
20+
// valuesKey is used as a key to store the Sentry Hub instance on the fasthttp.RequestCtx.
21+
valuesKey = "sentry"
22+
23+
// transactionKey is used as a key to store the Sentry transaction on the fasthttp.RequestCtx.
1924
transactionKey = "sentry_transaction"
2025
)
2126

@@ -40,13 +45,13 @@ type Options struct {
4045
// New returns a struct that provides Handle method
4146
// that satisfy fasthttp.RequestHandler interface.
4247
func New(options Options) *Handler {
43-
timeout := options.Timeout
44-
if timeout == 0 {
45-
timeout = 2 * time.Second
48+
if options.Timeout == 0 {
49+
options.Timeout = 2 * time.Second
4650
}
51+
4752
return &Handler{
4853
repanic: options.Repanic,
49-
timeout: timeout,
54+
timeout: options.Timeout,
5055
waitForDelivery: options.WaitForDelivery,
5156
}
5257
}
@@ -121,6 +126,7 @@ func GetHubFromContext(ctx *fasthttp.RequestCtx) *sentry.Hub {
121126
return nil
122127
}
123128

129+
// SetHubOnContext attaches the *sentry.Hub instance to the fasthttp.RequestCtx.
124130
func SetHubOnContext(ctx *fasthttp.RequestCtx, hub *sentry.Hub) {
125131
ctx.SetUserValue(valuesKey, hub)
126132
}
@@ -167,10 +173,8 @@ func convert(ctx *fasthttp.RequestCtx) *http.Request {
167173
r.AddCookie(&http.Cookie{Name: string(key), Value: string(value)})
168174
})
169175

170-
// Env
171176
r.RemoteAddr = ctx.RemoteAddr().String()
172177

173-
// Body
174178
r.Body = io.NopCloser(bytes.NewReader(ctx.Request.Body()))
175179

176180
return r

fiber/sentryfiber.go

+20-15
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ import (
1616
)
1717

1818
const (
19-
valuesKey = "sentry"
20-
sdkIdentifier = "sentry.go.fiber"
19+
// sdkIdentifier is the identifier of the FastHTTP SDK.
20+
sdkIdentifier = "sentry.go.fiber"
21+
22+
// valuesKey is used as a key to store the Sentry Hub instance on the fasthttp.RequestCtx.
23+
valuesKey = "sentry"
24+
25+
// transactionKey is used as a key to store the Sentry transaction on the fasthttp.RequestCtx.
2126
transactionKey = "sentry_transaction"
2227
)
2328

@@ -29,28 +34,27 @@ type handler struct {
2934

3035
type Options struct {
3136
// Repanic configures whether Sentry should repanic after recovery, in most cases it should be set to false,
32-
// as fasthttp doesn't include it's own Recovery handler.
37+
// as fasthttp doesn't include its own Recovery handler.
3338
Repanic bool
3439
// WaitForDelivery configures whether you want to block the request before moving forward with the response.
35-
// Because fasthttp doesn't include it's own Recovery handler, it will restart the application,
40+
// Because fasthttp doesn't include its own Recovery handler, it will restart the application,
3641
// and event won't be delivered otherwise.
3742
WaitForDelivery bool
3843
// Timeout for the event delivery requests.
3944
Timeout time.Duration
4045
}
4146

47+
// New returns a handler struct which satisfies Fiber's middleware interface
4248
func New(options Options) fiber.Handler {
43-
handler := handler{
44-
repanic: options.Repanic,
45-
timeout: time.Second * 2,
46-
waitForDelivery: options.WaitForDelivery,
49+
if options.Timeout == 0 {
50+
options.Timeout = 2 * time.Second
4751
}
4852

49-
if options.Timeout != 0 {
50-
handler.timeout = options.Timeout
51-
}
52-
53-
return handler.handle
53+
return (&handler{
54+
repanic: options.Repanic,
55+
timeout: options.Timeout,
56+
waitForDelivery: options.WaitForDelivery,
57+
}).handle
5458
}
5559

5660
func (h *handler) handle(ctx *fiber.Ctx) error {
@@ -115,17 +119,20 @@ func (h *handler) recoverWithSentry(hub *sentry.Hub, ctx *fiber.Ctx) {
115119
}
116120
}
117121

122+
// GetHubFromContext retrieves the Hub instance from the *fiber.Ctx.
118123
func GetHubFromContext(ctx *fiber.Ctx) *sentry.Hub {
119124
if hub, ok := ctx.Locals(valuesKey).(*sentry.Hub); ok {
120125
return hub
121126
}
122127
return nil
123128
}
124129

130+
// SetHubOnContext sets the Hub instance on the *fiber.Ctx.
125131
func SetHubOnContext(ctx *fiber.Ctx, hub *sentry.Hub) {
126132
ctx.Locals(valuesKey, hub)
127133
}
128134

135+
// GetSpanFromContext retrieves the Span instance from the *fiber.Ctx.
129136
func GetSpanFromContext(ctx *fiber.Ctx) *sentry.Span {
130137
if span, ok := ctx.Locals(transactionKey).(*sentry.Span); ok {
131138
return span
@@ -167,10 +174,8 @@ func convert(ctx *fiber.Ctx) *http.Request {
167174
r.AddCookie(&http.Cookie{Name: string(key), Value: string(value)})
168175
})
169176

170-
// Env
171177
r.RemoteAddr = ctx.Context().RemoteAddr().String()
172178

173-
// Body
174179
r.Body = io.NopCloser(bytes.NewReader(ctx.Request().Body()))
175180

176181
return r

gin/sentrygin.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ import (
1313
"github.com/gin-gonic/gin"
1414
)
1515

16-
// The identifier of the Gin SDK.
17-
const sdkIdentifier = "sentry.go.gin"
16+
const (
17+
// sdkIdentifier is the identifier of the Gin SDK.
18+
sdkIdentifier = "sentry.go.gin"
1819

19-
const valuesKey = "sentry"
20-
const transactionKey = "sentry_transaction"
20+
// valuesKey is used as a key to store the Sentry Hub instance on the gin.Context.
21+
valuesKey = "sentry"
22+
23+
// transactionKey is used as a key to store the Sentry transaction on the gin.Context.
24+
transactionKey = "sentry_transaction"
25+
)
2126

2227
type handler struct {
2328
repanic bool
@@ -40,13 +45,13 @@ type Options struct {
4045
// New returns a function that satisfies gin.HandlerFunc interface
4146
// It can be used with Use() methods.
4247
func New(options Options) gin.HandlerFunc {
43-
timeout := options.Timeout
44-
if timeout == 0 {
45-
timeout = 2 * time.Second
48+
if options.Timeout == 0 {
49+
options.Timeout = 2 * time.Second
4650
}
51+
4752
return (&handler{
4853
repanic: options.Repanic,
49-
timeout: timeout,
54+
timeout: options.Timeout,
5055
waitForDelivery: options.WaitForDelivery,
5156
}).handle
5257
}

http/sentryhttp.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ type Options struct {
5353
// New returns a new Handler. Use the Handle and HandleFunc methods to wrap
5454
// existing HTTP handlers.
5555
func New(options Options) *Handler {
56-
timeout := options.Timeout
57-
if timeout == 0 {
58-
timeout = 2 * time.Second
56+
if options.Timeout == 0 {
57+
options.Timeout = 2 * time.Second
5958
}
59+
6060
return &Handler{
6161
repanic: options.Repanic,
62-
timeout: timeout,
62+
timeout: options.Timeout,
6363
waitForDelivery: options.WaitForDelivery,
6464
}
6565
}

iris/sentryiris.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ import (
1212

1313
// The identifier of the Iris SDK.
1414
const (
15-
sdkIdentifier = "sentry.go.iris"
16-
valuesKey = "sentry"
15+
// sdkIdentifier is the identifier of the Iris SDK.
16+
sdkIdentifier = "sentry.go.iris"
17+
18+
// valuesKey is used as a key to store the Sentry Hub instance on the iris.Context.
19+
valuesKey = "sentry"
20+
21+
// transactionKey is used as a key to store the Sentry transaction on the iris.Context.
1722
transactionKey = "sentry_transaction"
1823
)
1924

@@ -38,13 +43,13 @@ type Options struct {
3843
// New returns a function that satisfies iris.Handler interface
3944
// It can be used with Use() method.
4045
func New(options Options) iris.Handler {
41-
timeout := options.Timeout
42-
if timeout == 0 {
43-
timeout = 2 * time.Second
46+
if options.Timeout == 0 {
47+
options.Timeout = 2 * time.Second
4448
}
49+
4550
return (&handler{
4651
repanic: options.Repanic,
47-
timeout: timeout,
52+
timeout: options.Timeout,
4853
waitForDelivery: options.WaitForDelivery,
4954
}).handle
5055
}
@@ -114,6 +119,7 @@ func GetHubFromContext(ctx iris.Context) *sentry.Hub {
114119
return nil
115120
}
116121

122+
// SetHubOnContext attaches a *sentry.Hub instance to iris.Context.
117123
func SetHubOnContext(ctx iris.Context, hub *sentry.Hub) {
118124
ctx.Values().Set(valuesKey, hub)
119125
}

logrus/logrusentry.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ import (
1111
sentry "github.com/getsentry/sentry-go"
1212
)
1313

14-
// The identifier of the Logrus SDK.
15-
const sdkIdentifier = "sentry.go.logrus"
16-
const name = "logrus"
14+
const (
15+
// sdkIdentifier is the identifier of the Logrus SDK.
16+
sdkIdentifier = "sentry.go.logrus"
17+
18+
// the name of the logger
19+
name = "logrus"
20+
)
1721

1822
// These default log field keys are used to pass specific metadata in a way that
1923
// Sentry understands. If they are found in the log fields, and the value is of

negroni/sentrynegroni.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type handler struct {
2222

2323
type Options struct {
2424
// Repanic configures whether Sentry should repanic after recovery, in most cases it should be set to true,
25-
// as negroni.Classic includes it's own Recovery middleware what handles http responses.
25+
// as negroni.Classic includes it's own Recovery middleware that handles http responses.
2626
Repanic bool
2727
// WaitForDelivery configures whether you want to block the request before moving forward with the response.
2828
// Because Negroni's default Recovery handler doesn't restart the application,
@@ -35,13 +35,13 @@ type Options struct {
3535
// New returns a handler struct which satisfies Negroni's middleware interface
3636
// It can be used with New(), Use() or With() methods.
3737
func New(options Options) negroni.Handler {
38-
timeout := options.Timeout
39-
if timeout == 0 {
40-
timeout = 2 * time.Second
38+
if options.Timeout == 0 {
39+
options.Timeout = 2 * time.Second
4140
}
41+
4242
return &handler{
4343
repanic: options.Repanic,
44-
timeout: timeout,
44+
timeout: options.Timeout,
4545
waitForDelivery: options.WaitForDelivery,
4646
}
4747
}
@@ -102,7 +102,7 @@ func (h *handler) recoverWithSentry(hub *sentry.Hub, r *http.Request) {
102102
}
103103

104104
// PanicHandlerFunc can be used for Negroni's default Recovery middleware option called PanicHandlerFunc,
105-
// which let you "plug-in" to it's own handler.
105+
// which let you "plug-in" to its own handler.
106106
func PanicHandlerFunc(info *negroni.PanicInformation) {
107107
hub := sentry.CurrentHub().Clone()
108108
hub.WithScope(func(scope *sentry.Scope) {

0 commit comments

Comments
 (0)