The step {@code charge} throws {@code card declined}. The retry strategy declines, so the step fails on its first + * attempt. The handler catches the step error and throws {@code payment failed} with the step error as its cause. So + * the execution fails and the exported record carries an {@code error} on the execution and on + * {@code operationsByName.charge}. Error names and cause depth differ per SDK by design, so telemetry-2 asserts only + * that each error is an object. It pins the messages {@code card declined} and {@code payment failed} through the core + * execution-result and history sections. Do not change them. + * + *
The handler configures the telemetry plugin exactly as {@link Telemetry1Success}. It constructs no record and
+ * calls no exporter method. The plugin builds and exports the record.
+ */
+public final class Telemetry2Failure extends DurableHandler Every handler in this module exports to the same log group with the same plugin settings. The runner reads that
+ * log group and compares the record to the requirement. A handler with different settings would produce a record the
+ * runner cannot match. So the settings live here once and each handler calls these methods.
+ */
+final class TelemetryConformanceConfig {
+
+ /** Environment variable that names the log group the runner reads. */
+ static final String LOG_GROUP_ENV = "TELEMETRY_LOG_GROUP_NAME";
+
+ private TelemetryConformanceConfig() {}
+
+ /**
+ * Validates the configured log group name.
+ *
+ * The deployed function must export to the log group the runner reads. A missing name would produce a function
+ * that exports nowhere, and the runner would time out instead of reporting a configuration error. So this method
+ * rejects a null or blank name, and the caller fails class initialization.
+ *
+ * @param logGroupName the value of {@link #LOG_GROUP_ENV}, possibly null
+ * @return the same value when it is set and not blank
+ * @throws IllegalStateException when the value is null or blank
+ */
+ static String requireLogGroupName(String logGroupName) {
+ if (logGroupName == null || logGroupName.isBlank()) {
+ throw new IllegalStateException(LOG_GROUP_ENV + " must be set");
+ }
+ return logGroupName;
+ }
+
+ /**
+ * Builds the telemetry plugin settings: one CloudWatch Logs exporter for the given log group, emit on completion,
+ * sample every execution, top-level operation detail, input and output included.
+ *
+ * This method constructs no client. The exporter creates its CloudWatch Logs client on first export, and the
+ * settings object is a plain value. So a unit test can call it with no credentials and no network.
+ *
+ * @param logGroupName the log group the exporter writes to
+ * @return the plugin settings every handler in this module uses
+ */
+ static DurableExecutionTelemetryConfig telemetryConfig(String logGroupName) {
+ return DurableExecutionTelemetryConfig.builder()
+ .addExporter(CloudWatchLogsExporter.builder()
+ .logGroupName(logGroupName)
+ .build())
+ .emitMode(DurableExecutionTelemetryConfig.EmitMode.ON_COMPLETE)
+ .samplingRate(1.0)
+ .operationDetail(DurableExecutionTelemetryConfig.OperationDetail.TOP_LEVEL)
+ .content(ContentConfig.builder().input(true).output(true).build())
+ .build();
+ }
+
+ /**
+ * Builds the handler configuration with the telemetry plugin from {@link #telemetryConfig(String)}.
+ *
+ * {@code DurableConfig.build()} constructs the default Lambda client, and that constructor sends one warm-up
+ * request. So this method is for the deployed handler only. Tests check {@link #telemetryConfig(String)} instead.
+ *
+ * @param logGroupName the log group the exporter writes to
+ * @return the configuration a telemetry conformance handler returns from {@code createConfiguration()}
+ */
+ static DurableConfig durableConfig(String logGroupName) {
+ return DurableConfig.builder()
+ .withPlugins(DurableExecutionTelemetry.durableExecutionTelemetry(telemetryConfig(logGroupName)))
+ .build();
+ }
+}
diff --git a/conformance-tests-telemetry/src/test/java/software/amazon/lambda/durable/conformance/telemetry/TelemetryConformanceConfigTest.java b/conformance-tests-telemetry/src/test/java/software/amazon/lambda/durable/conformance/telemetry/TelemetryConformanceConfigTest.java
new file mode 100644
index 000000000..df757f759
--- /dev/null
+++ b/conformance-tests-telemetry/src/test/java/software/amazon/lambda/durable/conformance/telemetry/TelemetryConformanceConfigTest.java
@@ -0,0 +1,62 @@
+// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+// SPDX-License-Identifier: Apache-2.0
+package software.amazon.lambda.durable.conformance.telemetry;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static software.amazon.lambda.durable.telemetry.DurableExecutionTelemetryConfig.EmitMode.ON_COMPLETE;
+import static software.amazon.lambda.durable.telemetry.DurableExecutionTelemetryConfig.OperationDetail.TOP_LEVEL;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.NullSource;
+import org.junit.jupiter.params.provider.ValueSource;
+import software.amazon.lambda.durable.telemetry.exporters.CloudWatchLogsExporter;
+
+/**
+ * Tests the shared handler setup through the helper with explicit values.
+ *
+ * The handlers read the log group name in a static initializer, so the guard is tested here, not through the
+ * environment. {@code durableConfig} builds a {@code DurableConfig}, whose constructor creates the default Lambda
+ * client and sends a warm-up request. So these tests check {@code telemetryConfig}, which constructs no client.
+ */
+class TelemetryConformanceConfigTest {
+
+ private static final String LOG_GROUP = "/aws/lambda/durable-execution-telemetry";
+
+ @ParameterizedTest
+ @NullSource
+ @ValueSource(strings = {"", " ", "\t"})
+ void requireLogGroupNameRejectsMissingValue(String value) {
+ var e = assertThrows(IllegalStateException.class, () -> TelemetryConformanceConfig.requireLogGroupName(value));
+ assertEquals("TELEMETRY_LOG_GROUP_NAME must be set", e.getMessage());
+ }
+
+ @Test
+ void requireLogGroupNameReturnsSetValue() {
+ assertSame(LOG_GROUP, TelemetryConformanceConfig.requireLogGroupName(LOG_GROUP));
+ }
+
+ @Test
+ void telemetryConfigUsesOneCloudWatchLogsExporter() {
+ var config = TelemetryConformanceConfig.telemetryConfig(LOG_GROUP);
+ assertEquals(1, config.exporters().size());
+ // The exporter exposes no log group accessor, so the name is not asserted here. The handler passes its
+ // static LOG_GROUP_NAME straight through, and the deployed run matches no record if the name is wrong.
+ assertInstanceOf(CloudWatchLogsExporter.class, config.exporters().get(0));
+ }
+
+ @Test
+ void telemetryConfigMatchesTheRunnerExpectations() {
+ var config = TelemetryConformanceConfig.telemetryConfig(LOG_GROUP);
+ // The runner reads one record per execution with its input and output. These four settings produce that.
+ assertEquals(ON_COMPLETE, config.emitMode());
+ assertEquals(1.0, config.samplingRate());
+ assertEquals(TOP_LEVEL, config.operationDetail());
+ assertTrue(config.content().includeInput());
+ assertTrue(config.content().includeOutput());
+ }
+}
diff --git a/conformance-tests-telemetry/template.yaml b/conformance-tests-telemetry/template.yaml
index 1f900ba84..81dfd7a2b 100644
--- a/conformance-tests-telemetry/template.yaml
+++ b/conformance-tests-telemetry/template.yaml
@@ -43,3 +43,14 @@ Resources:
CodeUri: .
Handler: software.amazon.lambda.durable.conformance.telemetry.Telemetry1Success
Role: !Ref LambdaExecutionRoleArn
+
+ Telemetry2Failure:
+ Type: AWS::Serverless::Function
+ DependsOn: TelemetryLogGroup
+ TestingMetadata:
+ TestDescription:
+ - telemetry-2
+ Properties:
+ CodeUri: .
+ Handler: software.amazon.lambda.durable.conformance.telemetry.Telemetry2Failure
+ Role: !Ref LambdaExecutionRoleArn