Skip to content

[feature] add an optional stepContext parameter#130

Merged
zhongkechen merged 10 commits intomainfrom
step-context
Feb 27, 2026
Merged

[feature] add an optional stepContext parameter#130
zhongkechen merged 10 commits intomainfrom
step-context

Conversation

@zhongkechen
Copy link
Contributor

@zhongkechen zhongkechen commented Feb 27, 2026

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Issue Link, if available

Add StepContext #80

Description

Add an optional stepContext to the user provided step function, which allows users to get the logger and additional execution context from it. Now any logger from whichever context behaves exactly the same.

        var greeting = context.step("create-greeting", String.class, ctx -> {
            ctx.getLogger().info("Creating greeting message");
            return "Hello, " + input.getName();
        });

equivalent to

        var greeting = context.step("create-greeting", String.class, () -> {
            context.getLogger().info("Creating greeting message");
            return "Hello, " + input.getName();
        });

Demo/Screenshots

step logger

{
    "@timestamp": "2026-02-27T00:25:46.759Z",
    "ecs.version": "1.2.0",
    "log.level": "INFO",
    "message": "Transforming greeting to uppercase",
    "process.thread.name": "durable-exec-16",
    "log.logger": "software.amazon.lambda.durable.DurableContext",
    "attempt": "0",
    "durableExecutionArn": "arn:aws:lambda:us-east-2:961306377283:function:logging-example:$LATEST/durable-execution/6a56c3ef-4a07-4ea1-8500-82bcfe388859/cb7be3f9-3b5a-31bc-8797-9ba38d44055a",
    "operationId": "2",
    "operationName": "transform",
    "requestId": "da78b44c-d811-4431-ad27-1280d6d1c2c8"
}

execution logger:

{
    "@timestamp": "2026-02-27T00:25:46.846Z",
    "ecs.version": "1.2.0",
    "log.level": "INFO",
    "message": "Completed processing, result: HELLO, WORLD!",
    "process.thread.name": "durable-exec-15",
    "log.logger": "software.amazon.lambda.durable.DurableContext",
    "durableExecutionArn": "arn:aws:lambda:us-east-2:961306377283:function:logging-example:$LATEST/durable-execution/6a56c3ef-4a07-4ea1-8500-82bcfe388859/cb7be3f9-3b5a-31bc-8797-9ba38d44055a",
    "requestId": "da78b44c-d811-4431-ad27-1280d6d1c2c8"
}
  • Updated operations to use DurableContext parameter
  • Made root context id consistent ("Root" -> null)

Checklist

  • I have filled out every section of the PR template
  • I have thoroughly tested this change

Testing

Unit Tests

Have unit tests been written for these changes? Updated

Integration Tests

Have integration tests been written for these changes? Updated

Examples

Has a new example been added for the change? (if applicable) Updated

@zhongkechen zhongkechen marked this pull request as ready for review February 27, 2026 00:39
@Override
public String handleRequest(Object input, DurableContext context) {
// Step 1: Record start time
startTime = context.step("record-start-time", Instant.class, Instant::now);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though the new parameter is optional, it's still breaking some edge cases like this.

phipag
phipag previously approved these changes Feb 27, 2026
Copy link
Contributor

@phipag phipag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

ParidelPooya
ParidelPooya previously approved these changes Feb 27, 2026
@zhongkechen zhongkechen merged commit ea5c08e into main Feb 27, 2026
10 checks passed
@zhongkechen zhongkechen deleted the step-context branch February 27, 2026 21:28
nvasiu pushed a commit to nvasiu/aws-durable-execution-sdk-java that referenced this pull request Feb 27, 2026
* add an optional stepContext parameter

* rename parent context id to context id

* rename parameter

* update loggin example

* add some comments

* update DurableLogger to use StepContext class

* update docs and examples to use child context logger

* add more javadoc and minor code cleanups

* add more comments and remove registration from context

* fix of test cases
@wangyb-A wangyb-A mentioned this pull request Feb 28, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants