From d67f681b43a4c8529f9133702d0b5327e504e887 Mon Sep 17 00:00:00 2001 From: zensh Date: Fri, 27 Mar 2020 16:32:38 +0800 Subject: [PATCH] add cannary info to access log. --- pkg/middlewares/canary/canary.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/middlewares/canary/canary.go b/pkg/middlewares/canary/canary.go index eb4f76a5ae..0f2a9d9e2e 100644 --- a/pkg/middlewares/canary/canary.go +++ b/pkg/middlewares/canary/canary.go @@ -13,6 +13,7 @@ import ( "github.com/containous/traefik/v2/pkg/config/dynamic" "github.com/containous/traefik/v2/pkg/log" "github.com/containous/traefik/v2/pkg/middlewares" + "github.com/containous/traefik/v2/pkg/middlewares/accesslog" "github.com/containous/traefik/v2/pkg/tracing" "github.com/opentracing/opentracing-go/ext" ) @@ -81,6 +82,15 @@ func (c *Canary) GetTracingInformation() (string, ext.SpanKindEnum) { func (c *Canary) ServeHTTP(rw http.ResponseWriter, req *http.Request) { c.processRequestID(rw, req) c.processCanary(rw, req) + + if logData := accesslog.GetLogData(req); logData != nil { + if requestID := req.Header.Get(headerXRequestID); requestID != "" { + logData.Core["XRequestID"] = requestID + } + if xCanary := req.Header.Values(headerXCanary); len(xCanary) > 0 { + logData.Core["XCanary"] = xCanary + } + } c.next.ServeHTTP(rw, req) }