diff --git a/blibli-backend-framework-api-client/pom.xml b/blibli-backend-framework-api-client/pom.xml
index c6fe6b7..f8739ee 100644
--- a/blibli-backend-framework-api-client/pom.xml
+++ b/blibli-backend-framework-api-client/pom.xml
@@ -21,6 +21,10 @@
blibli-backend-framework-sleuth
provided
+
+ org.springframework.cloud
+ spring-cloud-sleuth-zipkin
+
org.springframework
spring-web
diff --git a/blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/sleuth/ApiClientSleuthConfiguration.java b/blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/sleuth/ApiClientSleuthConfiguration.java
deleted file mode 100644
index 9990615..0000000
--- a/blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/sleuth/ApiClientSleuthConfiguration.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.blibli.oss.backend.apiclient.sleuth;
-
-import brave.Tracer;
-import com.blibli.oss.backend.apiclient.configuration.ApiClientConfiguration;
-import com.blibli.oss.backend.apiclient.properties.ApiClientProperties;
-import com.blibli.oss.backend.sleuth.configuration.SleuthConfiguration;
-import org.springframework.boot.autoconfigure.AutoConfigureAfter;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-@ConditionalOnClass({SleuthConfiguration.class})
-@AutoConfigureAfter({SleuthConfiguration.class, ApiClientConfiguration.class})
-public class ApiClientSleuthConfiguration {
-
- @Bean
- public SleuthGlobalApiClientInterceptor sleuthGlobalApiClientInterceptor(ApiClientProperties properties,
- Tracer tracer) {
- return new SleuthGlobalApiClientInterceptor(properties, tracer);
- }
-
-}
diff --git a/blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/sleuth/SleuthGlobalApiClientInterceptor.java b/blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/sleuth/SleuthGlobalApiClientInterceptor.java
deleted file mode 100644
index c1cd239..0000000
--- a/blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/sleuth/SleuthGlobalApiClientInterceptor.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.blibli.oss.backend.apiclient.sleuth;
-
-import brave.Tracer;
-import brave.propagation.ExtraFieldPropagation;
-import com.blibli.oss.backend.apiclient.interceptor.GlobalApiClientInterceptor;
-import com.blibli.oss.backend.apiclient.properties.ApiClientProperties;
-import com.blibli.oss.backend.sleuth.configuration.SleuthConfiguration;
-import lombok.AllArgsConstructor;
-import org.springframework.web.reactive.function.client.ClientRequest;
-import org.springframework.web.reactive.function.client.ClientResponse;
-import org.springframework.web.reactive.function.client.ExchangeFunction;
-import reactor.core.publisher.Mono;
-
-@AllArgsConstructor
-public class SleuthGlobalApiClientInterceptor implements GlobalApiClientInterceptor {
-
- private ApiClientProperties properties;
-
- private Tracer tracer;
-
- @Override
- public Mono filter(ClientRequest request, ExchangeFunction next) {
- if (properties.getSleuth().isEnabled() && tracer.currentSpan() != null) {
- return Mono.fromCallable(() -> {
- ClientRequest.Builder builder = ClientRequest.from(request);
- ExtraFieldPropagation.getAll(tracer.currentSpan().context()).forEach((key, value) -> {
- builder.header(SleuthConfiguration.HTTP_BAGGAGE_PREFIX + key, value);
- });
- return builder.build();
- }).flatMap(next::exchange);
- } else {
- return next.exchange(request);
- }
- }
-}
diff --git a/blibli-backend-framework-api-client/src/main/resources/META-INF/spring.factories b/blibli-backend-framework-api-client/src/main/resources/META-INF/spring.factories
index f237ee3..cfec83e 100644
--- a/blibli-backend-framework-api-client/src/main/resources/META-INF/spring.factories
+++ b/blibli-backend-framework-api-client/src/main/resources/META-INF/spring.factories
@@ -1,4 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.blibli.oss.backend.apiclient.configuration.ApiClientConfiguration,\
-com.blibli.oss.backend.apiclient.configuration.ApiClientRegistrar,\
-com.blibli.oss.backend.apiclient.sleuth.ApiClientSleuthConfiguration
\ No newline at end of file
+com.blibli.oss.backend.apiclient.configuration.ApiClientRegistrar
\ No newline at end of file
diff --git a/blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/controller/SleuthController.java b/blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/controller/SleuthController.java
index b236b9c..c10b025 100644
--- a/blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/controller/SleuthController.java
+++ b/blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/controller/SleuthController.java
@@ -1,7 +1,7 @@
package com.blibli.oss.backend.apiclient.controller;
import brave.Tracer;
-import brave.propagation.ExtraFieldPropagation;
+import brave.baggage.BaggageField;
import com.blibli.oss.backend.apiclient.client.SleuthApiClient;
import com.blibli.oss.backend.apiclient.client.model.GenericResponse;
import com.blibli.oss.backend.sleuth.configuration.SleuthConfiguration;
@@ -33,8 +33,8 @@ public class SleuthController {
)
public Mono
+
+ com.fasterxml.jackson.core
+ jackson-databind
+
org.springframework.boot
spring-boot-configuration-processor
diff --git a/blibli-backend-framework-kafka/src/main/java/com/blibli/oss/backend/kafka/listener/KafkaListenerBeanProcessor.java b/blibli-backend-framework-kafka/src/main/java/com/blibli/oss/backend/kafka/listener/KafkaListenerBeanProcessor.java
index d47f697..dcad8f0 100644
--- a/blibli-backend-framework-kafka/src/main/java/com/blibli/oss/backend/kafka/listener/KafkaListenerBeanProcessor.java
+++ b/blibli-backend-framework-kafka/src/main/java/com/blibli/oss/backend/kafka/listener/KafkaListenerBeanProcessor.java
@@ -4,6 +4,7 @@
import org.springframework.aop.support.AopUtils;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.annotation.KafkaListenerAnnotationBeanPostProcessor;
+import org.springframework.kafka.support.TopicPartitionOffset;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Method;
@@ -15,7 +16,9 @@ protected void processKafkaListener(KafkaListener kafkaListener, Method method,
Method methodToUse = checkProxy(method, bean);
KafkaListenerEndpoint endpoint = new KafkaListenerEndpoint();
endpoint.setMethod(methodToUse);
- processListener(endpoint, kafkaListener, bean, methodToUse, beanName);
+ String[] topics = {};
+ TopicPartitionOffset[] tps = {};
+ processListener(endpoint, kafkaListener, bean, beanName, topics, tps);
}
private Method checkProxy(Method methodArg, Object bean) {
diff --git a/blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/helper/MandatoryParameterHelper.java b/blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/helper/MandatoryParameterHelper.java
index c0a2564..98ff732 100644
--- a/blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/helper/MandatoryParameterHelper.java
+++ b/blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/helper/MandatoryParameterHelper.java
@@ -1,6 +1,6 @@
package com.blibli.oss.backend.mandatoryparameter.helper;
-import brave.propagation.ExtraFieldPropagation;
+import brave.baggage.BaggageField;
import brave.propagation.TraceContext;
import com.blibli.oss.backend.mandatoryparameter.model.MandatoryParameter;
import com.blibli.oss.backend.mandatoryparameter.sleuth.MandatoryParameterSleuth;
@@ -18,11 +18,11 @@ public static MandatoryParameter toSleuth(TraceContext traceContext, MandatoryPa
public static MandatoryParameter fromSleuth(TraceContext traceContext) {
return MandatoryParameter.builder()
- .storeId(ExtraFieldPropagation.get(traceContext, MandatoryParameterSleuth.STORE_ID))
- .clientId(ExtraFieldPropagation.get(traceContext, MandatoryParameterSleuth.CLIENT_ID))
- .channelId(ExtraFieldPropagation.get(traceContext, MandatoryParameterSleuth.CHANNEL_ID))
- .requestId(ExtraFieldPropagation.get(traceContext, MandatoryParameterSleuth.REQUEST_ID))
- .username(ExtraFieldPropagation.get(traceContext, MandatoryParameterSleuth.USERNAME))
+ .storeId(BaggageField.getByName(traceContext, MandatoryParameterSleuth.STORE_ID).getValue(traceContext))
+ .clientId(BaggageField.getByName(traceContext, MandatoryParameterSleuth.CLIENT_ID).getValue(traceContext))
+ .channelId(BaggageField.getByName(traceContext, MandatoryParameterSleuth.CHANNEL_ID).getValue(traceContext))
+ .requestId(BaggageField.getByName(traceContext, MandatoryParameterSleuth.REQUEST_ID).getValue(traceContext))
+ .username(BaggageField.getByName(traceContext, MandatoryParameterSleuth.USERNAME).getValue(traceContext))
.build();
}
diff --git a/blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/helper/SleuthHelper.java b/blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/helper/SleuthHelper.java
index 7a9c9a1..4509fba 100644
--- a/blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/helper/SleuthHelper.java
+++ b/blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/helper/SleuthHelper.java
@@ -1,14 +1,14 @@
package com.blibli.oss.backend.mandatoryparameter.helper;
-import brave.propagation.ExtraFieldPropagation;
+import brave.baggage.BaggageField;
import brave.propagation.TraceContext;
import org.springframework.util.StringUtils;
public class SleuthHelper {
public static void putExtraField(TraceContext traceContext, String name, String value) {
- if (!StringUtils.isEmpty(value)) {
- ExtraFieldPropagation.set(traceContext, name, value);
+ if (StringUtils.hasText(value)) {
+ BaggageField.getByName(traceContext, name).updateValue(traceContext, value);
}
}
diff --git a/blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/sleuth/MandatoryParameterSleuthAutoConfiguration.java b/blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/sleuth/MandatoryParameterSleuthAutoConfiguration.java
index d71aa3b..9828048 100644
--- a/blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/sleuth/MandatoryParameterSleuthAutoConfiguration.java
+++ b/blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/sleuth/MandatoryParameterSleuthAutoConfiguration.java
@@ -1,11 +1,11 @@
package com.blibli.oss.backend.mandatoryparameter.sleuth;
-import brave.Tracer;
import com.blibli.oss.backend.mandatoryparameter.swagger.properties.MandatoryParameterProperties;
import com.blibli.oss.backend.sleuth.configuration.SleuthConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
+import org.springframework.cloud.sleuth.Tracer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.config.WebFluxConfigurer;
diff --git a/blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/sleuth/MandatoryParameterSleuthWebFilter.java b/blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/sleuth/MandatoryParameterSleuthWebFilter.java
index 5a7abb7..54a5cf0 100644
--- a/blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/sleuth/MandatoryParameterSleuthWebFilter.java
+++ b/blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/sleuth/MandatoryParameterSleuthWebFilter.java
@@ -1,14 +1,13 @@
package com.blibli.oss.backend.mandatoryparameter.sleuth;
-import brave.Span;
-import brave.Tracer;
-import brave.propagation.TraceContext;
import com.blibli.oss.backend.mandatoryparameter.helper.ServerHelper;
-import com.blibli.oss.backend.mandatoryparameter.helper.SleuthHelper;
import com.blibli.oss.backend.mandatoryparameter.swagger.properties.MandatoryParameterProperties;
import com.blibli.oss.backend.sleuth.webflux.SleuthWebFilter;
import lombok.AllArgsConstructor;
import lombok.Getter;
+import org.springframework.cloud.sleuth.Span;
+import org.springframework.cloud.sleuth.TraceContext;
+import org.springframework.cloud.sleuth.Tracer;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;
@@ -28,12 +27,11 @@ public Mono filter(ServerWebExchange exchange, WebFilterChain chain, Span
}
private ServerWebExchange putMandatoryParameterToSleuth(TraceContext traceContext, ServerWebExchange exchange) {
- SleuthHelper.putExtraField(traceContext, MandatoryParameterSleuth.STORE_ID, ServerHelper.getValueFromQueryOrHeader(exchange, properties.getHeaderKey().getStoreId(), properties.getQueryKey().getStoreId()));
- SleuthHelper.putExtraField(traceContext, MandatoryParameterSleuth.CLIENT_ID, ServerHelper.getValueFromQueryOrHeader(exchange, properties.getHeaderKey().getClientId(), properties.getQueryKey().getClientId()));
- SleuthHelper.putExtraField(traceContext, MandatoryParameterSleuth.CHANNEL_ID, ServerHelper.getValueFromQueryOrHeader(exchange, properties.getHeaderKey().getChannelId(), properties.getQueryKey().getChannelId()));
- SleuthHelper.putExtraField(traceContext, MandatoryParameterSleuth.REQUEST_ID, ServerHelper.getValueFromQueryOrHeader(exchange, properties.getHeaderKey().getRequestId(), properties.getQueryKey().getRequestId()));
- SleuthHelper.putExtraField(traceContext, MandatoryParameterSleuth.USERNAME, ServerHelper.getValueFromQueryOrHeader(exchange, properties.getHeaderKey().getUsername(), properties.getQueryKey().getUsername()));
+ tracer.createBaggage(MandatoryParameterSleuth.STORE_ID).set(traceContext, ServerHelper.getValueFromQueryOrHeader(exchange, properties.getHeaderKey().getStoreId(), properties.getQueryKey().getStoreId()));
+ tracer.createBaggage(MandatoryParameterSleuth.CLIENT_ID).set(traceContext, ServerHelper.getValueFromQueryOrHeader(exchange, properties.getHeaderKey().getClientId(), properties.getQueryKey().getClientId()));
+ tracer.createBaggage(MandatoryParameterSleuth.CHANNEL_ID).set(traceContext, ServerHelper.getValueFromQueryOrHeader(exchange, properties.getHeaderKey().getChannelId(), properties.getQueryKey().getChannelId()));
+ tracer.createBaggage(MandatoryParameterSleuth.REQUEST_ID).set(traceContext, ServerHelper.getValueFromQueryOrHeader(exchange, properties.getHeaderKey().getRequestId(), properties.getQueryKey().getRequestId()));
+ tracer.createBaggage(MandatoryParameterSleuth.USERNAME).set(traceContext, ServerHelper.getValueFromQueryOrHeader(exchange, properties.getHeaderKey().getUsername(), properties.getQueryKey().getUsername()));
return exchange;
}
-
}
diff --git a/blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/MandatoryParameterTest.java b/blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/MandatoryParameterTest.java
index 447fcd5..fde1130 100644
--- a/blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/MandatoryParameterTest.java
+++ b/blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/MandatoryParameterTest.java
@@ -1,24 +1,17 @@
package com.blibli.oss.backend.mandatoryparameter;
-import com.blibli.oss.backend.mandatoryparameter.model.MandatoryParameter;
-import com.blibli.oss.backend.mandatoryparameter.swagger.annotation.MandatoryParameterAtHeader;
-import com.blibli.oss.backend.mandatoryparameter.swagger.annotation.MandatoryParameterAtQuery;
import com.blibli.oss.backend.mandatoryparameter.swagger.properties.MandatoryParameterProperties;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.reactive.server.WebTestClient;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RestController;
-import reactor.core.publisher.Mono;
@ExtendWith(SpringExtension.class)
@SpringBootTest(
- classes = MandatoryParameterTest.Application.class,
+ classes = TestApplication.class,
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)
public class MandatoryParameterTest {
@@ -95,30 +88,4 @@ void testMandatoryParameterSwagger() {
.jsonPath("$.paths./header.get.parameters[*]name").value(Matchers.contains("storeId", "channelId", "clientId", "username", "requestId"));
}
- @SpringBootApplication
- public static class Application {
-
- @MandatoryParameterAtQuery
- @RestController
- public static class QueryController {
-
- @GetMapping("/query")
- public Mono query(MandatoryParameter parameter) {
- return Mono.just(parameter);
- }
-
- }
-
- @MandatoryParameterAtHeader
- @RestController
- public static class HeaderController {
-
- @GetMapping("/header")
- public Mono header(MandatoryParameter parameter) {
- return Mono.just(parameter);
- }
-
- }
-
- }
}
diff --git a/blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/TestApplication.java b/blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/TestApplication.java
new file mode 100644
index 0000000..3b513d3
--- /dev/null
+++ b/blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/TestApplication.java
@@ -0,0 +1,140 @@
+package com.blibli.oss.backend.mandatoryparameter;
+
+import brave.Tracer;
+import com.blibli.oss.backend.mandatoryparameter.apiclient.apiclient.FirstApiClient;
+import com.blibli.oss.backend.mandatoryparameter.apiclient.apiclient.SecondApiClient;
+import com.blibli.oss.backend.mandatoryparameter.helper.MandatoryParameterHelper;
+import com.blibli.oss.backend.mandatoryparameter.model.MandatoryParameter;
+import com.blibli.oss.backend.mandatoryparameter.swagger.annotation.MandatoryParameterAtHeader;
+import com.blibli.oss.backend.mandatoryparameter.swagger.annotation.MandatoryParameterAtQuery;
+import com.blibli.oss.backend.mandatoryparameter.swagger.properties.MandatoryParameterProperties;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.stereotype.Service;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@SpringBootApplication
+public class TestApplication {
+
+ @MandatoryParameterAtQuery
+ @RestController
+ public static class QueryController {
+
+ @GetMapping("/query")
+ public Mono query(MandatoryParameter parameter) {
+ return Mono.just(parameter);
+ }
+
+ }
+
+ @MandatoryParameterAtHeader
+ @RestController
+ public static class HeaderController {
+
+ @GetMapping("/header")
+ public Mono header(MandatoryParameter parameter) {
+ return Mono.just(parameter);
+ }
+
+ }
+
+ @RestController
+ public static class SleuthController {
+
+ @Autowired
+ private SleuthService sleuthService;
+
+ @GetMapping(
+ value = "/sleuth",
+ produces = MediaType.APPLICATION_JSON_VALUE
+ )
+ public Mono mandatoryParameter(MandatoryParameter mandatoryParameter) {
+ return sleuthService.getMandatoryParameter();
+ }
+
+ }
+
+ @Service
+ public static class SleuthService {
+
+ @Autowired
+ private Tracer tracer;
+
+ public Mono getMandatoryParameter() {
+ return Mono.fromCallable(() -> MandatoryParameterHelper.fromSleuth(tracer.currentSpan().context()));
+ }
+
+ }
+
+ @RestController
+ @Slf4j
+ public static class ApiClientController {
+
+ @Autowired
+ private FirstApiClient firstApiClient;
+
+ @Autowired
+ private SecondApiClient secondApiClient;
+
+ @Autowired
+ private MandatoryParameterProperties properties;
+
+ @GetMapping(value = "/first", produces = MediaType.APPLICATION_JSON_VALUE)
+ public Mono> first(ServerWebExchange exchange) {
+ return Mono.fromCallable(() -> {
+ MultiValueMap queryParams = exchange.getRequest().getQueryParams();
+ Map map = new HashMap<>();
+ map.put(properties.getQueryKey().getStoreId(), queryParams.getFirst(properties.getQueryKey().getStoreId()));
+ map.put(properties.getQueryKey().getClientId(), queryParams.getFirst(properties.getQueryKey().getClientId()));
+ map.put(properties.getQueryKey().getChannelId(), queryParams.getFirst(properties.getQueryKey().getChannelId()));
+ map.put(properties.getQueryKey().getUsername(), queryParams.getFirst(properties.getQueryKey().getUsername()));
+ map.put(properties.getQueryKey().getRequestId(), queryParams.getFirst(properties.getQueryKey().getRequestId()));
+
+ log.info("Receive : " + exchange.getRequest().getQueryParams().toSingleValueMap().toString());
+
+ return map;
+ });
+ }
+
+ @GetMapping(value = "/second", produces = MediaType.APPLICATION_JSON_VALUE)
+ public Mono> second(ServerWebExchange exchange) {
+ return Mono.fromCallable(() -> {
+ HttpHeaders httpHeaders = exchange.getRequest().getHeaders();
+ Map map = new HashMap<>();
+ map.put(properties.getHeaderKey().getStoreId(), httpHeaders.getFirst(properties.getHeaderKey().getStoreId()));
+ map.put(properties.getHeaderKey().getClientId(), httpHeaders.getFirst(properties.getHeaderKey().getClientId()));
+ map.put(properties.getHeaderKey().getChannelId(), httpHeaders.getFirst(properties.getHeaderKey().getChannelId()));
+ map.put(properties.getHeaderKey().getUsername(), httpHeaders.getFirst(properties.getHeaderKey().getUsername()));
+ map.put(properties.getHeaderKey().getRequestId(), httpHeaders.getFirst(properties.getHeaderKey().getRequestId()));
+
+ log.info("Receive : " + exchange.getRequest().getQueryParams().toSingleValueMap().toString());
+
+ return map;
+ });
+ }
+
+ @GetMapping(value = "/test-first", produces = MediaType.APPLICATION_JSON_VALUE)
+ public Mono> testFirst(MandatoryParameter mandatoryParameter) {
+ log.info("Controller : " + mandatoryParameter);
+ return firstApiClient.first();
+ }
+
+ @GetMapping(value = "/test-second", produces = MediaType.APPLICATION_JSON_VALUE)
+ public Mono> testSecond(MandatoryParameter mandatoryParameter) {
+ log.info("Controller : " + mandatoryParameter);
+ return secondApiClient.second();
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/apiclient/MandatoryParameterApiClientTest.java b/blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/apiclient/MandatoryParameterApiClientTest.java
index 276ebba..a84f1bd 100644
--- a/blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/apiclient/MandatoryParameterApiClientTest.java
+++ b/blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/apiclient/MandatoryParameterApiClientTest.java
@@ -1,29 +1,17 @@
package com.blibli.oss.backend.mandatoryparameter.apiclient;
-import com.blibli.oss.backend.mandatoryparameter.apiclient.apiclient.FirstApiClient;
-import com.blibli.oss.backend.mandatoryparameter.apiclient.apiclient.SecondApiClient;
+import com.blibli.oss.backend.mandatoryparameter.TestApplication;
import com.blibli.oss.backend.mandatoryparameter.swagger.properties.MandatoryParameterProperties;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.MediaType;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.reactive.server.WebTestClient;
-import org.springframework.util.MultiValueMap;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.server.ServerWebExchange;
-import reactor.core.publisher.Mono;
-
-import java.util.HashMap;
-import java.util.Map;
@ExtendWith(SpringExtension.class)
@SpringBootTest(
- classes = MandatoryParameterApiClientTest.Application.class,
+ classes = TestApplication.class,
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, // https://github.com/spring-projects/spring-boot/issues/5077
properties = {
"server.port=15234"
@@ -79,60 +67,4 @@ void testSecond() {
.jsonPath("$.requestId").isEqualTo("requestId");
}
- @SpringBootApplication
- public static class Application {
-
- @RestController
- public static class ApiClientController {
-
- @Autowired
- private FirstApiClient firstApiClient;
-
- @Autowired
- private SecondApiClient secondApiClient;
-
- @Autowired
- private MandatoryParameterProperties properties;
-
- @GetMapping(value = "/first", produces = MediaType.APPLICATION_JSON_VALUE)
- public Mono> first(ServerWebExchange exchange) {
- return Mono.fromCallable(() -> {
- MultiValueMap queryParams = exchange.getRequest().getQueryParams();
- Map map = new HashMap<>();
- map.put(properties.getQueryKey().getStoreId(), queryParams.getFirst(properties.getQueryKey().getStoreId()));
- map.put(properties.getQueryKey().getClientId(), queryParams.getFirst(properties.getQueryKey().getClientId()));
- map.put(properties.getQueryKey().getChannelId(), queryParams.getFirst(properties.getQueryKey().getChannelId()));
- map.put(properties.getQueryKey().getUsername(), queryParams.getFirst(properties.getQueryKey().getUsername()));
- map.put(properties.getQueryKey().getRequestId(), queryParams.getFirst(properties.getQueryKey().getRequestId()));
- return map;
- });
- }
-
- @GetMapping(value = "/second", produces = MediaType.APPLICATION_JSON_VALUE)
- public Mono> second(ServerWebExchange exchange) {
- return Mono.fromCallable(() -> {
- HttpHeaders httpHeaders = exchange.getRequest().getHeaders();
- Map map = new HashMap<>();
- map.put(properties.getHeaderKey().getStoreId(), httpHeaders.getFirst(properties.getHeaderKey().getStoreId()));
- map.put(properties.getHeaderKey().getClientId(), httpHeaders.getFirst(properties.getHeaderKey().getClientId()));
- map.put(properties.getHeaderKey().getChannelId(), httpHeaders.getFirst(properties.getHeaderKey().getChannelId()));
- map.put(properties.getHeaderKey().getUsername(), httpHeaders.getFirst(properties.getHeaderKey().getUsername()));
- map.put(properties.getHeaderKey().getRequestId(), httpHeaders.getFirst(properties.getHeaderKey().getRequestId()));
- return map;
- });
- }
-
- @GetMapping(value = "/test-first", produces = MediaType.APPLICATION_JSON_VALUE)
- public Mono> testFirst() {
- return firstApiClient.first();
- }
-
- @GetMapping(value = "/test-second", produces = MediaType.APPLICATION_JSON_VALUE)
- public Mono> testSecond() {
- return secondApiClient.second();
- }
-
- }
-
- }
}
diff --git a/blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/helper/MandatoryParameterHelperTest.java b/blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/helper/MandatoryParameterHelperTest.java
index 188b4ef..12c1dfa 100644
--- a/blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/helper/MandatoryParameterHelperTest.java
+++ b/blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/helper/MandatoryParameterHelperTest.java
@@ -2,21 +2,19 @@
import brave.Span;
import brave.Tracer;
+import com.blibli.oss.backend.mandatoryparameter.TestApplication;
import com.blibli.oss.backend.mandatoryparameter.model.MandatoryParameter;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
-import java.util.Objects;
-
import static org.junit.jupiter.api.Assertions.*;
@ExtendWith(SpringExtension.class)
-@SpringBootTest(classes = MandatoryParameterHelperTest.Application.class)
+@SpringBootTest(classes = TestApplication.class)
class MandatoryParameterHelperTest {
public static final MandatoryParameter MANDATORY_PARAMETER = MandatoryParameter.builder()
@@ -34,10 +32,7 @@ class MandatoryParameterHelperTest {
@BeforeEach
void setUp() {
- span = tracer.currentSpan();
- if (Objects.isNull(span)) {
- span = tracer.nextSpan().start();
- }
+ span = tracer.newTrace();
}
@Test
@@ -48,9 +43,4 @@ void testToSleuth() {
assertEquals(MANDATORY_PARAMETER, mandatoryParameter);
}
- @SpringBootApplication
- static class Application {
-
- }
-
}
\ No newline at end of file
diff --git a/blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/sleuth/MandatoryParameterSleuthTest.java b/blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/sleuth/MandatoryParameterSleuthTest.java
index 646e1fb..0bb5418 100644
--- a/blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/sleuth/MandatoryParameterSleuthTest.java
+++ b/blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/sleuth/MandatoryParameterSleuthTest.java
@@ -1,26 +1,17 @@
package com.blibli.oss.backend.mandatoryparameter.sleuth;
-import brave.Tracer;
-import com.blibli.oss.backend.mandatoryparameter.helper.MandatoryParameterHelper;
-import com.blibli.oss.backend.mandatoryparameter.model.MandatoryParameter;
-import com.blibli.oss.backend.mandatoryparameter.swagger.annotation.MandatoryParameterAtQuery;
+import com.blibli.oss.backend.mandatoryparameter.TestApplication;
import com.blibli.oss.backend.mandatoryparameter.swagger.properties.MandatoryParameterProperties;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.http.MediaType;
-import org.springframework.stereotype.Service;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.reactive.server.WebTestClient;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RestController;
-import reactor.core.publisher.Mono;
@ExtendWith(SpringExtension.class)
@SpringBootTest(
- classes = MandatoryParameterSleuthTest.Application.class,
+ classes = TestApplication.class,
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)
public class MandatoryParameterSleuthTest {
@@ -52,37 +43,4 @@ void testExtraFieldsSleuth() {
.jsonPath("$.requestId").isEqualTo("requestId");
}
- @SpringBootApplication
- public static class Application {
-
- @RestController
- public static class SleuthController {
-
- @Autowired
- private SleuthService sleuthService;
-
- @MandatoryParameterAtQuery
- @GetMapping(
- value = "/sleuth",
- produces = MediaType.APPLICATION_JSON_VALUE
- )
- public Mono mandatoryParameter(MandatoryParameter mandatoryParameter) {
- return sleuthService.getMandatoryParameter();
- }
-
- }
-
- @Service
- public static class SleuthService {
-
- @Autowired
- private Tracer tracer;
-
- public Mono getMandatoryParameter() {
- return Mono.fromCallable(() -> MandatoryParameterHelper.fromSleuth(tracer.currentSpan().context()));
- }
-
- }
-
- }
}
diff --git a/blibli-backend-framework-newrelic/src/test/java/com/blibli/oss/backend/newrelic/aspect/CommandAspectTest.java b/blibli-backend-framework-newrelic/src/test/java/com/blibli/oss/backend/newrelic/aspect/CommandAspectTest.java
index b94ef6a..492860f 100644
--- a/blibli-backend-framework-newrelic/src/test/java/com/blibli/oss/backend/newrelic/aspect/CommandAspectTest.java
+++ b/blibli-backend-framework-newrelic/src/test/java/com/blibli/oss/backend/newrelic/aspect/CommandAspectTest.java
@@ -5,8 +5,8 @@
import com.blibli.oss.backend.newrelic.aspect.service.AspectModifyService;
import com.blibli.oss.backend.newrelic.injector.NewRelicTokenInjectorFilter;
import com.newrelic.api.agent.Segment;
+import com.newrelic.api.agent.Token;
import com.newrelic.api.agent.Transaction;
-import jdk.nashorn.internal.parser.Token;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
diff --git a/blibli-backend-framework-newrelic/src/test/java/com/blibli/oss/backend/newrelic/aspect/ReactiveMongoRepositoryAspectTest.java b/blibli-backend-framework-newrelic/src/test/java/com/blibli/oss/backend/newrelic/aspect/ReactiveMongoRepositoryAspectTest.java
index 9eb55b7..5ab2f71 100644
--- a/blibli-backend-framework-newrelic/src/test/java/com/blibli/oss/backend/newrelic/aspect/ReactiveMongoRepositoryAspectTest.java
+++ b/blibli-backend-framework-newrelic/src/test/java/com/blibli/oss/backend/newrelic/aspect/ReactiveMongoRepositoryAspectTest.java
@@ -4,8 +4,8 @@
import com.blibli.oss.backend.newrelic.aspect.service.AspectModifyService;
import com.newrelic.api.agent.DatastoreParameters;
import com.newrelic.api.agent.Segment;
+import com.newrelic.api.agent.Token;
import com.newrelic.api.agent.Transaction;
-import jdk.nashorn.internal.parser.Token;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.junit.jupiter.api.AfterEach;
@@ -24,11 +24,14 @@
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
+import org.springframework.data.repository.query.FluentQuery;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import reactor.util.context.Context;
+import java.util.function.Function;
+
import static com.blibli.oss.backend.newrelic.injector.NewRelicTokenInjectorFilter.TOKEN_CONTEXT_KEY;
import static com.blibli.oss.backend.newrelic.injector.NewRelicTokenInjectorFilter.TRANSACTION_CONTEXT_KEY;
import static org.mockito.ArgumentMatchers.argThat;
@@ -218,6 +221,11 @@ public Mono exists(Example example) {
throw new RuntimeException("NOT IMPLEMENTED");
}
+ @Override
+ public > P findBy(Example example, Function, P> queryFunction) {
+ throw new RuntimeException("NOT IMPLEMENTED");
+ }
+
@Override
public Flux findAll(Sort sort) {
throw new RuntimeException("NOT IMPLEMENTED");
@@ -293,6 +301,11 @@ public Mono delete(DummyData entity) {
throw new RuntimeException("NOT IMPLEMENTED");
}
+ @Override
+ public Mono deleteAllById(Iterable extends String> strings) {
+ throw new RuntimeException("NOT IMPLEMENTED");
+ }
+
@Override
public Mono deleteAll(Iterable extends DummyData> entities) {
throw new RuntimeException("NOT IMPLEMENTED");
diff --git a/blibli-backend-framework-newrelic/src/test/java/com/blibli/oss/backend/newrelic/injector/NewRelicTokenInjectorFilterTest.java b/blibli-backend-framework-newrelic/src/test/java/com/blibli/oss/backend/newrelic/injector/NewRelicTokenInjectorFilterTest.java
index 51854c1..61187d8 100644
--- a/blibli-backend-framework-newrelic/src/test/java/com/blibli/oss/backend/newrelic/injector/NewRelicTokenInjectorFilterTest.java
+++ b/blibli-backend-framework-newrelic/src/test/java/com/blibli/oss/backend/newrelic/injector/NewRelicTokenInjectorFilterTest.java
@@ -17,8 +17,8 @@
import java.util.Optional;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
diff --git a/blibli-backend-framework-newrelic/src/test/java/com/blibli/oss/backend/newrelic/integration/NewRelicIntegrationTest.java b/blibli-backend-framework-newrelic/src/test/java/com/blibli/oss/backend/newrelic/integration/NewRelicIntegrationTest.java
index 62224db..0fc9c77 100644
--- a/blibli-backend-framework-newrelic/src/test/java/com/blibli/oss/backend/newrelic/integration/NewRelicIntegrationTest.java
+++ b/blibli-backend-framework-newrelic/src/test/java/com/blibli/oss/backend/newrelic/integration/NewRelicIntegrationTest.java
@@ -6,7 +6,6 @@
import com.newrelic.api.agent.Token;
import com.newrelic.api.agent.TracedMethod;
import com.newrelic.api.agent.Transaction;
-import org.junit.Assert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -23,6 +22,7 @@
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.reactive.server.WebTestClient;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
@@ -94,7 +94,7 @@ public void testFilter() {
.jsonPath("$.data")
.isEqualTo("I say Hello World to NAMA");
- Assert.assertEquals("Command HelloWorldCommandImpl.HelloWorldCommandImpl.execute(..)", segmentNameCaptor.getValue());
+ assertEquals("Command HelloWorldCommandImpl.HelloWorldCommandImpl.execute(..)", segmentNameCaptor.getValue());
verify(newRelicAgent).getTransaction();
verify(transaction).startSegment(segmentNameCaptor.capture());
diff --git a/blibli-backend-framework-sleuth/src/main/java/com/blibli/oss/backend/sleuth/baggage/SleuthExtraFieldCustomizer.java b/blibli-backend-framework-sleuth/src/main/java/com/blibli/oss/backend/sleuth/baggage/SleuthExtraFieldCustomizer.java
new file mode 100644
index 0000000..f1be71f
--- /dev/null
+++ b/blibli-backend-framework-sleuth/src/main/java/com/blibli/oss/backend/sleuth/baggage/SleuthExtraFieldCustomizer.java
@@ -0,0 +1,29 @@
+package com.blibli.oss.backend.sleuth.baggage;
+
+import brave.baggage.BaggageField;
+import brave.baggage.BaggagePropagation;
+import brave.baggage.BaggagePropagationConfig;
+import brave.baggage.BaggagePropagationCustomizer;
+import com.blibli.oss.backend.sleuth.configuration.SleuthConfiguration;
+import com.blibli.oss.backend.sleuth.fields.SleuthExtraFields;
+import lombok.AllArgsConstructor;
+
+import java.util.List;
+
+@AllArgsConstructor
+public class SleuthExtraFieldCustomizer implements BaggagePropagationCustomizer {
+
+ private List sleuthExtraFields;
+
+ @Override
+ public void customize(BaggagePropagation.FactoryBuilder factoryBuilder) {
+ sleuthExtraFields.forEach(fields -> {
+ fields.getFields().forEach(field -> {
+ factoryBuilder.add(BaggagePropagationConfig.SingleBaggageField.newBuilder(BaggageField.create(field))
+ .addKeyName(SleuthConfiguration.HTTP_BAGGAGE_PREFIX + field)
+ .addKeyName(SleuthConfiguration.MESSAGING_BAGGAGE_PREFIX + field)
+ .build());
+ });
+ });
+ }
+}
diff --git a/blibli-backend-framework-sleuth/src/main/java/com/blibli/oss/backend/sleuth/configuration/SleuthConfiguration.java b/blibli-backend-framework-sleuth/src/main/java/com/blibli/oss/backend/sleuth/configuration/SleuthConfiguration.java
index 720efab..6ed1788 100644
--- a/blibli-backend-framework-sleuth/src/main/java/com/blibli/oss/backend/sleuth/configuration/SleuthConfiguration.java
+++ b/blibli-backend-framework-sleuth/src/main/java/com/blibli/oss/backend/sleuth/configuration/SleuthConfiguration.java
@@ -1,17 +1,12 @@
package com.blibli.oss.backend.sleuth.configuration;
-import brave.propagation.B3Propagation;
-import brave.propagation.ExtraFieldCustomizer;
-import brave.propagation.ExtraFieldPropagation;
-import brave.propagation.Propagation;
-import com.blibli.oss.backend.sleuth.fields.SleuthExtraFieldConfiguration;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.cloud.sleuth.autoconfig.SleuthProperties;
+import com.blibli.oss.backend.sleuth.baggage.SleuthExtraFieldCustomizer;
+import com.blibli.oss.backend.sleuth.fields.SleuthExtraFields;
+import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.stream.Collectors;
@Configuration
public class SleuthConfiguration {
@@ -19,66 +14,9 @@ public class SleuthConfiguration {
public static final String HTTP_BAGGAGE_PREFIX = "baggage-";
public static final String MESSAGING_BAGGAGE_PREFIX = "baggage_";
- @Autowired(required = false)
- private ExtraFieldPropagation.FactoryBuilder extraFieldPropagationFactoryBuilder;
-
- @Autowired(required = false)
- private List extraFieldCustomizers = new ArrayList<>();
-
- /**
- * This bean is copied from TraceAutoConfiguration class,
- * with some modification to support extra fields that can integrated for http and messaging
- *
- * @param extraFieldConfiguration extra field configuration
- * @param sleuthProperties sleuth properties
- * @return new bean
- * @see org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration
- * @see org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration#sleuthPropagation(SleuthProperties)
- */
- @Bean
- public Propagation.Factory sleuthPropagation(SleuthExtraFieldConfiguration extraFieldConfiguration, SleuthProperties sleuthProperties) {
- // modification to merge baggage from properties and from bean
- List baggageKeys = extraFieldConfiguration.getExtraFields(sleuthProperties.getBaggageKeys());
- if (baggageKeys.isEmpty()
- && sleuthProperties.getPropagationKeys().isEmpty()
- && extraFieldCustomizers.isEmpty()
- && this.extraFieldPropagationFactoryBuilder == null
- && sleuthProperties.getLocalKeys().isEmpty()) {
- return B3Propagation.FACTORY;
- }
- ExtraFieldPropagation.FactoryBuilder factoryBuilder;
- if (this.extraFieldPropagationFactoryBuilder != null) {
- factoryBuilder = this.extraFieldPropagationFactoryBuilder;
- } else {
- factoryBuilder = ExtraFieldPropagation
- .newFactoryBuilder(B3Propagation.FACTORY);
- }
- if (!baggageKeys.isEmpty()) {
- factoryBuilder
- // for HTTP
- .addPrefixedFields(HTTP_BAGGAGE_PREFIX, baggageKeys)
- // for messaging
- .addPrefixedFields(MESSAGING_BAGGAGE_PREFIX, baggageKeys);
- }
- if (!sleuthProperties.getPropagationKeys().isEmpty()) {
- for (String key : sleuthProperties.getPropagationKeys()) {
- factoryBuilder.addField(key);
- }
- }
- if (!sleuthProperties.getLocalKeys().isEmpty()) {
- for (String key : sleuthProperties.getLocalKeys()) {
- factoryBuilder.addRedactedField(key);
- }
- }
- for (ExtraFieldCustomizer customizer : this.extraFieldCustomizers) {
- customizer.customize(factoryBuilder);
- }
- return factoryBuilder.build();
- }
-
@Bean
- public SleuthExtraFieldConfiguration sleuthExtraFieldConfiguration() {
- return new SleuthExtraFieldConfiguration();
+ public SleuthExtraFieldCustomizer sleuthExtraFieldCustomizer(ObjectProvider sleuthExtraFields) {
+ return new SleuthExtraFieldCustomizer(sleuthExtraFields.stream().collect(Collectors.toList()));
}
}
diff --git a/blibli-backend-framework-sleuth/src/main/java/com/blibli/oss/backend/sleuth/webflux/SleuthWebFilter.java b/blibli-backend-framework-sleuth/src/main/java/com/blibli/oss/backend/sleuth/webflux/SleuthWebFilter.java
index cae9813..7c83ebe 100644
--- a/blibli-backend-framework-sleuth/src/main/java/com/blibli/oss/backend/sleuth/webflux/SleuthWebFilter.java
+++ b/blibli-backend-framework-sleuth/src/main/java/com/blibli/oss/backend/sleuth/webflux/SleuthWebFilter.java
@@ -1,8 +1,8 @@
package com.blibli.oss.backend.sleuth.webflux;
-import brave.Span;
-import brave.Tracer;
-import org.springframework.cloud.sleuth.instrument.web.TraceWebFilter;
+import org.springframework.cloud.sleuth.Span;
+import org.springframework.cloud.sleuth.Tracer;
+import org.springframework.cloud.sleuth.autoconfig.instrument.web.SleuthWebProperties;
import org.springframework.core.Ordered;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
@@ -13,23 +13,25 @@
public interface SleuthWebFilter extends WebFilter, Ordered {
+ String TRACE_REQUEST_ATTR = org.springframework.cloud.sleuth.Span.class.getName();
+
@Override
default int getOrder() {
- return Ordered.HIGHEST_PRECEDENCE + 10;
+ return SleuthWebProperties.TRACING_FILTER_ORDER + 10;
}
default Span getCurrentSpan(ServerWebExchange exchange) {
Span span = getTracer().currentSpan();
if (Objects.isNull(span)) {
- span = exchange.getAttribute(TraceWebFilter.class.getName() + ".TRACE");
+ span = exchange.getAttribute(TRACE_REQUEST_ATTR);
}
return span;
}
@Override
default Mono filter(ServerWebExchange exchange, WebFilterChain chain) {
- return Mono.fromCallable(() -> getCurrentSpan(exchange))
- .flatMap(span -> filter(exchange, chain, span));
+ Span currentSpan = getCurrentSpan(exchange);
+ return Objects.nonNull(currentSpan) ? filter(exchange, chain, currentSpan) : chain.filter(exchange);
}
Tracer getTracer();
diff --git a/blibli-backend-framework-sleuth/src/test/java/com/blibli/oss/backend/sleuth/SleuthTest.java b/blibli-backend-framework-sleuth/src/test/java/com/blibli/oss/backend/sleuth/SleuthTest.java
index 1f1fedb..5257964 100644
--- a/blibli-backend-framework-sleuth/src/test/java/com/blibli/oss/backend/sleuth/SleuthTest.java
+++ b/blibli-backend-framework-sleuth/src/test/java/com/blibli/oss/backend/sleuth/SleuthTest.java
@@ -2,7 +2,7 @@
import brave.Span;
import brave.Tracer;
-import brave.propagation.ExtraFieldPropagation;
+import brave.baggage.BaggageField;
import com.blibli.oss.backend.sleuth.fields.SleuthExtraFields;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -28,26 +28,24 @@ public class SleuthTest {
void testExists() {
Span span = tracer.newTrace();
- ExtraFieldPropagation.set(span.context(), "Eko", "Value");
- ExtraFieldPropagation.set(span.context(), "Kurniawan", "Value");
- ExtraFieldPropagation.set(span.context(), "Khannedy", "Value");
- ExtraFieldPropagation.set(span.context(), "Hello", "Value");
- ExtraFieldPropagation.set(span.context(), "World", "Value");
-
- assertEquals("Value", ExtraFieldPropagation.get(span.context(), "Eko"));
- assertEquals("Value", ExtraFieldPropagation.get(span.context(), "Kurniawan"));
- assertEquals("Value", ExtraFieldPropagation.get(span.context(), "Khannedy"));
- assertEquals("Value", ExtraFieldPropagation.get(span.context(), "Hello"));
- assertEquals("Value", ExtraFieldPropagation.get(span.context(), "World"));
+ BaggageField.getByName(span.context(), "Eko").updateValue(span.context(), "Value");
+ BaggageField.getByName(span.context(), "Kurniawan").updateValue(span.context(), "Value");
+ BaggageField.getByName(span.context(), "Khannedy").updateValue(span.context(), "Value");
+ BaggageField.getByName(span.context(), "Hello").updateValue(span.context(), "Value");
+ BaggageField.getByName(span.context(), "World").updateValue(span.context(), "Value");
+
+ assertEquals("Value", BaggageField.getByName(span.context(), "Eko").getValue(span.context()));
+ assertEquals("Value", BaggageField.getByName(span.context(), "Kurniawan").getValue(span.context()));
+ assertEquals("Value", BaggageField.getByName(span.context(), "Khannedy").getValue(span.context()));
+ assertEquals("Value", BaggageField.getByName(span.context(), "Hello").getValue(span.context()));
+ assertEquals("Value", BaggageField.getByName(span.context(), "World").getValue(span.context()));
}
@Test
void testNotExists() {
Span span = tracer.newTrace();
- ExtraFieldPropagation.set(span.context(), "NotExists", "Value");
-
- assertNull(ExtraFieldPropagation.get(span.context(), "NotExists"));
+ assertNull(BaggageField.getByName(span.context(), "NotExists"));
}
@SpringBootApplication
diff --git a/blibli-backend-framework-sleuth/src/test/resources/application.properties b/blibli-backend-framework-sleuth/src/test/resources/application.properties
index 8943478..5ac887b 100644
--- a/blibli-backend-framework-sleuth/src/test/resources/application.properties
+++ b/blibli-backend-framework-sleuth/src/test/resources/application.properties
@@ -1,3 +1,6 @@
-spring.sleuth.baggage-keys[0]=Eko
-spring.sleuth.baggage-keys[1]=Kurniawan
-spring.sleuth.baggage-keys[2]=Khannedy
\ No newline at end of file
+spring.sleuth.baggage.remote-fields[0]=Eko
+spring.sleuth.baggage.remote-fields[1]=Kurniawan
+spring.sleuth.baggage.remote-fields[2]=Khannedy
+spring.sleuth.baggage.local-fields[0]=Eko
+spring.sleuth.baggage.local-fields[1]=Kurniawan
+spring.sleuth.baggage.local-fields[2]=Khannedy
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 50744af..9d50e5a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -47,7 +47,7 @@
org.springframework.boot
spring-boot-starter-parent
- 2.3.0.RELEASE
+ 2.6.7
@@ -60,13 +60,18 @@
1.8
- Hoxton.SR4
+ 2021.0.1
1.2.26
${project.version}
0.6
2.26.3
6.4.0
5.11.0
+
+
+ 1.8
+ 1.8
+ 17
@@ -241,6 +246,18 @@
+
+ org.codehaus.mojo
+ animal-sniffer-maven-plugin
+ 1.20
+
+
+ org.codehaus.mojo.signature
+ java17
+ 1.0
+
+
+