diff --git a/connectivity/service/src/main/resources/logback.xml b/connectivity/service/src/main/resources/logback.xml index 0c7e34b66e..43f8d573ea 100644 --- a/connectivity/service/src/main/resources/logback.xml +++ b/connectivity/service/src/main/resources/logback.xml @@ -16,14 +16,14 @@ - %date{ISO8601} %-5level [%X{correlation-id}][%X{traceparent}] %logger{20} %X{pekkoSource} - %msg%n + %date{ISO8601} %-5level [%X{correlation-id}][%X{traceparent-trace-id}] %logger{20} %X{pekkoSource} - %msg%n System.err - %date{ISO8601} %-5level [%X{correlation-id}][%X{traceparent}] %logger{20} %X{pekkoSource} - %msg%n + %date{ISO8601} %-5level [%X{correlation-id}][%X{traceparent-trace-id}] %logger{20} %X{pekkoSource} - %msg%n ERROR diff --git a/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/security/authentication/preauth/PreAuthenticatedAuthenticationProvider.java b/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/security/authentication/preauth/PreAuthenticatedAuthenticationProvider.java index cd33cc484d..b2b972fd42 100644 --- a/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/security/authentication/preauth/PreAuthenticatedAuthenticationProvider.java +++ b/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/security/authentication/preauth/PreAuthenticatedAuthenticationProvider.java @@ -24,6 +24,10 @@ import javax.annotation.concurrent.Immutable; +import org.apache.pekko.http.javadsl.model.HttpRequest; +import org.apache.pekko.http.javadsl.model.Query; +import org.apache.pekko.http.javadsl.model.Uri; +import org.apache.pekko.http.javadsl.server.RequestContext; import org.eclipse.ditto.base.model.auth.AuthorizationContext; import org.eclipse.ditto.base.model.auth.AuthorizationContextType; import org.eclipse.ditto.base.model.auth.AuthorizationModelFactory; @@ -41,11 +45,6 @@ import org.eclipse.ditto.internal.utils.pekko.logging.ThreadSafeDittoLogger; import org.eclipse.ditto.utils.jsr305.annotations.AllValuesAreNonnullByDefault; -import org.apache.pekko.http.javadsl.model.HttpRequest; -import org.apache.pekko.http.javadsl.model.Query; -import org.apache.pekko.http.javadsl.model.Uri; -import org.apache.pekko.http.javadsl.server.RequestContext; - /** * Handles authentication by using a defined header field {@link org.eclipse.ditto.gateway.service.security.HttpHeader#X_DITTO_PRE_AUTH} which proxies in front * of Ditto may set to inject authenticated subjects into a HTTP request. @@ -126,7 +125,10 @@ protected CompletableFuture tryToAuthenticate(final Reques final var combinedHeaders = new HashMap<>(dittoHeaders); combinedHeaders.putAll(StreamSupport.stream(requestContext.getRequest().getHeaders().spliterator(), false) .collect(Collectors.toMap( - akka.http.javadsl.model.HttpHeader::name, akka.http.javadsl.model.HttpHeader::value))); + org.apache.pekko.http.javadsl.model.HttpHeader::name, + org.apache.pekko.http.javadsl.model.HttpHeader::value + )) + ); LOGGER.withCorrelationId(combinedHeaders) .info("Pre-authentication has been applied resulting in AuthorizationContext <{}>.", authContext); diff --git a/gateway/service/src/main/resources/logback.xml b/gateway/service/src/main/resources/logback.xml index b3a52bdeed..de70c86ed3 100755 --- a/gateway/service/src/main/resources/logback.xml +++ b/gateway/service/src/main/resources/logback.xml @@ -16,14 +16,14 @@ - %date{ISO8601} %-5level [%X{correlation-id}][%X{traceparent}] %logger{20} %X{pekkoSource} - %msg%n + %date{ISO8601} %-5level [%X{correlation-id}][%X{traceparent-trace-id}] %logger{20} %X{pekkoSource} - %msg%n System.err - %date{ISO8601} %-5level [%X{correlation-id}][%X{traceparent}] %logger{20} %X{pekkoSource} - %msg%n + %date{ISO8601} %-5level [%X{correlation-id}][%X{traceparent-trace-id}] %logger{20} %X{pekkoSource} - %msg%n ERROR diff --git a/internal/utils/pekko/src/main/java/org/eclipse/ditto/internal/utils/pekko/logging/CommonMdcEntryKey.java b/internal/utils/pekko/src/main/java/org/eclipse/ditto/internal/utils/pekko/logging/CommonMdcEntryKey.java index 76a75c6ea2..e63492dbf7 100644 --- a/internal/utils/pekko/src/main/java/org/eclipse/ditto/internal/utils/pekko/logging/CommonMdcEntryKey.java +++ b/internal/utils/pekko/src/main/java/org/eclipse/ditto/internal/utils/pekko/logging/CommonMdcEntryKey.java @@ -17,6 +17,7 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.function.Function; import java.util.stream.Stream; import javax.annotation.Nullable; @@ -34,6 +35,9 @@ public enum CommonMdcEntryKey implements CharSequence { DITTO_LOG_TAG("ditto-log-tag"), TRACE_PARENT(DittoHeaderDefinition.W3C_TRACEPARENT.getKey()); + private static final String TRACE_ID = TRACE_PARENT.key + "-trace-id"; + private static final String SPAN_ID = TRACE_PARENT.key + "-span-id"; + private final String key; CommonMdcEntryKey(final String key) { @@ -90,18 +94,27 @@ public static List extractMdcEntriesFromHeaders(@Nullable final Map - extractValue(headers, mdcEntryKey) - .map(value -> MdcEntry.of(mdcEntryKey.key, value)) - .stream() - ).toList(); + .flatMap(mdcEntryKey -> extractValue(headers, mdcEntryKey)) + .toList(); } - private static Optional extractValue(final Map headers, + private static Stream extractValue(final Map headers, final CommonMdcEntryKey mdcEntryKey) { - // accessing a key in a HashMap is super fast - return Optional.ofNullable(headers.get(mdcEntryKey.key)); + if (mdcEntryKey == TRACE_PARENT) { + return Optional.ofNullable(headers.get(mdcEntryKey.key)) + .filter(traceParent -> traceParent.charAt(2) == '-' && traceParent.length() == 55) + .map(traceParent -> Stream.of( + // positions defined by https://www.w3.org/TR/trace-context/#traceparent-header-field-values to contain the "trace-id" + MdcEntry.of(TRACE_ID, traceParent.substring(3, 35)), + MdcEntry.of(SPAN_ID, traceParent.substring(36, 52)) + )).stream() + .flatMap(Function.identity()); + } else { + return Optional.ofNullable(headers.get(mdcEntryKey.key)) + .map(value -> MdcEntry.of(mdcEntryKey.key, value)) + .stream(); + } } } diff --git a/policies/service/src/main/resources/logback.xml b/policies/service/src/main/resources/logback.xml index a6fed57a59..a203eb8171 100755 --- a/policies/service/src/main/resources/logback.xml +++ b/policies/service/src/main/resources/logback.xml @@ -16,14 +16,14 @@ - %date{ISO8601} %-5level [%X{correlation-id}][%X{traceparent}] %logger{20} %X{pekkoSource} - %msg%n + %date{ISO8601} %-5level [%X{correlation-id}][%X{traceparent-trace-id}] %logger{20} %X{pekkoSource} - %msg%n System.err - %date{ISO8601} %-5level [%X{correlation-id}][%X{traceparent}] %logger{20} %X{pekkoSource} - %msg%n + %date{ISO8601} %-5level [%X{correlation-id}][%X{traceparent-trace-id}] %logger{20} %X{pekkoSource} - %msg%n ERROR diff --git a/things/service/src/main/resources/logback.xml b/things/service/src/main/resources/logback.xml index a48ca68241..4f6086340b 100755 --- a/things/service/src/main/resources/logback.xml +++ b/things/service/src/main/resources/logback.xml @@ -16,14 +16,14 @@ - %date{ISO8601} %-5level [%X{correlation-id}][%X{traceparent}] %logger{20} %X{pekkoSource} - %msg%n + %date{ISO8601} %-5level [%X{correlation-id}][%X{traceparent-trace-id}] %logger{20} %X{pekkoSource} - %msg%n System.err - %date{ISO8601} %-5level [%X{correlation-id}][%X{traceparent}] %logger{20} %X{pekkoSource} - %msg%n + %date{ISO8601} %-5level [%X{correlation-id}][%X{traceparent-trace-id}] %logger{20} %X{pekkoSource} - %msg%n ERROR diff --git a/thingsearch/service/src/main/resources/logback.xml b/thingsearch/service/src/main/resources/logback.xml index b4665f4b44..bf25257f5e 100755 --- a/thingsearch/service/src/main/resources/logback.xml +++ b/thingsearch/service/src/main/resources/logback.xml @@ -16,14 +16,14 @@ - %date{ISO8601} %-5level [%X{correlation-id}][%X{traceparent}] %logger{20} %X{pekkoSource} - %msg%n + %date{ISO8601} %-5level [%X{correlation-id}][%X{traceparent-trace-id}] %logger{20} %X{pekkoSource} - %msg%n System.err - %date{ISO8601} %-5level [%X{correlation-id}][%X{traceparent}] %logger{20} %X{pekkoSource} - %msg%n + %date{ISO8601} %-5level [%X{correlation-id}][%X{traceparent-trace-id}] %logger{20} %X{pekkoSource} - %msg%n ERROR