Is your feature request related to a problem? Please describe.
I am trying to implement this error reporting tool called Bugsnag as middleware with Iris.
On there page they have many examples with different GO frameworks, but not with Iris.
This is what I've tried so far:
package middleware
import (
"context"
"github.com/bugsnag/bugsnag-go"
"github.com/bugsnag/bugsnag-go/device"
"github.com/kataras/iris"
)
const FrameworkName string = "Iris"
func AutoNotify(rawData ...interface{}) iris.Handler {
for _, datum := range rawData {
if c, ok := datum.(bugsnag.Configuration); ok {
bugsnag.Configure(c)
}
}
device.AddVersion(FrameworkName, iris.Version)
state := bugsnag.HandledState{
SeverityReason: bugsnag.SeverityReasonUnhandledMiddlewareError,
OriginalSeverity: bugsnag.SeverityError,
Unhandled: true,
Framework: FrameworkName,
}
rawData = append(rawData, state)
return func(c iris.Context) {
r := c.Request().Clone(context.Background())
notifier := bugsnag.New(append(rawData, r)...)
ctx := bugsnag.AttachRequestData(r.Context(), r)
if notifier.Config.IsAutoCaptureSessions() {
ctx = bugsnag.StartSession(ctx)
}
// in the past I could have done this, but now this methos id gone
c.ResetRequest(r.WithContext(ctx))
notifier.FlushSessionsOnRepanic(false)
defer notifier.AutoNotify(ctx)
c.Next()
}
}
But ResetRequest(r *http.Request) method doesn't exists anymore to set the context's request.
Any thoughts?
Hello @speedwheel,
But ResetRequest(r *http.Request) method doesn't exists anymore to set the context's request.
It does exist my friend on master: https://github.com/kataras/iris/blob/789f0a186e7d0e89cd22426369b61ad242d7e743/context/context.go#L177 and on v12.1.8: https://github.com/kataras/iris/blob/a1e9813c610a61aba3e803a655cefc36c6efc3b2/context/context.go#L129
I created a PR which adds Iris integration on their repository at: https://github.com/bugsnag/bugsnag-go/pull/129.
You can see the code and the test at: https://github.com/bugsnag/bugsnag-go/pull/129/files#diff-0862ce3825a9a1e9f004faac60670428
@kataras Wow that was fast, thanks, you are awesome!
Thanks @speedwheel :heart: did you manage to get it working?
@kataras Yes it worked, thanks ❤️
Regarding the ResetRequest method, my bad, I imported "github.com/kataras/iris" instead of "github.com/kataras/iris"/v12.