diff --git a/annotations/pom.xml b/annotations/pom.xml
index ba7f01a..fb70499 100644
--- a/annotations/pom.xml
+++ b/annotations/pom.xml
@@ -7,7 +7,7 @@
io.getlime.core
lime-java-core-parent
- 1.8.0
+ 1.9.0
annotations
diff --git a/audit-base/pom.xml b/audit-base/pom.xml
index bbccf8b..b5b17bf 100644
--- a/audit-base/pom.xml
+++ b/audit-base/pom.xml
@@ -6,7 +6,7 @@
io.getlime.core
lime-java-core-parent
- 1.8.0
+ 1.9.0
audit-base
diff --git a/audit-base/src/test/resources/application.properties b/audit-base/src/test/resources/application.properties
index b5d2db4..d47f7a9 100644
--- a/audit-base/src/test/resources/application.properties
+++ b/audit-base/src/test/resources/application.properties
@@ -1,11 +1,2 @@
-# H2
-spring.h2.console.enabled=true
-spring.h2.console.path=/h2
-# Datasource
-spring.datasource.url=jdbc:h2:file:~/audit
-spring.datasource.username=sa
-spring.datasource.password=
-spring.datasource.driver-class-name=org.h2.Driver
-
# Audit configuration
-spring.application.name=test-application
\ No newline at end of file
+spring.application.name=test-application
diff --git a/bom/pom.xml b/bom/pom.xml
index 5bd68f3..1c2c933 100644
--- a/bom/pom.xml
+++ b/bom/pom.xml
@@ -7,7 +7,7 @@
io.getlime.core
lime-java-core-parent
- 1.8.0
+ 1.9.0
core-bom
diff --git a/http-common/pom.xml b/http-common/pom.xml
index d2e6bff..6adf198 100644
--- a/http-common/pom.xml
+++ b/http-common/pom.xml
@@ -7,7 +7,7 @@
io.getlime.core
lime-java-core-parent
- 1.8.0
+ 1.9.0
http-common
diff --git a/pom.xml b/pom.xml
index 4da940f..43c093f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,7 +8,7 @@
Wultra - Core Java Libraries
io.getlime.core
lime-java-core-parent
- 1.8.0
+ 1.9.0
pom
2017
@@ -53,14 +53,14 @@
UTF-8
- 17
- 17
- 3.2.2
+ 17
+ ${java.version}
+
+ 3.12.1
+ 3.2.5
- 3.1.6
-
- 1.4.14
+ 3.2.3
3.0.1
@@ -73,18 +73,6 @@
pom
import
-
-
-
- ch.qos.logback
- logback-classic
- ${logback.version}
-
-
- ch.qos.logback
- logback-core
- ${logback.version}
-
@@ -99,6 +87,12 @@
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+
org.apache.maven.plugins
maven-surefire-plugin
diff --git a/rest-client-base/pom.xml b/rest-client-base/pom.xml
index 43f0a6b..bab834d 100644
--- a/rest-client-base/pom.xml
+++ b/rest-client-base/pom.xml
@@ -6,7 +6,7 @@
io.getlime.core
lime-java-core-parent
- 1.8.0
+ 1.9.0
rest-client-base
@@ -61,6 +61,12 @@
netty-http-authenticator
1.5
+
+
+ io.opentelemetry
+ opentelemetry-api
+
+
diff --git a/rest-client-base/src/main/java/com/wultra/core/rest/client/base/DefaultRestClient.java b/rest-client-base/src/main/java/com/wultra/core/rest/client/base/DefaultRestClient.java
index e89b7e0..1a1741a 100644
--- a/rest-client-base/src/main/java/com/wultra/core/rest/client/base/DefaultRestClient.java
+++ b/rest-client-base/src/main/java/com/wultra/core/rest/client/base/DefaultRestClient.java
@@ -212,6 +212,7 @@ private void initializeWebClient() throws RestClientException {
});
});
}
+ builder.filter(TraceparentFilterFunction.handleTraceparentContext());
final ReactorClientHttpConnector connector = new ReactorClientHttpConnector(httpClient);
webClient = builder.baseUrl(config.getBaseUrl()).clientConnector(connector).build();
diff --git a/rest-client-base/src/main/java/com/wultra/core/rest/client/base/TraceparentFilterFunction.java b/rest-client-base/src/main/java/com/wultra/core/rest/client/base/TraceparentFilterFunction.java
new file mode 100644
index 0000000..46a501e
--- /dev/null
+++ b/rest-client-base/src/main/java/com/wultra/core/rest/client/base/TraceparentFilterFunction.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2024 Wultra s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.wultra.core.rest.client.base;
+
+import io.opentelemetry.api.trace.Span;
+import io.opentelemetry.api.trace.SpanContext;
+import io.opentelemetry.api.trace.TraceFlags;
+import org.springframework.web.reactive.function.client.ClientRequest;
+import org.springframework.web.reactive.function.client.ClientResponse;
+import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
+import org.springframework.web.reactive.function.client.ExchangeFunction;
+import reactor.core.publisher.Mono;
+
+/**
+ * An ExchangeFilterFunction for adding traceparent header to WebClient requests.
+ * It also propagates trace ID through Reactor context and MDC for logging purposes.
+ *
+ * @author Jan Dusil, jan.dusil@wultra.com
+ */
+public class TraceparentFilterFunction implements ExchangeFilterFunction {
+
+ private static final String TRACEPARENT_HEADER_KEY = "traceparent";
+
+ /**
+ * Applies the filter to the given ClientRequest and ExchangeFunction.
+ *
+ * @param request The client request.
+ * @param next The next exchange function in the chain.
+ * @return a Mono after applying the filter.
+ */
+ @Override
+ public Mono filter(final ClientRequest request, final ExchangeFunction next) {
+ return next.exchange(addTraceparentHeader(request));
+ }
+
+ /**
+ * Adds a traceparent header to the ClientRequest if a current span context is available.
+ *
+ * @param request The client request.
+ * @return a modified ClientRequest with the traceparent header added.
+ */
+ private ClientRequest addTraceparentHeader(final ClientRequest request) {
+ final Span currentSpan = Span.current();
+ if (currentSpan != null) {
+ final SpanContext spanContext = currentSpan.getSpanContext();
+ if (spanContext != null) {
+ final String traceId = spanContext.getTraceId();
+ /* The parentId of the next server Span will be the current spanId */
+ final String parentId = spanContext.getSpanId();
+ final TraceFlags traceFlags = spanContext.getTraceFlags();
+ if (traceId != null && parentId != null && traceFlags != null) {
+ final String headerValue = String.format("00-%s-%s-%s",
+ traceId,
+ parentId,
+ traceFlags.asHex());
+ return ClientRequest.from(request)
+ .headers(headers -> headers.set(TRACEPARENT_HEADER_KEY, headerValue))
+ .build();
+ }
+ }
+ }
+ return request;
+ }
+
+ /**
+ * Factory method to create an instance of TraceparentFilterFunction.
+ *
+ * @return a new instance of TraceparentFilterFunction.
+ */
+ public static ExchangeFilterFunction handleTraceparentContext() {
+ return new TraceparentFilterFunction();
+ }
+}
diff --git a/rest-client-base/src/test/java/com/wultra/core/rest/client/base/controller/PublicTestRestController.java b/rest-client-base/src/test/java/com/wultra/core/rest/client/base/controller/PublicTestRestController.java
index b2c8ad4..958e232 100644
--- a/rest-client-base/src/test/java/com/wultra/core/rest/client/base/controller/PublicTestRestController.java
+++ b/rest-client-base/src/test/java/com/wultra/core/rest/client/base/controller/PublicTestRestController.java
@@ -80,7 +80,7 @@ public ObjectResponse testPostWithObjectRequestAndResponse(@Reques
}
@PostMapping(value = "/multipart-request-response", consumes = { MediaType.MULTIPART_FORM_DATA_VALUE })
- public ObjectResponse testPostWithMultipartRequestAndResponse(@RequestPart TestRequest request) {
+ public ObjectResponse testPostWithMultipartRequestAndResponse(@RequestPart("request") TestRequest request) {
TestResponse testResponse = new TestResponse(request.getRequest());
return new ObjectResponse<>(testResponse);
}
diff --git a/rest-client-base/src/test/java/com/wultra/core/rest/client/base/model/TestRequest.java b/rest-client-base/src/test/java/com/wultra/core/rest/client/base/model/TestRequest.java
index 76c8960..775d74c 100644
--- a/rest-client-base/src/test/java/com/wultra/core/rest/client/base/model/TestRequest.java
+++ b/rest-client-base/src/test/java/com/wultra/core/rest/client/base/model/TestRequest.java
@@ -15,11 +15,14 @@
*/
package com.wultra.core.rest.client.base.model;
+import lombok.ToString;
+
/**
* Test request.
*
* @author Roman Strobl, roman.strobl@wultra.com
*/
+@ToString
public class TestRequest {
private String request;
diff --git a/rest-model-base/pom.xml b/rest-model-base/pom.xml
index 015e291..d9118ff 100644
--- a/rest-model-base/pom.xml
+++ b/rest-model-base/pom.xml
@@ -6,7 +6,7 @@
io.getlime.core
lime-java-core-parent
- 1.8.0
+ 1.9.0
rest-model-base