diff --git a/otel-plugin/src/main/java/software/amazon/lambda/durable/otel/ExecutionOtelPlugin.java b/otel-plugin/src/main/java/software/amazon/lambda/durable/otel/ExecutionOtelPlugin.java index d0a156579..92236d4f0 100644 --- a/otel-plugin/src/main/java/software/amazon/lambda/durable/otel/ExecutionOtelPlugin.java +++ b/otel-plugin/src/main/java/software/amazon/lambda/durable/otel/ExecutionOtelPlugin.java @@ -440,6 +440,9 @@ public void onUserFunctionStart(UserFunctionStartInfo info) { if (info.name() != null) { spanBuilder.setAttribute(DURABLE_OPERATION_NAME, info.name()); } + if (info.subType() != null) { + spanBuilder.setAttribute(DURABLE_OPERATION_SUBTYPE, info.subType()); + } if (info.attempt() != null) { spanBuilder.setAttribute(DURABLE_ATTEMPT_NUMBER, info.attempt().longValue()); } diff --git a/otel-plugin/src/test/java/software/amazon/lambda/durable/otel/ExecutionOtelPluginTest.java b/otel-plugin/src/test/java/software/amazon/lambda/durable/otel/ExecutionOtelPluginTest.java index 6936065c2..a693be2e4 100644 --- a/otel-plugin/src/test/java/software/amazon/lambda/durable/otel/ExecutionOtelPluginTest.java +++ b/otel-plugin/src/test/java/software/amazon/lambda/durable/otel/ExecutionOtelPluginTest.java @@ -332,6 +332,25 @@ void attemptSpan_childOfOperation_linkedToInvocation() { "Attempt span must carry a link to the invocation span"); } + @Test + void attemptSpan_carriesOperationSubtype() { + plugin.onInvocationStart(new InvocationInfo("req-1", ARN, true, Instant.now())); + 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)); + plugin.onInvocationEnd(new InvocationEndInfo("req-1", ARN, true, InvocationStatus.SUCCEEDED, null)); + + var attemptSpan = spanExporter.getFinishedSpanItems().stream() + .filter(s -> s.getName().contains("process-order")) + .findFirst() + .orElseThrow(); + assertEquals( + "Step", + attemptSpan.getAttributes().get(AttributeKey.stringKey("durable.operation.subtype")), + "Attempt span should carry durable.operation.subtype from the operation"); + } + @Test void childOperation_parentedToParentOperationSpan() { plugin.onInvocationStart(new InvocationInfo("req-1", ARN, true, Instant.now()));