You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2024/01/03 03:23:40 UTC

(servicecomb-java-chassis) branch master updated: [SCB-2848]setting trace id to MDC in executor (#4172)

This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git


The following commit(s) were added to refs/heads/master by this push:
     new aba764c85 [SCB-2848]setting trace id to MDC in executor (#4172)
aba764c85 is described below

commit aba764c85ff7fb736b140db62e109fa0c9a719f3
Author: liubao68 <bi...@qq.com>
AuthorDate: Wed Jan 3 11:23:34 2024 +0800

    [SCB-2848]setting trace id to MDC in executor (#4172)
---
 .../org/apache/servicecomb/core/Invocation.java    |  5 ----
 .../event/InvocationRunInExecutorFinishEvent.java  | 28 ------------------
 .../event/InvocationRunInExecutorStartEvent.java   | 25 ----------------
 .../core/exception/DefaultExceptionProcessor.java  | 29 +++++++++++++------
 .../core/filter/impl/ScheduleFilter.java           | 11 ++++----
 .../invocation/InvocationTimeoutBootListener.java  |  7 -----
 .../servicecomb/core/tracing/TraceIdLogger.java    | 33 ++++++++++++----------
 .../apache/servicecomb/core/TestInvocation.java    |  4 +--
 .../localRegistryServer/CodeFirstEndpoint.java     | 11 ++------
 .../demo/localRegistryServer/ServerEndpoint.java   | 11 ++------
 .../servicecomb/demo/registry/ServerEndpoint.java  | 11 ++------
 .../demo/multiServiceCenter/ServerEndpoint.java    | 11 ++------
 .../multiServiceCenterServerB/ServerEndpoint.java  | 11 ++------
 .../demo/prefix/RegisterUrlPrefixEndpoint.java     | 11 ++------
 .../demo/zeroconfig/edge/ServerEndpoint.java       | 10 ++-----
 .../demo/zeroconfig/server/ServerEndpoint.java     | 10 ++-----
 .../src/main/resources/microservice.yaml           |  2 +-
 17 files changed, 70 insertions(+), 160 deletions(-)

diff --git a/core/src/main/java/org/apache/servicecomb/core/Invocation.java b/core/src/main/java/org/apache/servicecomb/core/Invocation.java
index fe2f5d6a4..11fe585f5 100644
--- a/core/src/main/java/org/apache/servicecomb/core/Invocation.java
+++ b/core/src/main/java/org/apache/servicecomb/core/Invocation.java
@@ -35,7 +35,6 @@ import org.apache.servicecomb.core.event.InvocationBusinessFinishEvent;
 import org.apache.servicecomb.core.event.InvocationBusinessMethodStartEvent;
 import org.apache.servicecomb.core.event.InvocationEncodeResponseStartEvent;
 import org.apache.servicecomb.core.event.InvocationFinishEvent;
-import org.apache.servicecomb.core.event.InvocationRunInExecutorFinishEvent;
 import org.apache.servicecomb.core.event.InvocationStartEvent;
 import org.apache.servicecomb.core.event.InvocationStartSendRequestEvent;
 import org.apache.servicecomb.core.event.InvocationTimeoutCheckEvent;
@@ -340,10 +339,6 @@ public class Invocation extends SwaggerInvocation {
     onStart();
   }
 
-  public void onExecuteFinish() {
-    EventManager.post(new InvocationRunInExecutorFinishEvent(this));
-  }
-
   public void onStartSendRequest() {
     EventManager.post(new InvocationStartSendRequestEvent(this));
   }
diff --git a/core/src/main/java/org/apache/servicecomb/core/event/InvocationRunInExecutorFinishEvent.java b/core/src/main/java/org/apache/servicecomb/core/event/InvocationRunInExecutorFinishEvent.java
deleted file mode 100644
index 73ee6cd6d..000000000
--- a/core/src/main/java/org/apache/servicecomb/core/event/InvocationRunInExecutorFinishEvent.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.core.event;
-
-import org.apache.servicecomb.core.Invocation;
-
-/**
- * for async invocation, only indicate finished in executor, not finished invocation
- */
-public class InvocationRunInExecutorFinishEvent extends InvocationBaseEvent {
-  public InvocationRunInExecutorFinishEvent(Invocation invocation) {
-    super(invocation);
-  }
-}
diff --git a/core/src/main/java/org/apache/servicecomb/core/event/InvocationRunInExecutorStartEvent.java b/core/src/main/java/org/apache/servicecomb/core/event/InvocationRunInExecutorStartEvent.java
deleted file mode 100644
index 3779bde03..000000000
--- a/core/src/main/java/org/apache/servicecomb/core/event/InvocationRunInExecutorStartEvent.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.core.event;
-
-import org.apache.servicecomb.core.Invocation;
-
-public class InvocationRunInExecutorStartEvent extends InvocationBaseEvent {
-  public InvocationRunInExecutorStartEvent(Invocation invocation) {
-    super(invocation);
-  }
-}
diff --git a/core/src/main/java/org/apache/servicecomb/core/exception/DefaultExceptionProcessor.java b/core/src/main/java/org/apache/servicecomb/core/exception/DefaultExceptionProcessor.java
index 6eb43d069..2d9a0b14e 100644
--- a/core/src/main/java/org/apache/servicecomb/core/exception/DefaultExceptionProcessor.java
+++ b/core/src/main/java/org/apache/servicecomb/core/exception/DefaultExceptionProcessor.java
@@ -32,6 +32,7 @@ import java.util.stream.Collectors;
 import org.apache.servicecomb.config.inject.InjectProperties;
 import org.apache.servicecomb.config.inject.InjectProperty;
 import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.core.tracing.TraceIdLogger;
 import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
 import org.apache.servicecomb.foundation.common.utils.ExceptionUtils;
 import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
@@ -113,9 +114,17 @@ public class DefaultExceptionProcessor implements ExceptionProcessor {
     try {
       ExceptionConverter<Throwable> converter =
           converterCache.computeIfAbsent(unwrapped.getClass(), clazz -> findConverter(unwrapped));
-      LOGGER.warn("convert operation {} exception using {}.",
-          invocation == null ? "NA" : invocation.getMicroserviceQualifiedName(),
-          converter.getClass().getSimpleName(), throwable);
+      if (invocation == null) {
+        LOGGER.warn("Convert unknown operation exception {}/{} using {}.",
+            throwable.getClass().getSimpleName(), unwrapped.getClass().getSimpleName(),
+            converter.getClass().getSimpleName());
+      } else {
+        invocation.getTraceIdLogger().warn("{} Convert operation {} exception {}/{} using {}.",
+            TraceIdLogger.constructSource(DefaultExceptionProcessor.class.getSimpleName()),
+            invocation.getMicroserviceQualifiedName(),
+            throwable.getClass().getSimpleName(), unwrapped.getClass().getSimpleName(),
+            converter.getClass().getSimpleName());
+      }
       return converter.convert(invocation, unwrapped, genericStatus);
     } catch (Exception e) {
       LOGGER.error("BUG: ExceptionConverter.convert MUST not throw exception, please fix it.\n"
@@ -152,18 +161,18 @@ public class DefaultExceptionProcessor implements ExceptionProcessor {
     }
 
     if (isPrintStackTrace()) {
-      LOGGER.error("failed to invoke {}, endpoint={}, trace id={}.",
+      invocation.getTraceIdLogger().error("{} Failed to invoke {}, endpoint={}.",
+          TraceIdLogger.constructSource(DefaultExceptionProcessor.class.getSimpleName()),
           invocation.getMicroserviceQualifiedName(),
           invocation.getEndpoint(),
-          invocation.getTraceId(),
           exception);
       return;
     }
 
-    LOGGER.error("failed to invoke {}, endpoint={}, trace id={}, message={}.",
+    invocation.getTraceIdLogger().error("{} Failed to invoke {}, endpoint={}, message={}.",
+        TraceIdLogger.constructSource(DefaultExceptionProcessor.class.getSimpleName()),
         invocation.getMicroserviceQualifiedName(),
         invocation.getEndpoint(),
-        invocation.getTraceId(),
         ExceptionUtils.getExceptionMessageWithoutTrace(exception));
   }
 
@@ -193,12 +202,14 @@ public class DefaultExceptionProcessor implements ExceptionProcessor {
     }
 
     if (isPrintStackTrace()) {
-      LOGGER.error("failed to process {} invocation, operation={}.",
+      invocation.getTraceIdLogger().error("{} Failed to process {} invocation, operation={}.",
+          TraceIdLogger.constructSource(DefaultExceptionProcessor.class.getSimpleName()),
           invocation.getInvocationType(), invocation.getMicroserviceQualifiedName(), exception);
       return;
     }
 
-    LOGGER.error("failed to process {} invocation, operation={}, message={}.",
+    invocation.getTraceIdLogger().error("{} Failed to process {} invocation, operation={}, message={}.",
+        TraceIdLogger.constructSource(DefaultExceptionProcessor.class.getSimpleName()),
         invocation.getInvocationType(), invocation.getMicroserviceQualifiedName(),
         ExceptionUtils.getExceptionMessageWithoutTrace(exception));
   }
diff --git a/core/src/main/java/org/apache/servicecomb/core/filter/impl/ScheduleFilter.java b/core/src/main/java/org/apache/servicecomb/core/filter/impl/ScheduleFilter.java
index 058ce3600..341c01fa8 100644
--- a/core/src/main/java/org/apache/servicecomb/core/filter/impl/ScheduleFilter.java
+++ b/core/src/main/java/org/apache/servicecomb/core/filter/impl/ScheduleFilter.java
@@ -24,8 +24,10 @@ import org.apache.servicecomb.core.filter.AbstractFilter;
 import org.apache.servicecomb.core.filter.Filter;
 import org.apache.servicecomb.core.filter.FilterNode;
 import org.apache.servicecomb.core.filter.ProviderFilter;
+import org.apache.servicecomb.core.tracing.TraceIdLogger;
 import org.apache.servicecomb.swagger.invocation.Response;
 import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.slf4j.MDC;
 
 import jakarta.ws.rs.core.Response.Status;
 
@@ -52,12 +54,9 @@ public class ScheduleFilter extends AbstractFilter implements ProviderFilter {
 
   protected CompletableFuture<Response> runInExecutor(Invocation invocation, FilterNode next) {
     invocation.getInvocationStageTrace().finishProviderQueue();
-    try {
-      checkInQueueTimeout(invocation);
-      return next.onFilter(invocation);
-    } finally {
-      invocation.onExecuteFinish();
-    }
+    MDC.put(TraceIdLogger.KEY_TRACE_ID, invocation.getTraceId());
+    checkInQueueTimeout(invocation);
+    return next.onFilter(invocation);
   }
 
   private void checkInQueueTimeout(Invocation invocation) {
diff --git a/core/src/main/java/org/apache/servicecomb/core/invocation/InvocationTimeoutBootListener.java b/core/src/main/java/org/apache/servicecomb/core/invocation/InvocationTimeoutBootListener.java
index e21ed59b2..0c5da22ff 100644
--- a/core/src/main/java/org/apache/servicecomb/core/invocation/InvocationTimeoutBootListener.java
+++ b/core/src/main/java/org/apache/servicecomb/core/invocation/InvocationTimeoutBootListener.java
@@ -21,7 +21,6 @@ import java.util.List;
 
 import org.apache.servicecomb.core.event.InvocationBusinessFinishEvent;
 import org.apache.servicecomb.core.event.InvocationBusinessMethodStartEvent;
-import org.apache.servicecomb.core.event.InvocationRunInExecutorStartEvent;
 import org.apache.servicecomb.core.event.InvocationStartEvent;
 import org.apache.servicecomb.core.event.InvocationStartSendRequestEvent;
 import org.apache.servicecomb.core.event.InvocationTimeoutCheckEvent;
@@ -73,12 +72,6 @@ public class InvocationTimeoutBootListener {
     strategy.start(event.getInvocation());
   }
 
-  @Subscribe
-  @EnableExceptionPropagation
-  public void onInvocationRunInExecutorStartEvent(InvocationRunInExecutorStartEvent event) {
-    strategy.startRunInExecutor(event.getInvocation());
-  }
-
   @Subscribe
   @EnableExceptionPropagation
   public void onInvocationBusinessMethodStartEvent(InvocationBusinessMethodStartEvent event) {
diff --git a/core/src/main/java/org/apache/servicecomb/core/tracing/TraceIdLogger.java b/core/src/main/java/org/apache/servicecomb/core/tracing/TraceIdLogger.java
index 72fd77a39..18f0e3664 100644
--- a/core/src/main/java/org/apache/servicecomb/core/tracing/TraceIdLogger.java
+++ b/core/src/main/java/org/apache/servicecomb/core/tracing/TraceIdLogger.java
@@ -18,18 +18,19 @@ package org.apache.servicecomb.core.tracing;
 
 import org.apache.servicecomb.core.Invocation;
 import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
 import org.slf4j.Marker;
 
 public class TraceIdLogger {
+  private static final Logger LOGGER = LoggerFactory.getLogger("scb-trace");
+
   private static final Marker MARKER = new ScbMarker();
 
-  private static final String KEY_TRACE_ID = "SERVICECOMB_TRACE_ID";
+  public static final String KEY_TRACE_ID = "SERVICECOMB_TRACE_ID";
 
   private final Invocation invocation;
 
-  private String name;
-
   public TraceIdLogger(Invocation invocation) {
     this.invocation = invocation;
   }
@@ -38,34 +39,36 @@ public class TraceIdLogger {
     return invocation;
   }
 
+  public static String constructSource(String source) {
+    return "[" + source + "(" +
+        Thread.currentThread().getStackTrace()[2].getLineNumber() + ")]";
+  }
+
   public final String getName() {
-    if (name == null) {
-      name = invocation.getTraceId() + "-" + invocation.getInvocationId();
-    }
-    return name;
+    return invocation.getTraceId();
   }
 
-  public void error(Logger logger, String format, Object... arguments) {
+  public void error(String format, Object... arguments) {
     MDC.put(KEY_TRACE_ID, getName());
-    logger.error(MARKER, format, arguments);
+    LOGGER.error(MARKER, format, arguments);
     MDC.remove(KEY_TRACE_ID);
   }
 
-  public void warn(Logger logger, String format, Object... arguments) {
+  public void warn(String format, Object... arguments) {
     MDC.put(KEY_TRACE_ID, getName());
-    logger.warn(MARKER, format, arguments);
+    LOGGER.warn(MARKER, format, arguments);
     MDC.remove(KEY_TRACE_ID);
   }
 
-  public void info(Logger logger, String format, Object... arguments) {
+  public void info(String format, Object... arguments) {
     MDC.put(KEY_TRACE_ID, getName());
-    logger.info(MARKER, format, arguments);
+    LOGGER.info(MARKER, format, arguments);
     MDC.remove(KEY_TRACE_ID);
   }
 
-  public void debug(Logger logger, String format, Object... arguments) {
+  public void debug(String format, Object... arguments) {
     MDC.put(KEY_TRACE_ID, getName());
-    logger.debug(MARKER, format, arguments);
+    LOGGER.debug(MARKER, format, arguments);
     MDC.remove(KEY_TRACE_ID);
   }
 }
diff --git a/core/src/test/java/org/apache/servicecomb/core/TestInvocation.java b/core/src/test/java/org/apache/servicecomb/core/TestInvocation.java
index ac1af9b51..4cf335cd3 100644
--- a/core/src/test/java/org/apache/servicecomb/core/TestInvocation.java
+++ b/core/src/test/java/org/apache/servicecomb/core/TestInvocation.java
@@ -268,11 +268,11 @@ public class TestInvocation {
     Invocation invocation = new Invocation(referenceConfig, operationMeta, invocationRuntimeType, arguments);
     invocation.addContext(CoreConst.TRACE_ID_NAME, "abc");
     invocation.onStart();
-    Assertions.assertEquals("abc-0", invocation.getTraceIdLogger().getName());
+    Assertions.assertEquals("abc", invocation.getTraceIdLogger().getName());
 
     invocation = new Invocation(referenceConfig, operationMeta, invocationRuntimeType, arguments);
     invocation.addContext(CoreConst.TRACE_ID_NAME, "abc");
     invocation.onStart();
-    Assertions.assertEquals("abc-1", invocation.getTraceIdLogger().getName());
+    Assertions.assertEquals("abc", invocation.getTraceIdLogger().getName());
   }
 }
diff --git a/demo/demo-local-registry/demo-local-registry-server/src/main/java/org/apache/servicecomb/demo/localRegistryServer/CodeFirstEndpoint.java b/demo/demo-local-registry/demo-local-registry-server/src/main/java/org/apache/servicecomb/demo/localRegistryServer/CodeFirstEndpoint.java
index 7a01fcbdd..06fdf6b79 100644
--- a/demo/demo-local-registry/demo-local-registry-server/src/main/java/org/apache/servicecomb/demo/localRegistryServer/CodeFirstEndpoint.java
+++ b/demo/demo-local-registry/demo-local-registry-server/src/main/java/org/apache/servicecomb/demo/localRegistryServer/CodeFirstEndpoint.java
@@ -17,26 +17,21 @@
 
 package org.apache.servicecomb.demo.localRegistryServer;
 
-import jakarta.ws.rs.core.MediaType;
-
 import org.apache.servicecomb.core.Invocation;
 import org.apache.servicecomb.provider.rest.common.RestSchema;
 import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import jakarta.ws.rs.core.MediaType;
+
 @RestSchema(schemaId = "CodeFirstEndpoint")
 @RequestMapping(path = "/register/url/codeFirst", produces = MediaType.APPLICATION_JSON)
 public class CodeFirstEndpoint {
-  private static final Logger LOGGER
-      = LoggerFactory.getLogger(CodeFirstEndpoint.class);
-
   @GetMapping(path = "/getName")
   public String getName(@RequestParam(name = "name") String name) {
-    ((Invocation) ContextUtils.getInvocationContext()).getTraceIdLogger().info(LOGGER, "get name invoked.");
+    ((Invocation) ContextUtils.getInvocationContext()).getTraceIdLogger().info("get name invoked.");
     return name;
   }
 }
diff --git a/demo/demo-local-registry/demo-local-registry-server/src/main/java/org/apache/servicecomb/demo/localRegistryServer/ServerEndpoint.java b/demo/demo-local-registry/demo-local-registry-server/src/main/java/org/apache/servicecomb/demo/localRegistryServer/ServerEndpoint.java
index be39f3a79..2db9d87dd 100644
--- a/demo/demo-local-registry/demo-local-registry-server/src/main/java/org/apache/servicecomb/demo/localRegistryServer/ServerEndpoint.java
+++ b/demo/demo-local-registry/demo-local-registry-server/src/main/java/org/apache/servicecomb/demo/localRegistryServer/ServerEndpoint.java
@@ -17,26 +17,21 @@
 
 package org.apache.servicecomb.demo.localRegistryServer;
 
-import jakarta.ws.rs.core.MediaType;
-
 import org.apache.servicecomb.core.Invocation;
 import org.apache.servicecomb.provider.rest.common.RestSchema;
 import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import jakarta.ws.rs.core.MediaType;
+
 @RestSchema(schemaId = "ServerEndpoint")
 @RequestMapping(path = "/register/url/prefix", produces = MediaType.APPLICATION_JSON)
 public class ServerEndpoint {
-  private static final Logger LOGGER
-      = LoggerFactory.getLogger(ServerEndpoint.class);
-
   @GetMapping(path = "/getName")
   public String getName(@RequestParam(name = "name") String name) {
-    ((Invocation) ContextUtils.getInvocationContext()).getTraceIdLogger().info(LOGGER, "get name invoked.");
+    ((Invocation) ContextUtils.getInvocationContext()).getTraceIdLogger().info("get name invoked.");
     return name;
   }
 }
diff --git a/demo/demo-multi-registries/demo-multi-registries-server/src/main/java/org/apache/servicecomb/demo/registry/ServerEndpoint.java b/demo/demo-multi-registries/demo-multi-registries-server/src/main/java/org/apache/servicecomb/demo/registry/ServerEndpoint.java
index 03ed503e6..eb594aaba 100644
--- a/demo/demo-multi-registries/demo-multi-registries-server/src/main/java/org/apache/servicecomb/demo/registry/ServerEndpoint.java
+++ b/demo/demo-multi-registries/demo-multi-registries-server/src/main/java/org/apache/servicecomb/demo/registry/ServerEndpoint.java
@@ -17,26 +17,21 @@
 
 package org.apache.servicecomb.demo.registry;
 
-import jakarta.ws.rs.core.MediaType;
-
 import org.apache.servicecomb.core.Invocation;
 import org.apache.servicecomb.provider.rest.common.RestSchema;
 import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import jakarta.ws.rs.core.MediaType;
+
 @RestSchema(schemaId = "ServerEndpoint")
 @RequestMapping(path = "/register/url/prefix", produces = MediaType.APPLICATION_JSON)
 public class ServerEndpoint {
-  private static final Logger LOGGER
-      = LoggerFactory.getLogger(ServerEndpoint.class);
-
   @GetMapping(path = "/getName")
   public String getName(@RequestParam(name = "name") String name) {
-    ((Invocation) ContextUtils.getInvocationContext()).getTraceIdLogger().info(LOGGER, "get name invoked.");
+    ((Invocation) ContextUtils.getInvocationContext()).getTraceIdLogger().info("get name invoked.");
     return name;
   }
 }
diff --git a/demo/demo-multi-service-center/demo-multi-service-center-serverA/src/main/java/org/apache/servicecomb/demo/multiServiceCenter/ServerEndpoint.java b/demo/demo-multi-service-center/demo-multi-service-center-serverA/src/main/java/org/apache/servicecomb/demo/multiServiceCenter/ServerEndpoint.java
index d789dab7c..16fdb41bd 100644
--- a/demo/demo-multi-service-center/demo-multi-service-center-serverA/src/main/java/org/apache/servicecomb/demo/multiServiceCenter/ServerEndpoint.java
+++ b/demo/demo-multi-service-center/demo-multi-service-center-serverA/src/main/java/org/apache/servicecomb/demo/multiServiceCenter/ServerEndpoint.java
@@ -17,26 +17,21 @@
 
 package org.apache.servicecomb.demo.multiServiceCenter;
 
-import jakarta.ws.rs.core.MediaType;
-
 import org.apache.servicecomb.core.Invocation;
 import org.apache.servicecomb.provider.rest.common.RestSchema;
 import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import jakarta.ws.rs.core.MediaType;
+
 @RestSchema(schemaId = "ServerEndpoint")
 @RequestMapping(path = "/register/url/prefix", produces = MediaType.APPLICATION_JSON)
 public class ServerEndpoint {
-  private static final Logger LOGGER
-      = LoggerFactory.getLogger(ServerEndpoint.class);
-
   @GetMapping(path = "/getName")
   public String getName(@RequestParam(name = "name") String name) {
-    ((Invocation) ContextUtils.getInvocationContext()).getTraceIdLogger().info(LOGGER, "get name invoked.");
+    ((Invocation) ContextUtils.getInvocationContext()).getTraceIdLogger().info("get name invoked.");
     return name;
   }
 }
diff --git a/demo/demo-multi-service-center/demo-multi-service-center-serverB/src/main/java/org/apache/servicecomb/demo/multiServiceCenterServerB/ServerEndpoint.java b/demo/demo-multi-service-center/demo-multi-service-center-serverB/src/main/java/org/apache/servicecomb/demo/multiServiceCenterServerB/ServerEndpoint.java
index 3822ffd5f..d14c1d4a7 100644
--- a/demo/demo-multi-service-center/demo-multi-service-center-serverB/src/main/java/org/apache/servicecomb/demo/multiServiceCenterServerB/ServerEndpoint.java
+++ b/demo/demo-multi-service-center/demo-multi-service-center-serverB/src/main/java/org/apache/servicecomb/demo/multiServiceCenterServerB/ServerEndpoint.java
@@ -17,26 +17,21 @@
 
 package org.apache.servicecomb.demo.multiServiceCenterServerB;
 
-import jakarta.ws.rs.core.MediaType;
-
 import org.apache.servicecomb.core.Invocation;
 import org.apache.servicecomb.provider.rest.common.RestSchema;
 import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import jakarta.ws.rs.core.MediaType;
+
 @RestSchema(schemaId = "ServerEndpoint")
 @RequestMapping(path = "/register/url/prefix", produces = MediaType.APPLICATION_JSON)
 public class ServerEndpoint {
-  private static final Logger LOGGER
-      = LoggerFactory.getLogger(ServerEndpoint.class);
-
   @GetMapping(path = "/getName")
   public String getName(@RequestParam(name = "name") String name) {
-    ((Invocation) ContextUtils.getInvocationContext()).getTraceIdLogger().info(LOGGER, "get name invoked.");
+    ((Invocation) ContextUtils.getInvocationContext()).getTraceIdLogger().info("get name invoked.");
     return name;
   }
 }
diff --git a/demo/demo-register-url-prefix/demo-register-url-prefix-server/src/main/java/org/apache/servicecomb/demo/prefix/RegisterUrlPrefixEndpoint.java b/demo/demo-register-url-prefix/demo-register-url-prefix-server/src/main/java/org/apache/servicecomb/demo/prefix/RegisterUrlPrefixEndpoint.java
index 86b1d4002..dae91a50f 100644
--- a/demo/demo-register-url-prefix/demo-register-url-prefix-server/src/main/java/org/apache/servicecomb/demo/prefix/RegisterUrlPrefixEndpoint.java
+++ b/demo/demo-register-url-prefix/demo-register-url-prefix-server/src/main/java/org/apache/servicecomb/demo/prefix/RegisterUrlPrefixEndpoint.java
@@ -17,26 +17,21 @@
 
 package org.apache.servicecomb.demo.prefix;
 
-import jakarta.ws.rs.core.MediaType;
-
 import org.apache.servicecomb.core.Invocation;
 import org.apache.servicecomb.provider.rest.common.RestSchema;
 import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import jakarta.ws.rs.core.MediaType;
+
 @RestSchema(schemaId = "RegisterUrlPrefixEndpoint")
 @RequestMapping(path = "/register/url/prefix", produces = MediaType.APPLICATION_JSON)
 public class RegisterUrlPrefixEndpoint {
-  private static final Logger LOGGER
-      = LoggerFactory.getLogger(RegisterUrlPrefixEndpoint.class);
-
   @GetMapping(path = "/getName")
   public String getName(@RequestParam(name = "name") String name) {
-    ((Invocation) ContextUtils.getInvocationContext()).getTraceIdLogger().info(LOGGER, "get name invoked.");
+    ((Invocation) ContextUtils.getInvocationContext()).getTraceIdLogger().info("get name invoked.");
     return name;
   }
 }
diff --git a/demo/demo-zeroconfig-registry/demo-zeroconfig-registry-edge/src/main/java/org/apache/servicecomb/demo/zeroconfig/edge/ServerEndpoint.java b/demo/demo-zeroconfig-registry/demo-zeroconfig-registry-edge/src/main/java/org/apache/servicecomb/demo/zeroconfig/edge/ServerEndpoint.java
index 8b57fc652..71f259366 100644
--- a/demo/demo-zeroconfig-registry/demo-zeroconfig-registry-edge/src/main/java/org/apache/servicecomb/demo/zeroconfig/edge/ServerEndpoint.java
+++ b/demo/demo-zeroconfig-registry/demo-zeroconfig-registry-edge/src/main/java/org/apache/servicecomb/demo/zeroconfig/edge/ServerEndpoint.java
@@ -17,25 +17,21 @@
 
 package org.apache.servicecomb.demo.zeroconfig.edge;
 
-import jakarta.ws.rs.core.MediaType;
 import org.apache.servicecomb.core.Invocation;
 import org.apache.servicecomb.provider.rest.common.RestSchema;
 import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import jakarta.ws.rs.core.MediaType;
+
 @RestSchema(schemaId = "ServerEndpoint")
 @RequestMapping(path = "/edge/prefix", produces = MediaType.APPLICATION_JSON)
 public class ServerEndpoint {
-  private static final Logger LOGGER
-      = LoggerFactory.getLogger(ServerEndpoint.class);
-
   @GetMapping(path = "/getName")
   public String getName(@RequestParam(name = "name") String name) {
-    ((Invocation) ContextUtils.getInvocationContext()).getTraceIdLogger().info(LOGGER, "get name invoked.");
+    ((Invocation) ContextUtils.getInvocationContext()).getTraceIdLogger().info("get name invoked.");
     return name;
   }
 }
diff --git a/demo/demo-zeroconfig-registry/demo-zeroconfig-registry-server/src/main/java/org/apache/servicecomb/demo/zeroconfig/server/ServerEndpoint.java b/demo/demo-zeroconfig-registry/demo-zeroconfig-registry-server/src/main/java/org/apache/servicecomb/demo/zeroconfig/server/ServerEndpoint.java
index f13ef2645..b0dd4ef5d 100644
--- a/demo/demo-zeroconfig-registry/demo-zeroconfig-registry-server/src/main/java/org/apache/servicecomb/demo/zeroconfig/server/ServerEndpoint.java
+++ b/demo/demo-zeroconfig-registry/demo-zeroconfig-registry-server/src/main/java/org/apache/servicecomb/demo/zeroconfig/server/ServerEndpoint.java
@@ -17,25 +17,21 @@
 
 package org.apache.servicecomb.demo.zeroconfig.server;
 
-import jakarta.ws.rs.core.MediaType;
 import org.apache.servicecomb.core.Invocation;
 import org.apache.servicecomb.provider.rest.common.RestSchema;
 import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import jakarta.ws.rs.core.MediaType;
+
 @RestSchema(schemaId = "ServerEndpoint")
 @RequestMapping(path = "/register/url/prefix", produces = MediaType.APPLICATION_JSON)
 public class ServerEndpoint {
-  private static final Logger LOGGER
-      = LoggerFactory.getLogger(ServerEndpoint.class);
-
   @GetMapping(path = "/getName")
   public String getName(@RequestParam(name = "name") String name) {
-    ((Invocation) ContextUtils.getInvocationContext()).getTraceIdLogger().info(LOGGER, "get name invoked.");
+    ((Invocation) ContextUtils.getInvocationContext()).getTraceIdLogger().info("get name invoked.");
     return name;
   }
 }
diff --git a/solutions/solution-basic/src/main/resources/microservice.yaml b/solutions/solution-basic/src/main/resources/microservice.yaml
index dbfa47b21..cead07182 100644
--- a/solutions/solution-basic/src/main/resources/microservice.yaml
+++ b/solutions/solution-basic/src/main/resources/microservice.yaml
@@ -23,7 +23,7 @@ servicecomb:
 # metrics and access log
   accesslog:
     enabled: true
-    pattern: "|%h|%r|%s|%D"
+    pattern: "|%SCB-traceId|%h|%r|%s|%D"
 
   metrics:
     window_time: 300000