|
|
|
|
@ -90,9 +90,12 @@ func FromContext(c context.Context) *models.ReqContext { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Middleware provides a middleware to initialize the Macaron context.
|
|
|
|
|
func (h *ContextHandler) Middleware(mContext *web.Context) { |
|
|
|
|
_, span := h.tracer.Start(mContext.Req.Context(), "Auth - Middleware") |
|
|
|
|
// Middleware provides a middleware to initialize the request context.
|
|
|
|
|
func (h *ContextHandler) Middleware(next http.Handler) http.Handler { |
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
ctx := r.Context() |
|
|
|
|
mContext := web.FromContext(ctx) |
|
|
|
|
_, span := h.tracer.Start(ctx, "Auth - Middleware") |
|
|
|
|
defer span.End() |
|
|
|
|
|
|
|
|
|
reqContext := &models.ReqContext{ |
|
|
|
|
@ -105,7 +108,7 @@ func (h *ContextHandler) Middleware(mContext *web.Context) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Inject ReqContext into http.Request.Context
|
|
|
|
|
mContext.Req = mContext.Req.WithContext(ctxkey.Set(mContext.Req.Context(), reqContext)) |
|
|
|
|
*r = *r.WithContext(context.WithValue(ctx, reqContextKey{}, reqContext)) |
|
|
|
|
|
|
|
|
|
traceID := tracing.TraceIDFromContext(mContext.Req.Context(), false) |
|
|
|
|
if traceID != "" { |
|
|
|
|
@ -168,6 +171,9 @@ func (h *ContextHandler) Middleware(mContext *web.Context) { |
|
|
|
|
reqContext.Logger.Error("Failed to update last_seen_at", "error", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
next.ServeHTTP(w, r) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (h *ContextHandler) initContextWithAnonymousUser(reqContext *models.ReqContext) bool { |
|
|
|
|
|