generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 4
feat(sdk): add configureLogger method with modeAware option #253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 0 additions & 25 deletions
25
.../aws-durable-execution-sdk-js-examples/src/examples/logger-example/logger-example.test.ts
This file was deleted.
Oops, something went wrong.
70 changes: 0 additions & 70 deletions
70
packages/aws-durable-execution-sdk-js-examples/src/examples/logger-example/logger-example.ts
This file was deleted.
Oops, something went wrong.
132 changes: 132 additions & 0 deletions
132
...ion-sdk-js-examples/src/examples/logger-test/after-callback/logger-after-callback.test.ts
This file contains hidden or 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,132 @@ | ||
| import { handler } from "./logger-after-callback"; | ||
| import { createTests } from "../../../utils/test-helper"; | ||
| import { | ||
| InvocationType, | ||
| WaitingOperationStatus, | ||
| } from "@aws/durable-execution-sdk-js-testing"; | ||
| import * as fs from "fs"; | ||
| import * as path from "path"; | ||
| import * as os from "os"; | ||
| import { randomUUID } from "crypto"; | ||
|
|
||
| createTests({ | ||
| name: "logger-after-callback", | ||
| functionName: "logger-after-callback", | ||
| handler, | ||
| invocationType: InvocationType.Event, | ||
| tests: (runner, isCloud) => { | ||
| if (!isCloud) { | ||
| it("should log correctly with modeAware=true", async () => { | ||
| const logFilePath = path.join( | ||
| os.tmpdir(), | ||
| `logger-test-${randomUUID()}.log`, | ||
| ); | ||
|
|
||
| if (fs.existsSync(logFilePath)) { | ||
| fs.unlinkSync(logFilePath); | ||
| } | ||
|
|
||
| try { | ||
| const executionPromise = runner.run({ | ||
| payload: { logFilePath, modeAware: true }, | ||
| }); | ||
|
|
||
| const callbackOp = runner.getOperationByIndex(0); | ||
| await callbackOp.waitForData(WaitingOperationStatus.STARTED); | ||
| await callbackOp.sendCallbackSuccess("test-result"); | ||
|
|
||
| const execution = await executionPromise; | ||
|
|
||
| const result = execution.getResult() as any; | ||
| expect(result.message).toBe("Success"); | ||
| expect(result.callbackId).toBeDefined(); | ||
| expect(result.result).toBe("test-result"); | ||
|
|
||
| const logContent = fs.readFileSync(logFilePath, "utf-8"); | ||
| const logLines = logContent | ||
| .trim() | ||
| .split("\n") | ||
| .map((line) => JSON.parse(line)); | ||
|
|
||
| const beforeCallbackLogs = logLines.filter( | ||
| (log) => log.message === "Before createCallback", | ||
| ); | ||
| const afterCallbackLogs = logLines.filter( | ||
| (log) => log.message === "After createCallback", | ||
| ); | ||
|
|
||
| // With modeAware: true: | ||
| // - "Before createCallback" appears once (execution mode only, suppressed during replay) | ||
| // - "After createCallback" appears once (after callback resolves, in execution mode) | ||
| expect(beforeCallbackLogs.length).toBe(1); | ||
| expect(afterCallbackLogs.length).toBe(1); | ||
| } finally { | ||
| if (fs.existsSync(logFilePath)) { | ||
| fs.unlinkSync(logFilePath); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| it("should log correctly with modeAware=false", async () => { | ||
| const logFilePath = path.join( | ||
| os.tmpdir(), | ||
| `logger-test-${randomUUID()}.log`, | ||
| ); | ||
|
|
||
| if (fs.existsSync(logFilePath)) { | ||
| fs.unlinkSync(logFilePath); | ||
| } | ||
|
|
||
| try { | ||
| const executionPromise = runner.run({ | ||
| payload: { logFilePath, modeAware: false }, | ||
| }); | ||
|
|
||
| const callbackOp = runner.getOperationByIndex(0); | ||
| await callbackOp.waitForData(WaitingOperationStatus.STARTED); | ||
| await callbackOp.sendCallbackSuccess("test-result"); | ||
|
|
||
| const execution = await executionPromise; | ||
|
|
||
| const result = execution.getResult() as any; | ||
| expect(result.message).toBe("Success"); | ||
|
|
||
| const logContent = fs.readFileSync(logFilePath, "utf-8"); | ||
| const logLines = logContent | ||
| .trim() | ||
| .split("\n") | ||
| .map((line) => JSON.parse(line)); | ||
|
|
||
| const beforeCallbackLogs = logLines.filter( | ||
| (log) => log.message === "Before createCallback", | ||
| ); | ||
| const afterCallbackLogs = logLines.filter( | ||
| (log) => log.message === "After createCallback", | ||
| ); | ||
|
|
||
| // With modeAware: false: | ||
| // - "Before createCallback" appears twice (execution + replay) | ||
| // - "After createCallback" appears once (after callback resolves) | ||
| expect(beforeCallbackLogs.length).toBe(2); | ||
| expect(afterCallbackLogs.length).toBe(1); | ||
| } finally { | ||
| if (fs.existsSync(logFilePath)) { | ||
| fs.unlinkSync(logFilePath); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| it("should execute successfully", async () => { | ||
| const executionPromise = runner.run(); | ||
|
|
||
| const callbackOp = runner.getOperationByIndex(0); | ||
| await callbackOp.waitForData(WaitingOperationStatus.STARTED); | ||
| await callbackOp.sendCallbackSuccess("test-result"); | ||
|
|
||
| const execution = await executionPromise; | ||
| const result = execution.getResult() as any; | ||
| expect(result.message).toBe("Success"); | ||
| }); | ||
| }, | ||
| }); | ||
70 changes: 70 additions & 0 deletions
70
...xecution-sdk-js-examples/src/examples/logger-test/after-callback/logger-after-callback.ts
This file contains hidden or 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,70 @@ | ||
| import { withDurableExecution, Logger } from "@aws/durable-execution-sdk-js"; | ||
| import { ExampleConfig } from "../../../types"; | ||
| import * as fs from "fs"; | ||
|
|
||
| export const config: ExampleConfig = { | ||
| name: "Logger After Callback", | ||
| description: "Test logger mode switching after createCallback operation", | ||
| }; | ||
|
|
||
| interface LoggerTestEvent { | ||
| logFilePath?: string; | ||
| modeAware?: boolean; | ||
| } | ||
|
|
||
| export const handler = withDurableExecution( | ||
| async (event: LoggerTestEvent, context) => { | ||
| if (event.logFilePath) { | ||
| const fileLogger: Logger = { | ||
| log: (level, message, data) => { | ||
| fs.appendFileSync( | ||
| event.logFilePath!, | ||
| JSON.stringify({ level, message, data }) + "\n", | ||
| ); | ||
| }, | ||
| info: (message, data) => { | ||
| fs.appendFileSync( | ||
| event.logFilePath!, | ||
| JSON.stringify({ level: "info", message, data }) + "\n", | ||
| ); | ||
| }, | ||
| error: (message, error, data) => { | ||
| fs.appendFileSync( | ||
| event.logFilePath!, | ||
| JSON.stringify({ level: "error", message, error, data }) + "\n", | ||
| ); | ||
| }, | ||
| warn: (message, data) => { | ||
| fs.appendFileSync( | ||
| event.logFilePath!, | ||
| JSON.stringify({ level: "warn", message, data }) + "\n", | ||
| ); | ||
| }, | ||
| debug: (message, data) => { | ||
| fs.appendFileSync( | ||
| event.logFilePath!, | ||
| JSON.stringify({ level: "debug", message, data }) + "\n", | ||
| ); | ||
| }, | ||
| }; | ||
|
|
||
| context.configureLogger({ | ||
| customLogger: fileLogger, | ||
| modeAware: event.modeAware ?? true, | ||
| }); | ||
| } else { | ||
| context.configureLogger({ modeAware: event.modeAware ?? true }); | ||
| } | ||
|
|
||
| context.logger.info("Before createCallback"); | ||
|
|
||
| const [callbackPromise, callbackId] = | ||
| await context.createCallback<string>(); | ||
|
|
||
| const result = await callbackPromise; | ||
|
|
||
| context.logger.info("After createCallback"); | ||
|
|
||
| return { message: "Success", callbackId, result }; | ||
| }, | ||
| ); |
60 changes: 60 additions & 0 deletions
60
...e-execution-sdk-js-examples/src/examples/logger-test/after-wait/logger-after-wait.test.ts
This file contains hidden or 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,60 @@ | ||
| import { handler } from "./logger-after-wait"; | ||
| import { createTests } from "../../../utils/test-helper"; | ||
| import * as fs from "fs"; | ||
| import * as path from "path"; | ||
| import * as os from "os"; | ||
| import { randomUUID } from "crypto"; | ||
|
|
||
| createTests({ | ||
| name: "logger-after-wait", | ||
| functionName: "logger-after-wait", | ||
| handler, | ||
| tests: (runner, isCloud) => { | ||
| if (!isCloud) { | ||
| it("should log after wait in execution mode with modeAware=true", async () => { | ||
| const logFilePath = path.join( | ||
| os.tmpdir(), | ||
| `logger-test-${randomUUID()}.log`, | ||
| ); | ||
|
|
||
| if (fs.existsSync(logFilePath)) { | ||
| fs.unlinkSync(logFilePath); | ||
| } | ||
|
|
||
| try { | ||
| const execution = await runner.run({ | ||
| payload: { logFilePath, modeAware: true }, | ||
| }); | ||
|
|
||
| expect(execution.getResult()).toEqual({ message: "Success" }); | ||
|
|
||
| const logContent = fs.readFileSync(logFilePath, "utf-8"); | ||
| const logLines = logContent | ||
| .trim() | ||
| .split("\n") | ||
| .map((line) => JSON.parse(line)); | ||
|
|
||
| const beforeWaitLogs = logLines.filter( | ||
| (log) => log.message === "Before wait", | ||
| ); | ||
| const afterWaitLogs = logLines.filter( | ||
| (log) => log.message === "After wait", | ||
| ); | ||
|
|
||
| // With modeAware: true, both logs appear once (execution mode only) | ||
| expect(beforeWaitLogs.length).toBe(1); | ||
| expect(afterWaitLogs.length).toBe(1); | ||
| } finally { | ||
| if (fs.existsSync(logFilePath)) { | ||
| fs.unlinkSync(logFilePath); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| it("should execute successfully", async () => { | ||
| const execution = await runner.run(); | ||
| expect(execution.getResult()).toEqual({ message: "Success" }); | ||
| }); | ||
| }, | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.