TUN-1419: Identify request/response headers/content length with ray ID
This commit is contained in:
parent
61cd4a918d
commit
47c878b9c4
|
@ -534,7 +534,7 @@ func tunnelFlags(shouldHide bool) []cli.Flag {
|
||||||
altsrc.NewStringFlag(&cli.StringFlag{
|
altsrc.NewStringFlag(&cli.StringFlag{
|
||||||
Name: "loglevel",
|
Name: "loglevel",
|
||||||
Value: "info",
|
Value: "info",
|
||||||
Usage: "Application logging level {panic, fatal, error, warn, info, debug}",
|
Usage: "Application logging level {panic, fatal, error, warn, info, debug}. " + debugLevelWarning,
|
||||||
EnvVars: []string{"TUNNEL_LOGLEVEL"},
|
EnvVars: []string{"TUNNEL_LOGLEVEL"},
|
||||||
Hidden: shouldHide,
|
Hidden: shouldHide,
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -13,6 +13,9 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const debugLevelWarning = "At debug level, request URL, method, protocol, content legnth and header will be logged. " +
|
||||||
|
"Response status, content length and header will also be logged in debug level."
|
||||||
|
|
||||||
var logger = log.CreateLogger()
|
var logger = log.CreateLogger()
|
||||||
|
|
||||||
func configMainLogger(c *cli.Context) error {
|
func configMainLogger(c *cli.Context) error {
|
||||||
|
@ -22,6 +25,9 @@ func configMainLogger(c *cli.Context) error {
|
||||||
return errors.Wrap(err, "Unknown logging level specified")
|
return errors.Wrap(err, "Unknown logging level specified")
|
||||||
}
|
}
|
||||||
logger.SetLevel(logLevel)
|
logger.SetLevel(logLevel)
|
||||||
|
if logLevel == logrus.DebugLevel {
|
||||||
|
logger.Warn(debugLevelWarning)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -636,25 +636,41 @@ func (h *TunnelHandler) logError(stream *h2mux.MuxedStream, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *TunnelHandler) logRequest(req *http.Request, cfRay string, lbProbe bool) {
|
func (h *TunnelHandler) logRequest(req *http.Request, cfRay string, lbProbe bool) {
|
||||||
|
logger := log.NewEntry(h.logger)
|
||||||
if cfRay != "" {
|
if cfRay != "" {
|
||||||
h.logger.WithField("CF-RAY", cfRay).Debugf("%s %s %s", req.Method, req.URL, req.Proto)
|
logger = logger.WithField("CF-RAY", cfRay)
|
||||||
|
logger.Debugf("%s %s %s", req.Method, req.URL, req.Proto)
|
||||||
} else if lbProbe {
|
} else if lbProbe {
|
||||||
h.logger.Debugf("Load Balancer health check %s %s %s", req.Method, req.URL, req.Proto)
|
logger.Debugf("Load Balancer health check %s %s %s", req.Method, req.URL, req.Proto)
|
||||||
} else {
|
} else {
|
||||||
h.logger.Warnf("All requests should have a CF-RAY header. Please open a support ticket with Cloudflare. %s %s %s ", req.Method, req.URL, req.Proto)
|
logger.Warnf("All requests should have a CF-RAY header. Please open a support ticket with Cloudflare. %s %s %s ", req.Method, req.URL, req.Proto)
|
||||||
|
}
|
||||||
|
logger.Debugf("Request Headers %+v", req.Header)
|
||||||
|
|
||||||
|
if contentLen := req.ContentLength; contentLen == -1 {
|
||||||
|
logger.Debugf("Request Content length unknown")
|
||||||
|
} else {
|
||||||
|
logger.Debugf("Request content length %d", contentLen)
|
||||||
}
|
}
|
||||||
h.logger.Debugf("Request Headers %+v", req.Header)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *TunnelHandler) logResponse(r *http.Response, cfRay string, lbProbe bool) {
|
func (h *TunnelHandler) logResponse(r *http.Response, cfRay string, lbProbe bool) {
|
||||||
|
logger := log.NewEntry(h.logger)
|
||||||
if cfRay != "" {
|
if cfRay != "" {
|
||||||
h.logger.WithField("CF-RAY", cfRay).Debugf("%s", r.Status)
|
logger = logger.WithField("CF-RAY", cfRay)
|
||||||
|
logger.Debugf("%s", r.Status)
|
||||||
} else if lbProbe {
|
} else if lbProbe {
|
||||||
h.logger.Debugf("Response to Load Balancer health check %s", r.Status)
|
logger.Debugf("Response to Load Balancer health check %s", r.Status)
|
||||||
} else {
|
} else {
|
||||||
h.logger.Infof("%s", r.Status)
|
logger.Infof("%s", r.Status)
|
||||||
|
}
|
||||||
|
logger.Debugf("Response Headers %+v", r.Header)
|
||||||
|
|
||||||
|
if contentLen := r.ContentLength; contentLen == -1 {
|
||||||
|
logger.Debugf("Response content length unknown")
|
||||||
|
} else {
|
||||||
|
logger.Debugf("Response content length %d", contentLen)
|
||||||
}
|
}
|
||||||
h.logger.Debugf("Response Headers %+v", r.Header)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *TunnelHandler) UpdateMetrics(connectionID string) {
|
func (h *TunnelHandler) UpdateMetrics(connectionID string) {
|
||||||
|
|
Loading…
Reference in New Issue