Optimize default settings of trace id
This commit is contained in:
@@ -106,3 +106,8 @@ refresh-local-cache:
|
||||
fizz:
|
||||
aggregate:
|
||||
writeMapNullValue: false
|
||||
|
||||
fizz-trace-id:
|
||||
header: X-Trace-Id # default
|
||||
value-strategy: requestId # default, or can be uuid
|
||||
value-prefix: fizz # default
|
||||
|
||||
@@ -72,10 +72,10 @@ public class SystemConfig {
|
||||
@Value("${fizz-trace-id.header:X-Trace-Id}")
|
||||
private String fizzTraceIdHeader;
|
||||
|
||||
@Value("${fizz-trace-id.value-strategy:}")
|
||||
@Value("${fizz-trace-id.value-strategy:requestId}")
|
||||
private String fizzTraceIdValueStrategy;
|
||||
|
||||
@Value("${fizz-trace-id.value-prefix:}")
|
||||
@Value("${fizz-trace-id.value-prefix:fizz}")
|
||||
private String fizzTraceIdValuePrefix;
|
||||
|
||||
public String fizzTraceIdHeader() {
|
||||
|
||||
@@ -65,6 +65,8 @@ public class FlowControlFilter extends FizzWebFilter {
|
||||
|
||||
private static final String uuid = "uuid";
|
||||
|
||||
private static final String defaultFizzTraceIdValueStrategy = "requestId";
|
||||
|
||||
public static final String ADMIN_REQUEST = "$a";
|
||||
|
||||
@Resource
|
||||
@@ -166,16 +168,18 @@ public class FlowControlFilter extends FizzWebFilter {
|
||||
private void setTraceId(ServerWebExchange exchange) {
|
||||
String traceId = exchange.getRequest().getHeaders().getFirst(systemConfig.fizzTraceIdHeader());
|
||||
if (StringUtils.isBlank(traceId)) {
|
||||
if (StringUtils.isBlank(systemConfig.fizzTraceIdValueStrategy())) {
|
||||
String fizzTraceIdValueStrategy = systemConfig.fizzTraceIdValueStrategy();
|
||||
if (fizzTraceIdValueStrategy.equals(defaultFizzTraceIdValueStrategy)) {
|
||||
traceId = exchange.getRequest().getId();
|
||||
} else if (systemConfig.fizzTraceIdValueStrategy().equals(uuid)) {
|
||||
} else if (fizzTraceIdValueStrategy.equals(uuid)) {
|
||||
traceId = UUIDUtil.getUUID();
|
||||
} else {
|
||||
throw Utils.runtimeExceptionWithoutStack("unsupported " + systemConfig.fizzTraceIdValueStrategy() + " trace id value strategy!");
|
||||
throw Utils.runtimeExceptionWithoutStack("unsupported " + fizzTraceIdValueStrategy + " trace id value strategy!");
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(systemConfig.fizzTraceIdValuePrefix())) {
|
||||
traceId = systemConfig.fizzTraceIdValuePrefix() + traceId;
|
||||
String fizzTraceIdValuePrefix = systemConfig.fizzTraceIdValuePrefix();
|
||||
if (StringUtils.isNotBlank(fizzTraceIdValuePrefix)) {
|
||||
traceId = fizzTraceIdValuePrefix + Constants.Symbol.DASH + traceId;
|
||||
}
|
||||
exchange.getAttributes().put(WebUtils.TRACE_ID, traceId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user