Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions blibli-backend-framework-api-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<artifactId>blibli-backend-framework-sleuth</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
com.blibli.oss.backend.apiclient.configuration.ApiClientRegistrar
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -33,8 +33,8 @@ public class SleuthController {
)
public Mono<Map<String, String>> first(@RequestParam("firstName") String firstName,
@RequestParam("lastName") String lastName) {
ExtraFieldPropagation.set(tracer.currentSpan().context(), "FirstName", firstName);
ExtraFieldPropagation.set(tracer.currentSpan().context(), "LastName", lastName);
BaggageField.getByName(tracer.currentSpan().context(), "FirstName").updateValue(tracer.currentSpan().context(), firstName);
BaggageField.getByName(tracer.currentSpan().context(), "LastName").updateValue(tracer.currentSpan().context(), lastName);
return sleuthApiClient.second();
}

Expand All @@ -43,9 +43,13 @@ public Mono<Map<String, String>> first(@RequestParam("firstName") String firstNa
produces = MediaType.APPLICATION_JSON_VALUE
)
public Mono<Map<String, String>> second(ServerWebExchange exchange) {

exchange.getRequest().getHeaders().forEach((s, strings) ->
System.out.println("HEADER " + s + ":" + String.join(",", strings.toArray(new String[0]))));

Map<String, String> map = new HashMap<>();
map.put("firstName", ExtraFieldPropagation.get(tracer.currentSpan().context(), "FirstName"));
map.put("lastName", ExtraFieldPropagation.get(tracer.currentSpan().context(), "LastName"));
map.put("firstName", BaggageField.getByName(tracer.currentSpan().context(), "FirstName").getValue(tracer.currentSpan().context()));
map.put("lastName", BaggageField.getByName(tracer.currentSpan().context(), "LastName").getValue(tracer.currentSpan().context()));
map.put("headerFirstName", exchange.getRequest().getHeaders().getFirst(SleuthConfiguration.HTTP_BAGGAGE_PREFIX + "firstname"));
map.put("headerLastName", exchange.getRequest().getHeaders().getFirst(SleuthConfiguration.HTTP_BAGGAGE_PREFIX + "lastname"));
return Mono.just(map);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ blibli.backend.reactor.scheduler.configs.exampleClient.thread-pool.queue-size=10
blibli.backend.reactor.scheduler.configs.exampleClient.thread-pool.queue-type=linked

spring.sleuth.baggage-keys[0]=FirstName
spring.sleuth.baggage.remote-fields[0]=FirstName
spring.sleuth.baggage.local-fields[0]=FirstName

blibli.backend.apiclient.sleuth.enabled=true
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.blibli.oss.backend.externalapi.helper;

import brave.propagation.ExtraFieldPropagation;
import brave.baggage.BaggageField;
import brave.propagation.TraceContext;
import com.blibli.oss.backend.externalapi.model.ExternalSession;
import com.blibli.oss.backend.externalapi.properties.ExternalApiProperties;
Expand Down Expand Up @@ -28,11 +28,11 @@ public static ExternalSession getExternalSession(HttpHeaders headers, ExternalAp

public static ExternalSession fromSleuth(TraceContext traceContext) {
ExternalSession.ExternalSessionBuilder builder = ExternalSession.builder()
.userId(ExtraFieldPropagation.get(traceContext, ExternalSessionSleuth.USER_ID))
.sessionId(ExtraFieldPropagation.get(traceContext, ExternalSessionSleuth.SESSION_ID))
.member(Boolean.parseBoolean(ExtraFieldPropagation.get(traceContext, ExternalSessionSleuth.IS_MEMBER)));
.userId(BaggageField.getByName(traceContext, ExternalSessionSleuth.USER_ID).getValue(traceContext))
.sessionId(BaggageField.getByName(traceContext, ExternalSessionSleuth.SESSION_ID).getValue(traceContext))
.member(Boolean.parseBoolean(BaggageField.getByName(traceContext, ExternalSessionSleuth.IS_MEMBER).getValue(traceContext)));

String additionalParameters = ExtraFieldPropagation.get(traceContext, ExternalSessionSleuth.ADDITIONAL_PARAMETERS);
String additionalParameters = BaggageField.getByName(traceContext, ExternalSessionSleuth.ADDITIONAL_PARAMETERS).getValue(traceContext);
if (Objects.nonNull(additionalParameters)) {
String[] split = additionalParameters.split("\n");
for (String pair : split) {
Expand All @@ -45,16 +45,16 @@ public static ExternalSession fromSleuth(TraceContext traceContext) {
}

public static ExternalSession toSleuth(TraceContext traceContext, ExternalSession externalSession) {
ExtraFieldPropagation.set(traceContext, ExternalSessionSleuth.USER_ID, externalSession.getUserId());
ExtraFieldPropagation.set(traceContext, ExternalSessionSleuth.SESSION_ID, externalSession.getSessionId());
ExtraFieldPropagation.set(traceContext, ExternalSessionSleuth.IS_MEMBER, String.valueOf(externalSession.isMember()));
BaggageField.getByName(traceContext, ExternalSessionSleuth.USER_ID).updateValue(traceContext, externalSession.getUserId());
BaggageField.getByName(traceContext, ExternalSessionSleuth.SESSION_ID).updateValue(traceContext, externalSession.getSessionId());
BaggageField.getByName(traceContext, ExternalSessionSleuth.IS_MEMBER).updateValue(traceContext, String.valueOf(externalSession.isMember()));

if (!externalSession.getAdditionalParameters().isEmpty()) {
StringBuilder builder = new StringBuilder();
externalSession.getAdditionalParameters().forEach((key, value) -> {
builder.append(key).append("=").append(value).append("\n");
});
ExtraFieldPropagation.set(traceContext, ExternalSessionSleuth.ADDITIONAL_PARAMETERS, builder.toString());
BaggageField.getByName(traceContext, ExternalSessionSleuth.ADDITIONAL_PARAMETERS).updateValue(traceContext, builder.toString());
}

return externalSession;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.blibli.oss.backend.internalapi.helper;

import brave.propagation.ExtraFieldPropagation;
import brave.baggage.BaggageField;
import brave.propagation.TraceContext;
import com.blibli.oss.backend.internalapi.model.InternalSession;
import com.blibli.oss.backend.internalapi.properties.InternalApiProperties;
Expand Down Expand Up @@ -33,19 +33,19 @@ private static List<String> getRoles(String roles) {

public static InternalSession fromSleuth(TraceContext traceContext) {
return InternalSession.builder()
.userId(ExtraFieldPropagation.get(traceContext, InternalSessionSleuth.USER_ID))
.userName(ExtraFieldPropagation.get(traceContext, InternalSessionSleuth.USER_NAME))
.roles(getRoles(ExtraFieldPropagation.get(traceContext, InternalSessionSleuth.ROLES)))
.userId(BaggageField.getByName(traceContext, InternalSessionSleuth.USER_ID).getValue(traceContext))
.userName(BaggageField.getByName(traceContext, InternalSessionSleuth.USER_NAME).getValue(traceContext))
.roles(getRoles(BaggageField.getByName(traceContext, InternalSessionSleuth.ROLES).getValue(traceContext)))
.build();
}

public static InternalSession toSleuth(TraceContext traceContext, InternalSession externalSession) {
ExtraFieldPropagation.set(traceContext, InternalSessionSleuth.USER_ID, externalSession.getUserId());
ExtraFieldPropagation.set(traceContext, InternalSessionSleuth.USER_NAME, externalSession.getUserName());
BaggageField.getByName(traceContext, InternalSessionSleuth.USER_ID).updateValue(traceContext, externalSession.getUserId());
BaggageField.getByName(traceContext, InternalSessionSleuth.USER_NAME).updateValue(traceContext, externalSession.getUserName());

StringJoiner stringJoiner = new StringJoiner(",");
externalSession.getRoles().forEach(stringJoiner::add);
ExtraFieldPropagation.set(traceContext, InternalSessionSleuth.ROLES, stringJoiner.toString());
BaggageField.getByName(traceContext, InternalSessionSleuth.ROLES).updateValue(traceContext, stringJoiner.toString());

return externalSession;
}
Expand Down
4 changes: 4 additions & 0 deletions blibli-backend-framework-kafka/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.springframework.aop.support.AopUtils;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.annotation.KafkaListenerAnnotationBeanPostProcessor;
import org.springframework.kafka.config.MethodKafkaListenerEndpoint;
import org.springframework.kafka.support.TopicPartitionOffset;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Method;
Expand All @@ -13,9 +15,11 @@ public class KafkaListenerBeanProcessor extends KafkaListenerAnnotationBeanPostP
@Override
protected void processKafkaListener(KafkaListener kafkaListener, Method method, Object bean, String beanName) {
Method methodToUse = checkProxy(method, bean);
KafkaListenerEndpoint endpoint = new KafkaListenerEndpoint();
MethodKafkaListenerEndpoint endpoint = new MethodKafkaListenerEndpoint();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ini jangan diganti, kalo diganti, nanti kafka interceptor nya gak kan jalan lagi

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted mas, sblmnya gak notice kalau extend ke class yang sama

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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -28,12 +27,11 @@ public Mono<Void> 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;
}

}
Loading