aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/caddyhttp/app.go3
-rw-r--r--modules/caddyhttp/logging.go11
-rw-r--r--modules/caddyhttp/routes.go6
-rw-r--r--modules/caddyhttp/server.go10
4 files changed, 28 insertions, 2 deletions
diff --git a/modules/caddyhttp/app.go b/modules/caddyhttp/app.go
index 4df8689a5..5dbecf9b2 100644
--- a/modules/caddyhttp/app.go
+++ b/modules/caddyhttp/app.go
@@ -198,6 +198,9 @@ func (app *App) Provision(ctx caddy.Context) error {
// only enable access logs if configured
if srv.Logs != nil {
srv.accessLogger = app.logger.Named("log.access")
+ if srv.Logs.Trace {
+ srv.traceLogger = app.logger.Named("log.trace")
+ }
}
// the Go standard library does not let us serve only HTTP/2 using
diff --git a/modules/caddyhttp/logging.go b/modules/caddyhttp/logging.go
index 1fab1e8e8..823763e91 100644
--- a/modules/caddyhttp/logging.go
+++ b/modules/caddyhttp/logging.go
@@ -65,6 +65,17 @@ type ServerLogConfig struct {
// and this includes some request and response headers, i.e `Cookie`,
// `Set-Cookie`, `Authorization`, and `Proxy-Authorization`.
ShouldLogCredentials bool `json:"should_log_credentials,omitempty"`
+
+ // Log each individual handler that is invoked.
+ // Requires that the log emit at DEBUG level.
+ //
+ // NOTE: This may log the configuration of your
+ // HTTP handler modules; do not enable this in
+ // insecure contexts when there is sensitive
+ // data in the configuration.
+ //
+ // EXPERIMENTAL: Subject to change or removal.
+ Trace bool `json:"trace,omitempty"`
}
// wrapLogger wraps logger in one or more logger named
diff --git a/modules/caddyhttp/routes.go b/modules/caddyhttp/routes.go
index 9db4f2520..6f2371495 100644
--- a/modules/caddyhttp/routes.go
+++ b/modules/caddyhttp/routes.go
@@ -326,8 +326,10 @@ func wrapMiddleware(_ caddy.Context, mh MiddlewareHandler, metrics *Metrics) Mid
nextCopy := next
return HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {
- // TODO: This is where request tracing could be implemented
- // TODO: see what the std lib gives us in terms of stack tracing too
+ // EXPERIMENTAL: Trace each module that gets invoked
+ if server, ok := r.Context().Value(ServerCtxKey).(*Server); ok && server != nil {
+ server.logTrace(handlerToUse)
+ }
return handlerToUse.ServeHTTP(w, r, nextCopy)
})
}
diff --git a/modules/caddyhttp/server.go b/modules/caddyhttp/server.go
index 1d621456d..96a819b40 100644
--- a/modules/caddyhttp/server.go
+++ b/modules/caddyhttp/server.go
@@ -234,6 +234,7 @@ type Server struct {
logger *zap.Logger
accessLogger *zap.Logger
errorLogger *zap.Logger
+ traceLogger *zap.Logger
ctx caddy.Context
server *http.Server
@@ -738,6 +739,15 @@ func (s *Server) shouldLogRequest(r *http.Request) bool {
return !s.Logs.SkipUnmappedHosts
}
+// logTrace will log that this middleware handler is being invoked.
+// It emits at DEBUG level.
+func (s *Server) logTrace(mh MiddlewareHandler) {
+ if s.Logs == nil || !s.Logs.Trace {
+ return
+ }
+ s.traceLogger.Debug(caddy.GetModuleName(mh), zap.Any("module", mh))
+}
+
// logRequest logs the request to access logs, unless skipped.
func (s *Server) logRequest(
accLog *zap.Logger, r *http.Request, wrec ResponseRecorder, duration *time.Duration,