Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void onUserFunctionStart(UserFunctionStartInfo info) {
@Override
public void onUserFunctionEnd(UserFunctionEndInfo info) {
if (isStep(info.type()) && info.attempt() != null) {
String outcome = info.succeeded() ? "SUCCEEDED" : "FAILED";
String outcome = info.outcome().name();
System.out.println(String.format(
"{\"plugin\": \"%s\", \"hook\": \"attempt-end\", \"n\": %d, \"outcome\": \"%s\", \"op\": \"%s\"%s}",
prefix, info.attempt(), outcome, info.id(), arnField()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void onUserFunctionEnd(UserFunctionEndInfo info) {
System.out.println(String.format(
"{\"plugin\": \"CONFPLUGIN-HEALTHY\", \"hook\": \"attempt-end\", \"op\": \"%s\", "
+ "\"outcome\": \"%s\"%s}",
info.id(), info.succeeded() ? "SUCCEEDED" : "FAILED", PluginSupport.arnField(executionArn)));
info.id(), info.outcome().name(), PluginSupport.arnField(executionArn)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void onUserFunctionEnd(UserFunctionEndInfo info) {
if (!PluginSupport.isBranch(info.subType())) {
return;
}
String outcome = info.succeeded() ? "SUCCEEDED" : "FAILED";
String outcome = info.outcome().name();
System.out.println(String.format(
"{\"plugin\": \"CONFPLUGIN\", \"hook\": \"fn-end\", \"op\": \"%s\", \"parent\": \"%s\", "
+ "\"outcome\": \"%s\"%s}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void onUserFunctionEnd(UserFunctionEndInfo info) {
if (!PluginSupport.isStep(info.type()) || info.attempt() == null) {
return;
}
String outcome = info.succeeded() ? "SUCCEEDED" : "FAILED";
String outcome = info.outcome().name();
System.out.println(String.format(
"{\"plugin\": \"CONFPLUGIN\", \"hook\": \"attempt-end\", \"n\": %d, \"outcome\": \"%s\", "
+ "\"op\": \"%s\"%s}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
* [PLUGIN] onInvocationStart: requestId=..., durableExecutionArn=..., firstInvocation=true
* [PLUGIN] onOperationStart: name=create-greeting, type=STEP
* [PLUGIN] onUserFunctionStart: name=create-greeting, attempt=1
* [PLUGIN] onUserFunctionEnd: name=create-greeting, succeeded=true
* [PLUGIN] onUserFunctionEnd: name=create-greeting, outcome=SUCCEEDED
* [PLUGIN] onOperationEnd: name=create-greeting
* [PLUGIN] onOperationStart: name=transform, type=STEP
* [PLUGIN] onUserFunctionStart: name=transform, attempt=1
* [PLUGIN] onUserFunctionEnd: name=transform, succeeded=true
* [PLUGIN] onUserFunctionEnd: name=transform, outcome=SUCCEEDED
* [PLUGIN] onOperationEnd: name=transform
* [PLUGIN] onInvocationEnd: status=SUCCEEDED
* </pre>
Expand Down Expand Up @@ -91,9 +91,9 @@ public void onUserFunctionStart(UserFunctionStartInfo info) {
@Override
public void onUserFunctionEnd(UserFunctionEndInfo info) {
System.out.printf(
"[PLUGIN] onUserFunctionEnd: name=%s, succeeded=%s, error=%s%n",
"[PLUGIN] onUserFunctionEnd: name=%s, outcome=%s, error=%s%n",
Comment thread
wangyb-A marked this conversation as resolved.
info.name(),
info.succeeded(),
info.outcome(),
info.error() != null ? info.error().getMessage() : null);
}
}
Expand Down
2 changes: 1 addition & 1 deletion otel-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ Operation and attempt spans link to the Workflow span. `ExecutionOtelPlugin` rev
| `durable.operation.type` | Parent operation type |
| `durable.operation.name` | Parent operation name |
| `durable.attempt.number` | 1-based attempt number |
| `durable.attempt.outcome` | SUCCEEDED or FAILED |
| `durable.attempt.outcome` | SUCCEEDED (span status `OK`), FAILED (`ERROR`), or INCOMPLETE (`UNSET`) |
Comment thread
wangyb-A marked this conversation as resolved.

## Log Correlation (MDC)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,14 +495,19 @@ public void onUserFunctionEnd(UserFunctionEndInfo info) {
var span = attemptSpans.remove(key);
if (span == null) return;

var outcome = info.succeeded() ? "SUCCEEDED" : "FAILED";
span.setAttribute(DURABLE_ATTEMPT_OUTCOME, outcome);

if (!info.succeeded() && info.error() != null) {
span.setStatus(StatusCode.ERROR, info.error().getMessage());
span.recordException(info.error());
} else if (info.succeeded()) {
span.setStatus(StatusCode.OK);
span.setAttribute(DURABLE_ATTEMPT_OUTCOME, info.outcome().name());
Comment thread
wangyb-A marked this conversation as resolved.

switch (info.outcome()) {
case SUCCEEDED -> span.setStatus(StatusCode.OK);
case FAILED -> {
if (info.error() != null) {
span.setStatus(StatusCode.ERROR, info.error().getMessage());
span.recordException(info.error());
}
}
case INCOMPLETE -> {
Comment thread
wangyb-A marked this conversation as resolved.
// An incomplete user function is expected when the durable execution suspends.
}
}

endSpan(span, info.endTimestamp());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,14 +523,19 @@ public void onUserFunctionEnd(UserFunctionEndInfo info) {
var span = attemptSpans.remove(key);
if (span == null) return;

var outcome = info.succeeded() ? "SUCCEEDED" : "FAILED";
span.setAttribute(DURABLE_ATTEMPT_OUTCOME, outcome);

if (!info.succeeded() && info.error() != null) {
span.setStatus(StatusCode.ERROR, info.error().getMessage());
span.recordException(info.error());
} else if (info.succeeded()) {
span.setStatus(StatusCode.OK);
span.setAttribute(DURABLE_ATTEMPT_OUTCOME, info.outcome().name());
Comment thread
zhongkechen marked this conversation as resolved.

switch (info.outcome()) {
case SUCCEEDED -> span.setStatus(StatusCode.OK);
case FAILED -> {
if (info.error() != null) {
span.setStatus(StatusCode.ERROR, info.error().getMessage());
span.recordException(info.error());
}
}
case INCOMPLETE -> {
// An incomplete user function is expected when the durable execution suspends.
}
}

if (info.endTimestamp() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import software.amazon.lambda.durable.execution.SuspendExecutionException;
import software.amazon.lambda.durable.plugin.*;

class ExecutionOtelPluginTest {
Expand Down Expand Up @@ -459,7 +460,17 @@ void attemptSpan_childOfOperation_linkedToInvocation() {
plugin.onUserFunctionStart(
new UserFunctionStartInfo("op-1", "compute", "STEP", "Step", null, Instant.now(), false, 1));
plugin.onUserFunctionEnd(new UserFunctionEndInfo(
"op-1", "compute", "STEP", "Step", null, Instant.now(), Instant.now(), false, 1, true, null));
"op-1",
"compute",
"STEP",
"Step",
null,
Instant.now(),
Instant.now(),
false,
1,
UserFunctionOutcome.SUCCEEDED,
null));
plugin.onOperationEnd(new OperationEndInfo(
"op-1",
"compute",
Expand Down Expand Up @@ -500,7 +511,17 @@ void attemptSpan_carriesOperationSubtype() {
plugin.onUserFunctionStart(
new UserFunctionStartInfo("op-1", "process-order", "STEP", "Step", null, Instant.now(), false, 1));
plugin.onUserFunctionEnd(new UserFunctionEndInfo(
"op-1", "process-order", "STEP", "Step", null, Instant.now(), Instant.now(), false, 1, true, null));
"op-1",
"process-order",
"STEP",
"Step",
null,
Instant.now(),
Instant.now(),
false,
1,
UserFunctionOutcome.SUCCEEDED,
null));
plugin.onInvocationEnd(new InvocationEndInfo("req-1", ARN, true, InvocationStatus.SUCCEEDED, null));

var attemptSpan = spanExporter.getFinishedSpanItems().stream()
Expand Down Expand Up @@ -574,7 +595,7 @@ void userFunctionFailure_setsErrorOnAttemptSpan() {
Instant.now(),
false,
1,
false,
UserFunctionOutcome.FAILED,
new RuntimeException("step failed")));
plugin.onInvocationEnd(new InvocationEndInfo("req-1", ARN, true, InvocationStatus.FAILED, null));

Expand All @@ -591,7 +612,17 @@ void userFunctionSuccess_setsOkOnAttemptSpan() {
plugin.onUserFunctionStart(
new UserFunctionStartInfo("op-1", "compute", "STEP", "Step", null, Instant.now(), false, 1));
plugin.onUserFunctionEnd(new UserFunctionEndInfo(
"op-1", "compute", "STEP", "Step", null, Instant.now(), Instant.now(), false, 1, true, null));
"op-1",
"compute",
"STEP",
"Step",
null,
Instant.now(),
Instant.now(),
false,
1,
UserFunctionOutcome.SUCCEEDED,
null));
plugin.onInvocationEnd(new InvocationEndInfo("req-1", ARN, true, InvocationStatus.SUCCEEDED, null));

var attemptSpan = spanExporter.getFinishedSpanItems().stream()
Expand All @@ -601,6 +632,31 @@ void userFunctionSuccess_setsOkOnAttemptSpan() {
assertEquals(StatusCode.OK, attemptSpan.getStatus().getStatusCode());
}

@Test
void userFunctionIncomplete_leavesAttemptSpanUnset() {
plugin.onInvocationStart(new InvocationInfo("req-1", ARN, true, Instant.now()));
plugin.onUserFunctionStart(
new UserFunctionStartInfo("op-1", "waiting", "STEP", "Step", null, Instant.now(), false, 1));
plugin.onUserFunctionEnd(new UserFunctionEndInfo(
"op-1",
"waiting",
"STEP",
"Step",
null,
Instant.now(),
Instant.now(),
false,
1,
UserFunctionOutcome.INCOMPLETE,
new SuspendExecutionException()));
plugin.onInvocationEnd(new InvocationEndInfo("req-1", ARN, true, InvocationStatus.PENDING, null));

var attemptSpan = spanByName(spanExporter.getFinishedSpanItems(), "waiting attempt 1");
assertEquals(StatusCode.UNSET, attemptSpan.getStatus().getStatusCode());
assertEquals("INCOMPLETE", attemptSpan.getAttributes().get(AttributeKey.stringKey("durable.attempt.outcome")));
assertTrue(attemptSpan.getEvents().isEmpty());
}

@Test
void operationSuccess_setsOkOnOperationSpan() {
plugin.onInvocationStart(new InvocationInfo("req-1", ARN, true, Instant.now()));
Expand Down
Loading
Loading