Merge branch 'refs/heads/hotfix/improve-batch-operation' into feature/starter
# Conflicts: # workflow-engine-api/src/main/java/cn/axzo/workflow/client/config/WorkflowRequestInterceptor.java
This commit is contained in:
commit
6922a2d9d3
@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -199,8 +200,8 @@ public class WorkflowEngineClientAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RequestInterceptor workflowRequestInterceptor(String serviceVersion) {
|
||||
return new WorkflowRequestInterceptor(serviceVersion);
|
||||
public RequestInterceptor workflowRequestInterceptor(String serviceVersion, Environment environment) {
|
||||
return new WorkflowRequestInterceptor(serviceVersion, environment);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ package cn.axzo.workflow.client.config;
|
||||
import feign.RequestInterceptor;
|
||||
import feign.RequestTemplate;
|
||||
import feign.Target;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* 通用的 Feign 请求拦截器
|
||||
@ -12,12 +12,12 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
* @since 2024/2/4 15:33
|
||||
*/
|
||||
public class WorkflowRequestInterceptor implements RequestInterceptor {
|
||||
@Value("${spring.application.name}")
|
||||
private String applicationName;
|
||||
private final String serviceVersion;
|
||||
private final Environment environment;
|
||||
|
||||
public WorkflowRequestInterceptor(String serviceVersion) {
|
||||
public WorkflowRequestInterceptor(String serviceVersion, Environment environment) {
|
||||
this.serviceVersion = serviceVersion;
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
public static final String HEADER_HTTP_CLIENT = "Http-Client";
|
||||
@ -34,7 +34,7 @@ public class WorkflowRequestInterceptor implements RequestInterceptor {
|
||||
|| apiClassPath.contains("cn.axzo.workflow.client.feign.manage")) {
|
||||
requestTemplate.header(HEADER_HTTP_CLIENT, HEADER_HTTP_CLIENT_VALUE);
|
||||
requestTemplate.header(HEADER_API_VERSION, serviceVersion);
|
||||
requestTemplate.header(HEADER_SERVER_NAME, applicationName);
|
||||
requestTemplate.header(HEADER_SERVER_NAME, environment.getProperty("spring.application.name"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,15 +13,20 @@ import org.springframework.context.ApplicationEvent;
|
||||
public class ApiLogEvent extends ApplicationEvent {
|
||||
private String traceId;
|
||||
private String apiUrl;
|
||||
private String requestApplicationName;
|
||||
private String clientVersion;
|
||||
private Object requestBody;
|
||||
private Object responseBody;
|
||||
private Double takeTime;
|
||||
private String type;
|
||||
|
||||
public ApiLogEvent(String traceId, String apiUrl, Object requestBody, Object responseBody, Double takeTime, String type) {
|
||||
public ApiLogEvent(String traceId, String apiUrl, String requestApplicationName, String clientVersion,
|
||||
Object requestBody, Object responseBody, Double takeTime, String type) {
|
||||
super(apiUrl);
|
||||
this.traceId = traceId;
|
||||
this.apiUrl = apiUrl;
|
||||
this.requestApplicationName = requestApplicationName;
|
||||
this.clientVersion = clientVersion;
|
||||
this.requestBody = requestBody;
|
||||
this.responseBody = responseBody;
|
||||
this.takeTime = takeTime;
|
||||
@ -40,6 +45,14 @@ public class ApiLogEvent extends ApplicationEvent {
|
||||
return apiUrl;
|
||||
}
|
||||
|
||||
public String getRequestApplicationName() {
|
||||
return requestApplicationName;
|
||||
}
|
||||
|
||||
public String getClientVersion() {
|
||||
return clientVersion;
|
||||
}
|
||||
|
||||
public Object getRequestBody() {
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
@ -28,6 +28,16 @@ public class ExtAxApiLog extends BaseEntity<ExtAxApiLog> {
|
||||
*/
|
||||
private String apiUrl;
|
||||
|
||||
/**
|
||||
* 请求方服务名称
|
||||
*/
|
||||
private String requestApplicationName;
|
||||
|
||||
/**
|
||||
* 客户端 API 版本
|
||||
*/
|
||||
private String clientVersion;
|
||||
|
||||
/**
|
||||
* 请求参数
|
||||
*/
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
alter table ext_ax_api_log
|
||||
modify request_body longblob null comment '请求参数';
|
||||
|
||||
alter table ext_ax_api_log
|
||||
add request_application_name varchar(20) default '' null comment '请求方服务名称' after type;
|
||||
|
||||
alter table ext_ax_api_log
|
||||
add client_version varchar(20) default '' null comment '客户端 API 版本' after request_application_name;
|
||||
|
||||
@ -21,12 +21,17 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StopWatch;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cn.axzo.workflow.client.config.WorkflowRequestInterceptor.HEADER_API_VERSION;
|
||||
import static cn.axzo.workflow.client.config.WorkflowRequestInterceptor.HEADER_SERVER_NAME;
|
||||
import static cn.azxo.framework.common.constatns.Constants.CTX_LOG_ID_MDC;
|
||||
|
||||
/**
|
||||
@ -79,6 +84,8 @@ public class ErrorReportAspect implements Ordered {
|
||||
String type = getType(joinPoint);
|
||||
ApiLogEvent event = new ApiLogEvent(MDC.get(CTX_LOG_ID_MDC),
|
||||
signature.toShortString(),
|
||||
Objects.isNull(getOriginRequest()) ? "" : getOriginRequest().getHeader(HEADER_SERVER_NAME),
|
||||
Objects.isNull(getOriginRequest()) ? "" : getOriginRequest().getHeader(HEADER_API_VERSION),
|
||||
Objects.equals(type, "Controller") ? joinPoint.getArgs() : null,
|
||||
Objects.equals(type, "Controller") ? result : null,
|
||||
watch.getTotalTimeSeconds(),
|
||||
@ -134,4 +141,13 @@ public class ErrorReportAspect implements Ordered {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private HttpServletRequest getOriginRequest() {
|
||||
try {
|
||||
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
return Objects.requireNonNull(requestAttributes).getRequest();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user