From f33bd70d75185964b8579d38d4f1987aa8e73935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8C=85=E5=AD=90?= Date: Wed, 28 Apr 2021 16:23:55 +0800 Subject: [PATCH] middleware/logging client add traceid (#878) --- middleware/logging/logging.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/middleware/logging/logging.go b/middleware/logging/logging.go index 6e865ce43..001d4c008 100644 --- a/middleware/logging/logging.go +++ b/middleware/logging/logging.go @@ -101,10 +101,12 @@ func Client(l log.Logger) middleware.Middleware { var ( path string method string - component string args string + component string query string + traceID string ) + traceID = trace.SpanContextFromContext(ctx).TraceID().String() if info, ok := http.FromClientContext(ctx); ok { component = "HTTP" path = info.Request.URL.Path @@ -123,6 +125,7 @@ func Client(l log.Logger) middleware.Middleware { logger.Errorw( "kind", "client", "component", component, + "traceID", traceID, "path", path, "method", method, "args", args, @@ -135,6 +138,7 @@ func Client(l log.Logger) middleware.Middleware { logger.Infow( "kind", "client", "component", component, + "traceID", traceID, "path", path, "method", method, "args", args, @@ -146,6 +150,7 @@ func Client(l log.Logger) middleware.Middleware { logger.Errorw( "kind", "client", "component", component, + "traceID", traceID, "path", path, "method", method, "args", args, @@ -157,6 +162,7 @@ func Client(l log.Logger) middleware.Middleware { logger.Infow( "kind", "client", "component", component, + "traceID", traceID, "path", path, "method", method, "args", args,