-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45fc2d0
commit b8f4bd3
Showing
13 changed files
with
100 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
sdk-core/src/main/java/dev/restate/sdk/core/RestateContextDataProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// 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.syscalls.InvocationHandler; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.apache.logging.log4j.core.util.ContextDataProvider; | ||
|
||
/** | ||
* Log4j2 {@link ContextDataProvider} inferring context from {@link | ||
* InvocationHandler#SYSCALLS_THREAD_LOCAL}. | ||
* | ||
* <p>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 RestateContextDataProvider implements ContextDataProvider { | ||
@Override | ||
public Map<String, String> supplyContextData() { | ||
SyscallsInternal syscalls = (SyscallsInternal) InvocationHandler.SYSCALLS_THREAD_LOCAL.get(); | ||
if (syscalls == null) { | ||
return Collections.emptyMap(); | ||
} | ||
|
||
// We can't use the immutable MapN implementation from Map.of because of | ||
// https://github.com/apache/logging-log4j2/issues/2098 | ||
HashMap<String, String> m = new HashMap<>(3); | ||
m.put( | ||
RestateEndpoint.LoggingContextSetter.INVOCATION_ID_KEY, | ||
syscalls.request().invocationId().toString()); | ||
m.put( | ||
RestateEndpoint.LoggingContextSetter.INVOCATION_TARGET_KEY, | ||
syscalls.getFullyQualifiedMethodName()); | ||
m.put( | ||
RestateEndpoint.LoggingContextSetter.INVOCATION_STATUS_KEY, | ||
syscalls.getInvocationState().toString()); | ||
return m; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...c/main/resources/META-INF/services/org.apache.logging.log4j.core.util.ContextDataProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dev.restate.sdk.core.RestateContextDataProvider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters