Commit f144f4dc authored by ale's avatar ale

Add tracing support to auth-server requests

parent ad4e6235
Pipeline #1599 passed with stages
in 1 minute and 42 seconds
......@@ -16,6 +16,7 @@ import (
"github.com/gorilla/csrf"
"github.com/gorilla/sessions"
"github.com/tstranex/u2f"
"go.opencensus.io/trace"
"git.autistici.org/id/auth"
authclient "git.autistici.org/id/auth/client"
......@@ -293,7 +294,31 @@ func (l *loginHandler) makeAuthRequest(w http.ResponseWriter, req *http.Request,
U2FResponse: u2fResponse,
U2FAppID: appID,
}
return l.authClient.Authenticate(req.Context(), &ar)
// Trace the authentication request.
ctx, span := trace.StartSpan(req.Context(), "auth",
trace.WithSpanKind(trace.SpanKindClient))
span.AddAttributes(
trace.StringAttribute("auth.user", username),
trace.StringAttribute("auth.service", l.authService),
trace.BoolAttribute("auth.with_password", len(password) > 0),
trace.BoolAttribute("auth.with_otp", otp != ""),
trace.BoolAttribute("auth.with_u2f", u2fResponse != nil),
)
defer span.End()
resp, err := l.authClient.Authenticate(ctx, &ar)
// Record the authentication response status in the trace.
if err != nil {
span.SetStatus(trace.Status{Code: trace.StatusCodeUnknown, Message: err.Error()})
} else if resp.Status == auth.StatusOK {
span.SetStatus(trace.Status{Code: trace.StatusCodeOK, Message: "OK"})
} else {
span.SetStatus(trace.Status{Code: trace.StatusCodePermissionDenied, Message: resp.Status.String()})
}
return resp, err
}
// Return a (relative) URL that will redirect the user to the login
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment