diff --git a/docs/sdk-reference/observability/plugins.md b/docs/sdk-reference/observability/plugins.md index a99eab6..13df7d3 100644 --- a/docs/sdk-reference/observability/plugins.md +++ b/docs/sdk-reference/observability/plugins.md @@ -141,11 +141,15 @@ snapshot of all operations. === "Python" - This hook is a work in progress and is not yet available in the Python SDK. + ```python + --8<-- "examples/python/sdk-reference/plugins/checkpoint-change-hook.py" + ``` === "Java" - This hook is a work in progress and is not yet available in the Java SDK. + ```java + --8<-- "examples/java/sdk-reference/plugins/checkpoint-change-hook.java" + ``` ## Use a plugin diff --git a/examples/java/sdk-reference/plugins/checkpoint-change-hook.java b/examples/java/sdk-reference/plugins/checkpoint-change-hook.java new file mode 100644 index 0000000..53ea6bb --- /dev/null +++ b/examples/java/sdk-reference/plugins/checkpoint-change-hook.java @@ -0,0 +1,4 @@ +@Override +public void onOperationChange(OperationChangeInfo info) { + System.out.println("operations changed, ids: " + info.updatedOperations().keySet()); +} diff --git a/examples/java/sdk-reference/plugins/complete-plugin.java b/examples/java/sdk-reference/plugins/complete-plugin.java index 93d634a..af1cad6 100644 --- a/examples/java/sdk-reference/plugins/complete-plugin.java +++ b/examples/java/sdk-reference/plugins/complete-plugin.java @@ -3,6 +3,7 @@ import software.amazon.lambda.durable.plugin.InvocationEndInfo; import software.amazon.lambda.durable.plugin.OperationInfo; import software.amazon.lambda.durable.plugin.OperationEndInfo; +import software.amazon.lambda.durable.plugin.OperationChangeInfo; import software.amazon.lambda.durable.plugin.UserFunctionStartInfo; import software.amazon.lambda.durable.plugin.UserFunctionEndInfo; @@ -29,6 +30,11 @@ public void onOperationEnd(OperationEndInfo info) { System.out.println("operation " + info.name() + " end, error: " + info.error()); } + @Override + public void onOperationChange(OperationChangeInfo info) { + System.out.println("operations changed, ids: " + info.updatedOperations().keySet()); + } + @Override public void onUserFunctionStart(UserFunctionStartInfo info) { System.out.println("user function " + info.name() + " start, attempt: " + info.attempt()); diff --git a/examples/python/sdk-reference/plugins/checkpoint-change-hook.py b/examples/python/sdk-reference/plugins/checkpoint-change-hook.py new file mode 100644 index 0000000..021c3ad --- /dev/null +++ b/examples/python/sdk-reference/plugins/checkpoint-change-hook.py @@ -0,0 +1,2 @@ +def on_operation_change(self, info: OperationChangeInfo) -> None: + print("operations changed", "ids:", list(info.updated_operations.keys())) diff --git a/examples/python/sdk-reference/plugins/complete-plugin.py b/examples/python/sdk-reference/plugins/complete-plugin.py index 727b953..7680953 100644 --- a/examples/python/sdk-reference/plugins/complete-plugin.py +++ b/examples/python/sdk-reference/plugins/complete-plugin.py @@ -4,6 +4,7 @@ InvocationEndInfo, OperationStartInfo, OperationEndInfo, + OperationChangeInfo, UserFunctionStartInfo, UserFunctionEndInfo, ) @@ -22,6 +23,9 @@ def on_operation_start(self, info: OperationStartInfo) -> None: def on_operation_end(self, info: OperationEndInfo) -> None: print(f"operation {info.name} end, status: {info.status}, error: {info.error}") + def on_operation_change(self, info: OperationChangeInfo) -> None: + print("operations changed", "ids:", list(info.updated_operations.keys())) + def on_user_function_start(self, info: UserFunctionStartInfo) -> None: print(f"user function {info.name} start, attempt: {info.attempt}") diff --git a/examples/typescript/sdk-reference/plugins/complete-plugin.ts b/examples/typescript/sdk-reference/plugins/complete-plugin.ts index c1472bc..6b5a501 100644 --- a/examples/typescript/sdk-reference/plugins/complete-plugin.ts +++ b/examples/typescript/sdk-reference/plugins/complete-plugin.ts @@ -27,6 +27,10 @@ export const examplePlugin: DurableInstrumentationPlugin = { console.log(`operation ${info.name} end, status: ${info.status}, error: ${info.error}`); }, + async onOperationChange(info: OperationChangeInfo): Promise { + console.log(`operations changed, ids: ${Object.keys(info.updatedOperations)}`); + }, + async onOperationAttemptStart(info: AttemptInfo): Promise { console.log(`attempt ${info.name} start, attempt: ${info.attempt}`); }, @@ -53,10 +57,6 @@ export const examplePlugin: DurableInstrumentationPlugin = { return fn(); }, - async onOperationChange(info: OperationChangeInfo): Promise { - console.log(`operations changed, ids: ${Object.keys(info.updatedOperations)}`); - }, - enrichLogContext(): Record { return { service: "orders" }; },