Skip to content

Commit

Permalink
feat(echo): get Hub from request context if available (#217)
Browse files Browse the repository at this point in the history
This supports the use case of setting up a hub and populating the scope in an
earlier middleware that runs before the Echo framework starts handling the
request. A typical case is AWS Lambda + Echo. See [1] for an example.

[1]: #217 (comment)
  • Loading branch information
j--wong committed Jul 17, 2020
1 parent e7c66ce commit dc614c4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion echo/sentryecho.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ func New(options Options) echo.MiddlewareFunc {

func (h *handler) handle(next echo.HandlerFunc) echo.HandlerFunc {
return func(ctx echo.Context) error {
hub := sentry.CurrentHub().Clone()
var hub *sentry.Hub
if sentry.HasHubOnContext(ctx.Request().Context()) {
hub = sentry.GetHubFromContext(ctx.Request().Context())
} else {
hub = sentry.CurrentHub().Clone()
}
hub.Scope().SetRequest(ctx.Request())
ctx.Set(valuesKey, hub)
defer h.recoverWithSentry(hub, ctx.Request())
Expand Down

0 comments on commit dc614c4

Please sign in to comment.