diff --git a/sdk-core/build.gradle.kts b/sdk-core/build.gradle.kts index 7b87e852..13dfbe96 100644 --- a/sdk-core/build.gradle.kts +++ b/sdk-core/build.gradle.kts @@ -17,9 +17,6 @@ dependencies { implementation(coreLibs.grpc.protobuf) implementation(coreLibs.log4j.api) - // We don't want a hard-dependency on it - compileOnly(coreLibs.log4j.core) - implementation(platform(coreLibs.opentelemetry.bom)) implementation(coreLibs.opentelemetry.api) implementation(coreLibs.opentelemetry.semconv) diff --git a/sdk-core/src/main/java/dev/restate/sdk/core/GrpcContextDataProvider.java b/sdk-core/src/main/java/dev/restate/sdk/core/GrpcContextDataProvider.java deleted file mode 100644 index 900257e9..00000000 --- a/sdk-core/src/main/java/dev/restate/sdk/core/GrpcContextDataProvider.java +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH -// -// This file is part of the Restate Java SDK, -// which is released under the MIT license. -// -// You can find a copy of the license in file LICENSE in the root -// directory of this repository or package, or at -// https://github.com/restatedev/sdk-java/blob/main/LICENSE -package dev.restate.sdk.core; - -import dev.restate.sdk.common.InvocationId; -import java.util.Map; -import org.apache.logging.log4j.core.util.ContextDataProvider; - -/** - * Log4j2 ContextDataProvider inferring context from the Grpc context. - * - *

This is used to propagate the context to the user code, such that log statements from the user - * will contain the restate logging context variables. - */ -public class GrpcContextDataProvider implements ContextDataProvider { - @Override - public Map supplyContextData() { - InvocationId invocationId = InvocationId.INVOCATION_ID_KEY.get(); - String serviceMethod = RestateGrpcServer.SERVICE_METHOD.get(); - - // We use Map.of constructors to avoid allocating hashmaps - if (invocationId == null && serviceMethod == null) { - return Map.of(); - } else if (invocationId == null) { - return Map.of(RestateGrpcServer.LoggingContextSetter.SERVICE_METHOD_KEY, serviceMethod); - } else { - return Map.of( - RestateGrpcServer.LoggingContextSetter.INVOCATION_ID_KEY, - invocationId.toString(), - RestateGrpcServer.LoggingContextSetter.SERVICE_METHOD_KEY, - serviceMethod); - } - } -} diff --git a/sdk-core/src/main/resources/META-INF/services/org.apache.logging.log4j.core.util.ContextDataProvider b/sdk-core/src/main/resources/META-INF/services/org.apache.logging.log4j.core.util.ContextDataProvider deleted file mode 100644 index bbed00cc..00000000 --- a/sdk-core/src/main/resources/META-INF/services/org.apache.logging.log4j.core.util.ContextDataProvider +++ /dev/null @@ -1 +0,0 @@ -dev.restate.sdk.core.GrpcContextDataProvider \ No newline at end of file diff --git a/sdk-lambda/src/main/java/dev/restate/sdk/lambda/BaseRestateLambdaHandler.java b/sdk-lambda/src/main/java/dev/restate/sdk/lambda/BaseRestateLambdaHandler.java index 7ed1d690..d8e33193 100644 --- a/sdk-lambda/src/main/java/dev/restate/sdk/lambda/BaseRestateLambdaHandler.java +++ b/sdk-lambda/src/main/java/dev/restate/sdk/lambda/BaseRestateLambdaHandler.java @@ -12,6 +12,7 @@ import com.amazonaws.services.lambda.runtime.RequestHandler; import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent; +import org.apache.logging.log4j.CloseableThreadContext; /** * Base implementation of a Lambda handler to execute restate services @@ -27,6 +28,8 @@ public abstract class BaseRestateLambdaHandler implements RequestHandler { + private static final String AWS_REQUEST_ID = "AWSRequestId"; + private final RestateLambdaEndpoint restateLambdaEndpoint; protected BaseRestateLambdaHandler() { @@ -41,6 +44,8 @@ protected BaseRestateLambdaHandler() { @Override public APIGatewayProxyResponseEvent handleRequest( APIGatewayProxyRequestEvent input, Context context) { - return restateLambdaEndpoint.handleRequest(input, context); + try (var requestId = CloseableThreadContext.put(AWS_REQUEST_ID, context.getAwsRequestId())) { + return restateLambdaEndpoint.handleRequest(input, context); + } } }