dubbo traceID 完成
This commit is contained in:
parent
318ab208be
commit
dcf5b53bd5
|
|
@ -3,9 +3,9 @@
|
||||||
<contextName>account-server</contextName>
|
<contextName>account-server</contextName>
|
||||||
<property name="log.charset" value="utf-8" />
|
<property name="log.charset" value="utf-8" />
|
||||||
<property name="log.pattern"
|
<property name="log.pattern"
|
||||||
value="%yellow(%d{yyyy-MM-dd HH:mm:ss.SSS}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) %X{traceId} [traceId=%X{traceId:-}, spanId=%X{spanId:-}] - %msg%n" />
|
value="%yellow(%d{yyyy-MM-dd HH:mm:ss.SSS}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) [traceId=%X{traceId:-}] - %msg%n" />
|
||||||
<!--写入文件格式-->
|
<!--写入文件格式-->
|
||||||
<property name="p_file" value="%d | %X{traceId} [traceId=%X{traceId:-}] | [%thread] %-5level %c [%L] - %msg %n "/>
|
<property name="p_file" value="%d |[traceId=%X{traceId:-}] | [%thread] %-5level %c [%L] - %msg %n "/>
|
||||||
<!--输出到控制台-->
|
<!--输出到控制台-->
|
||||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
<encoder>
|
<encoder>
|
||||||
|
|
|
||||||
|
|
@ -31,5 +31,8 @@ pagehelper:
|
||||||
support-methods-arguments: true
|
support-methods-arguments: true
|
||||||
|
|
||||||
dubbo:
|
dubbo:
|
||||||
|
provider:
|
||||||
|
filter: traceProviderFilter
|
||||||
consumer:
|
consumer:
|
||||||
|
filter: traceConsumerFilter
|
||||||
check: false
|
check: false
|
||||||
|
|
@ -3,9 +3,9 @@
|
||||||
<contextName>market-server</contextName>
|
<contextName>market-server</contextName>
|
||||||
<property name="log.charset" value="utf-8" />
|
<property name="log.charset" value="utf-8" />
|
||||||
<property name="log.pattern"
|
<property name="log.pattern"
|
||||||
value="%yellow(%d{yyyy-MM-dd HH:mm:ss.SSS}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) [traceId=%X{traceId:-}, spanId=%X{spanId:-}] - %msg%n" />
|
value="%yellow(%d{yyyy-MM-dd HH:mm:ss.SSS}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) [traceId=%X{traceId:-}] - %msg%n" />
|
||||||
<!--写入文件格式-->
|
<!--写入文件格式-->
|
||||||
<property name="p_file" value="%d | [traceId=%X{traceId:-}] | [%thread] %-5level %c [%L] - %msg %n "/>
|
<property name="p_file" value="%d |[traceId=%X{traceId:-}] | [%thread] %-5level %c [%L] - %msg %n "/>
|
||||||
<!--输出到控制台-->
|
<!--输出到控制台-->
|
||||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
<encoder>
|
<encoder>
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,10 @@ pagehelper:
|
||||||
support-methods-arguments: true
|
support-methods-arguments: true
|
||||||
|
|
||||||
dubbo:
|
dubbo:
|
||||||
|
provider:
|
||||||
|
filter: traceProviderFilter
|
||||||
consumer:
|
consumer:
|
||||||
|
filter: traceConsumerFilter
|
||||||
check: false
|
check: false
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@
|
||||||
<contextName>order-server</contextName>
|
<contextName>order-server</contextName>
|
||||||
<property name="log.charset" value="utf-8" />
|
<property name="log.charset" value="utf-8" />
|
||||||
<property name="log.pattern"
|
<property name="log.pattern"
|
||||||
value="%yellow(%d{yyyy-MM-dd HH:mm:ss.SSS}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) [traceId=%X{traceId:-}, spanId=%X{spanId:-}] - %msg%n" />
|
value="%yellow(%d{yyyy-MM-dd HH:mm:ss.SSS}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) [traceId=%X{traceId:-}] - %msg%n" />
|
||||||
<!--写入文件格式-->
|
<!--写入文件格式-->
|
||||||
<property name="p_file" value="%d | [traceId=%X{traceId:-}] | [%thread] %-5level %c [%L] - %msg %n "/>
|
<property name="p_file" value="%d |[traceId=%X{traceId:-}] | [%thread] %-5level %c [%L] - %msg %n "/>
|
||||||
<!--输出到控制台-->
|
<!--输出到控制台-->
|
||||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
<encoder>
|
<encoder>
|
||||||
|
|
|
||||||
|
|
@ -36,5 +36,8 @@ pagehelper:
|
||||||
support-methods-arguments: true
|
support-methods-arguments: true
|
||||||
|
|
||||||
dubbo:
|
dubbo:
|
||||||
|
provider:
|
||||||
|
filter: traceProviderFilter
|
||||||
consumer:
|
consumer:
|
||||||
|
filter: traceConsumerFilter
|
||||||
check: false
|
check: false
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@
|
||||||
<contextName>product-server</contextName>
|
<contextName>product-server</contextName>
|
||||||
<property name="log.charset" value="utf-8" />
|
<property name="log.charset" value="utf-8" />
|
||||||
<property name="log.pattern"
|
<property name="log.pattern"
|
||||||
value="%yellow(%d{yyyy-MM-dd HH:mm:ss.SSS}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) [traceId=%X{traceId:-}, spanId=%X{spanId:-}] - %msg%n" />
|
value="%yellow(%d{yyyy-MM-dd HH:mm:ss.SSS}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) [traceId=%X{traceId:-}] - %msg%n" />
|
||||||
<!--写入文件格式-->
|
<!--写入文件格式-->
|
||||||
<property name="p_file" value="%d | [traceId=%X{traceId:-}] | [%thread] %-5level %c [%L] - %msg %n "/>
|
<property name="p_file" value="%d |[traceId=%X{traceId:-}] | [%thread] %-5level %c [%L] - %msg %n "/>
|
||||||
<!--输出到控制台-->
|
<!--输出到控制台-->
|
||||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
<encoder>
|
<encoder>
|
||||||
|
|
|
||||||
|
|
@ -20,3 +20,10 @@ alipay:
|
||||||
key: your-key
|
key: your-key
|
||||||
secret: your-secret
|
secret: your-secret
|
||||||
templateCode: c
|
templateCode: c
|
||||||
|
|
||||||
|
dubbo:
|
||||||
|
provider:
|
||||||
|
filter: traceProviderFilter
|
||||||
|
consumer:
|
||||||
|
filter: traceConsumerFilter
|
||||||
|
check: false
|
||||||
|
|
@ -2,11 +2,10 @@
|
||||||
<configuration scan="true" scanPeriod="30 seconds" debug="false">
|
<configuration scan="true" scanPeriod="30 seconds" debug="false">
|
||||||
<contextName>system-server</contextName>
|
<contextName>system-server</contextName>
|
||||||
<property name="log.charset" value="utf-8" />
|
<property name="log.charset" value="utf-8" />
|
||||||
<!-- <property name="log.pattern" value="%yellow(%d{yyyy-MM-dd HH:mm:ss.SSS}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) - %msg%n" />-->
|
|
||||||
<property name="log.pattern"
|
<property name="log.pattern"
|
||||||
value="%yellow(%d{yyyy-MM-dd HH:mm:ss.SSS}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) [traceId=%X{traceId:-}, spanId=%X{spanId:-}] - %msg%n" />
|
value="%yellow(%d{yyyy-MM-dd HH:mm:ss.SSS}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) [traceId=%X{traceId:-}] - %msg%n" />
|
||||||
<!--写入文件格式-->
|
<!--写入文件格式-->
|
||||||
<property name="p_file" value="%d | [traceId=%X{traceId:-}] | [%thread] %-5level %c [%L] - %msg %n "/>
|
<property name="p_file" value="%d |[traceId=%X{traceId:-}] | [%thread] %-5level %c [%L] - %msg %n "/>
|
||||||
<!--输出到控制台-->
|
<!--输出到控制台-->
|
||||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
<encoder>
|
<encoder>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.czg.config;
|
package com.czg.config;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.dubbo.common.Constants;
|
import org.apache.dubbo.common.constants.CommonConstants;
|
||||||
import org.apache.dubbo.common.extension.Activate;
|
import org.apache.dubbo.common.extension.Activate;
|
||||||
import org.apache.dubbo.rpc.*;
|
import org.apache.dubbo.rpc.*;
|
||||||
import org.slf4j.MDC;
|
import org.slf4j.MDC;
|
||||||
|
|
@ -10,7 +10,7 @@ import org.slf4j.MDC;
|
||||||
* @author ww
|
* @author ww
|
||||||
* @description
|
* @description
|
||||||
*/
|
*/
|
||||||
@Activate(group = Constants.CONSUMER)
|
@Activate(group = CommonConstants.CONSUMER)
|
||||||
public class TraceConsumerFilter implements Filter {
|
public class TraceConsumerFilter implements Filter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
package com.czg.config;
|
|
||||||
|
|
||||||
import org.slf4j.MDC;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ww
|
|
||||||
* @description
|
|
||||||
*/
|
|
||||||
public class TraceContext {
|
|
||||||
private static final String TRACE_ID = "traceId";
|
|
||||||
|
|
||||||
public static void setTraceId(String traceId) {
|
|
||||||
MDC.put(TRACE_ID, traceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getTraceId() {
|
|
||||||
return MDC.get(TRACE_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void clear() {
|
|
||||||
MDC.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String generateTraceId() {
|
|
||||||
return UUID.randomUUID().toString().replace("-", "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
package com.czg.config;
|
package com.czg.config;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import org.apache.dubbo.common.constants.CommonConstants;
|
||||||
import org.apache.dubbo.rpc.*;
|
import org.apache.dubbo.rpc.*;
|
||||||
|
|
||||||
import com.alibaba.dubbo.common.Constants;
|
|
||||||
import org.apache.dubbo.common.extension.Activate;
|
import org.apache.dubbo.common.extension.Activate;
|
||||||
import org.slf4j.MDC;
|
import org.slf4j.MDC;
|
||||||
|
|
||||||
|
|
@ -11,7 +10,7 @@ import org.slf4j.MDC;
|
||||||
* @author ww
|
* @author ww
|
||||||
* @description
|
* @description
|
||||||
*/
|
*/
|
||||||
@Activate(group = Constants.PROVIDER)
|
@Activate(group = CommonConstants.PROVIDER)
|
||||||
public class TraceProviderFilter implements Filter {
|
public class TraceProviderFilter implements Filter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue