mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-28 09:13:09 -06:00
Use HTTP Sentry properly maybe
This commit is contained in:
parent
83edb2d2f9
commit
a850a2dd15
|
|
@ -16,6 +16,7 @@ package httputil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
|
@ -25,6 +26,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/getsentry/sentry-go"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth"
|
"github.com/matrix-org/dendrite/clientapi/auth"
|
||||||
federationsenderAPI "github.com/matrix-org/dendrite/federationsender/api"
|
federationsenderAPI "github.com/matrix-org/dendrite/federationsender/api"
|
||||||
|
|
@ -59,8 +61,20 @@ func MakeAuthAPI(
|
||||||
logger := util.GetLogger((req.Context()))
|
logger := util.GetLogger((req.Context()))
|
||||||
logger = logger.WithField("user_id", device.UserID)
|
logger = logger.WithField("user_id", device.UserID)
|
||||||
req = req.WithContext(util.ContextWithLogger(req.Context(), logger))
|
req = req.WithContext(util.ContextWithLogger(req.Context(), logger))
|
||||||
|
// add the user to Sentry, if enabled
|
||||||
|
hub := sentry.GetHubFromContext(req.Context())
|
||||||
|
if hub != nil {
|
||||||
|
hub.Scope().SetTag("user_id", device.UserID)
|
||||||
|
hub.Scope().SetTag("device_id", device.ID)
|
||||||
|
}
|
||||||
|
|
||||||
return f(req, device)
|
jsonRes := f(req, device)
|
||||||
|
// do not log 4xx as errors as they are client fails, not server fails
|
||||||
|
if hub != nil && jsonRes.Code >= 500 {
|
||||||
|
hub.Scope().SetExtra("response", jsonRes)
|
||||||
|
hub.CaptureException(fmt.Errorf("%s returned HTTP %d", req.URL.Path, jsonRes.Code))
|
||||||
|
}
|
||||||
|
return jsonRes
|
||||||
}
|
}
|
||||||
return MakeExternalAPI(metricsName, h)
|
return MakeExternalAPI(metricsName, h)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue