Skip to content

Commit 3ede02e

Browse files
committed
set up step functions contract tests
1 parent dc31109 commit 3ede02e

File tree

8 files changed

+735
-1
lines changed

8 files changed

+735
-1
lines changed

appsignals-tests/contract-tests/src/test/java/software/amazon/opentelemetry/appsignals/test/awssdk/base/AwsSdkBaseTest.java

Lines changed: 294 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public abstract class AwsSdkBaseTest extends ContractTestBase {
4444
LocalStackContainer.Service.DYNAMODB,
4545
LocalStackContainer.Service.SQS,
4646
LocalStackContainer.Service.KINESIS,
47-
LocalStackContainer.Service.SECRETSMANAGER)
47+
LocalStackContainer.Service.SECRETSMANAGER,
48+
LocalStackContainer.Service.IAM,
49+
LocalStackContainer.Service.STEPFUNCTIONS)
4850
.withEnv("DEFAULT_REGION", "us-west-2")
4951
.withNetwork(network)
5052
.withEnv("LOCALSTACK_HOST", "127.0.0.1")
@@ -106,6 +108,8 @@ protected String getApplicationWaitPattern() {
106108

107109
protected abstract String getSecretsManagerSpanNamePrefix();
108110

111+
protected abstract String getStepFunctionsSpanNamePrefix();
112+
109113
protected abstract String getS3RpcServiceName();
110114

111115
protected abstract String getDynamoDbRpcServiceName();
@@ -124,6 +128,8 @@ protected String getApplicationWaitPattern() {
124128

125129
protected abstract String getSecretsManagerRpcServiceName();
126130

131+
protected abstract String getStepFunctionsRpcServiceName();
132+
127133
private String getS3ServiceName() {
128134
return "AWS::S3";
129135
}
@@ -160,6 +166,8 @@ private String getSecretsManagerServiceName() {
160166
return "AWS::SecretsManager";
161167
}
162168

169+
private String getStepFunctionsServiceName() { return "AWS::StepFunctions"; }
170+
163171
private String s3SpanName(String operation) {
164172
return String.format("%s.%s", getS3SpanNamePrefix(), operation);
165173
}
@@ -196,6 +204,10 @@ private String secretsManagerSpanName(String operation) {
196204
return String.format("%s.%s", getSecretsManagerSpanNamePrefix(), operation);
197205
}
198206

207+
private String stepFunctionsSpanName(String operation) {
208+
return String.format("%s.%s", getStepFunctionsSpanNamePrefix(), operation);
209+
}
210+
199211
protected ThrowingConsumer<KeyValue> assertAttribute(String key, String value) {
200212
return (attribute) -> {
201213
var actualKey = attribute.getKey();
@@ -399,6 +411,7 @@ private void assertSpanAttributes(
399411
var spanAttributes = span.getAttributesList();
400412
assertThat(span.getKind()).isEqualTo(spanKind);
401413
assertThat(span.getName()).isEqualTo(spanName);
414+
402415
assertSemanticConventionsAttributes(
403416
spanAttributes, rpcService, method, peerName, peerPort, url, statusCode);
404417
assertAwsAttributes(
@@ -2794,4 +2807,284 @@ protected void doTestSecretsManagerFault() throws Exception {
27942807
null,
27952808
0.0);
27962809
}
2810+
2811+
protected void doTestStepFunctionsDescribeStateMachine() throws Exception {
2812+
appClient.get("/sfn/describestatemachine/test-state-machine").aggregate().join();
2813+
var traces = mockCollectorClient.getTraces();
2814+
var metrics =
2815+
mockCollectorClient.getMetrics(
2816+
Set.of(
2817+
AppSignalsConstants.ERROR_METRIC,
2818+
AppSignalsConstants.FAULT_METRIC,
2819+
AppSignalsConstants.LATENCY_METRIC));
2820+
var localService = getApplicationOtelServiceName();
2821+
var localOperation = "GET /sfn/describestatemachine/:name";
2822+
var type = "AWS::StepFunctions::StateMachine";
2823+
var identifier = "test-state-machine";
2824+
var cloudformationIdentifier =
2825+
"arn:aws:states:us-west-2:000000000000:stateMachine:test-state-machine";
2826+
2827+
assertSpanClientAttributes(
2828+
traces,
2829+
stepFunctionsSpanName("DescribeStateMachine"),
2830+
getStepFunctionsRpcServiceName(),
2831+
localService,
2832+
localOperation,
2833+
getStepFunctionsServiceName(),
2834+
"DescribeStateMachine",
2835+
type,
2836+
identifier,
2837+
cloudformationIdentifier,
2838+
"localstack",
2839+
4566,
2840+
"http://localstack:4566",
2841+
200,
2842+
List.of(
2843+
assertAttribute(
2844+
SemanticConventionsConstants.AWS_STATE_MACHINE_ARN,
2845+
"arn:aws:states:us-west-2:000000000000:stateMachine:test-state-machine")));
2846+
assertMetricClientAttributes(
2847+
metrics,
2848+
AppSignalsConstants.LATENCY_METRIC,
2849+
localService,
2850+
localOperation,
2851+
getStepFunctionsServiceName(),
2852+
"DescribeStateMachine",
2853+
type,
2854+
identifier,
2855+
cloudformationIdentifier,
2856+
5000.0);
2857+
assertMetricClientAttributes(
2858+
metrics,
2859+
AppSignalsConstants.FAULT_METRIC,
2860+
localService,
2861+
localOperation,
2862+
getStepFunctionsServiceName(),
2863+
"DescribeStateMachine",
2864+
type,
2865+
identifier,
2866+
cloudformationIdentifier,
2867+
0.0);
2868+
assertMetricClientAttributes(
2869+
metrics,
2870+
AppSignalsConstants.ERROR_METRIC,
2871+
localService,
2872+
localOperation,
2873+
getStepFunctionsServiceName(),
2874+
"DescribeStateMachine",
2875+
type,
2876+
identifier,
2877+
cloudformationIdentifier,
2878+
0.0);
2879+
}
2880+
2881+
protected void doTestStepFunctionsDescribeActivity() throws Exception {
2882+
appClient.get("/sfn/describeactivity/test-activity").aggregate().join();
2883+
var traces = mockCollectorClient.getTraces();
2884+
var metrics =
2885+
mockCollectorClient.getMetrics(
2886+
Set.of(
2887+
AppSignalsConstants.ERROR_METRIC,
2888+
AppSignalsConstants.FAULT_METRIC,
2889+
AppSignalsConstants.LATENCY_METRIC));
2890+
var localService = getApplicationOtelServiceName();
2891+
var localOperation = "GET /sfn/describeactivity/:name";
2892+
var type = "AWS::StepFunctions::Activity";
2893+
var identifier = "test-activity";
2894+
var cloudformationIdentifier = "arn:aws:states:us-west-2:000000000000:activity:test-activity";
2895+
2896+
assertSpanClientAttributes(
2897+
traces,
2898+
stepFunctionsSpanName("DescribeActivity"),
2899+
getStepFunctionsRpcServiceName(),
2900+
localService,
2901+
localOperation,
2902+
getStepFunctionsServiceName(),
2903+
"DescribeActivity",
2904+
type,
2905+
identifier,
2906+
cloudformationIdentifier,
2907+
"localstack",
2908+
4566,
2909+
"http://localstack:4566",
2910+
200,
2911+
List.of(
2912+
assertAttribute(
2913+
SemanticConventionsConstants.AWS_ACTIVITY_ARN,
2914+
"arn:aws:states:us-west-2:000000000000:activity:test-activity")));
2915+
assertMetricClientAttributes(
2916+
metrics,
2917+
AppSignalsConstants.LATENCY_METRIC,
2918+
localService,
2919+
localOperation,
2920+
getStepFunctionsServiceName(),
2921+
"DescribeActivity",
2922+
type,
2923+
identifier,
2924+
cloudformationIdentifier,
2925+
5000.0);
2926+
assertMetricClientAttributes(
2927+
metrics,
2928+
AppSignalsConstants.FAULT_METRIC,
2929+
localService,
2930+
localOperation,
2931+
getStepFunctionsServiceName(),
2932+
"DescribeActivity",
2933+
type,
2934+
identifier,
2935+
cloudformationIdentifier,
2936+
0.0);
2937+
assertMetricClientAttributes(
2938+
metrics,
2939+
AppSignalsConstants.ERROR_METRIC,
2940+
localService,
2941+
localOperation,
2942+
getStepFunctionsServiceName(),
2943+
"DescribeActivity",
2944+
type,
2945+
identifier,
2946+
cloudformationIdentifier,
2947+
0.0);
2948+
}
2949+
2950+
protected void doTestStepFunctionsError() throws Exception {
2951+
appClient.get("/sfn/error").aggregate().join();
2952+
var traces = mockCollectorClient.getTraces();
2953+
var metrics =
2954+
mockCollectorClient.getMetrics(
2955+
Set.of(
2956+
AppSignalsConstants.ERROR_METRIC,
2957+
AppSignalsConstants.FAULT_METRIC,
2958+
AppSignalsConstants.LATENCY_METRIC));
2959+
2960+
var localService = getApplicationOtelServiceName();
2961+
var localOperation = "GET /sfn/error";
2962+
var type = "AWS::StepFunctions::Activity";
2963+
var identifier = "nonexistent-activity";
2964+
var cloudformationIdentifier =
2965+
"arn:aws:states:us-west-2:000000000000:activity:nonexistent-activity";
2966+
2967+
assertSpanClientAttributes(
2968+
traces,
2969+
stepFunctionsSpanName("DescribeActivity"),
2970+
getStepFunctionsRpcServiceName(),
2971+
localService,
2972+
localOperation,
2973+
getStepFunctionsServiceName(),
2974+
"DescribeActivity",
2975+
type,
2976+
identifier,
2977+
cloudformationIdentifier,
2978+
"error.test",
2979+
8080,
2980+
"http://error.test:8080",
2981+
400,
2982+
List.of(
2983+
assertAttribute(
2984+
SemanticConventionsConstants.AWS_ACTIVITY_ARN,
2985+
"arn:aws:states:us-west-2:000000000000:activity:nonexistent-activity")));
2986+
assertMetricClientAttributes(
2987+
metrics,
2988+
AppSignalsConstants.LATENCY_METRIC,
2989+
localService,
2990+
localOperation,
2991+
getStepFunctionsServiceName(),
2992+
"DescribeActivity",
2993+
type,
2994+
identifier,
2995+
cloudformationIdentifier,
2996+
5000.0);
2997+
assertMetricClientAttributes(
2998+
metrics,
2999+
AppSignalsConstants.FAULT_METRIC,
3000+
localService,
3001+
localOperation,
3002+
getStepFunctionsServiceName(),
3003+
"DescribeActivity",
3004+
type,
3005+
identifier,
3006+
cloudformationIdentifier,
3007+
0.0);
3008+
assertMetricClientAttributes(
3009+
metrics,
3010+
AppSignalsConstants.ERROR_METRIC,
3011+
localService,
3012+
localOperation,
3013+
getStepFunctionsServiceName(),
3014+
"DescribeActivity",
3015+
type,
3016+
identifier,
3017+
cloudformationIdentifier,
3018+
1.0);
3019+
}
3020+
3021+
protected void doTestStepFunctionsFault() throws Exception {
3022+
appClient.get("/sfn/fault").aggregate().join();
3023+
var traces = mockCollectorClient.getTraces();
3024+
var metrics =
3025+
mockCollectorClient.getMetrics(
3026+
Set.of(
3027+
AppSignalsConstants.ERROR_METRIC,
3028+
AppSignalsConstants.FAULT_METRIC,
3029+
AppSignalsConstants.LATENCY_METRIC));
3030+
3031+
var localService = getApplicationOtelServiceName();
3032+
var localOperation = "GET /sfn/fault";
3033+
var type = "AWS::StepFunctions::Activity";
3034+
var identifier = "fault-activity";
3035+
var cloudformationIdentifier = "arn:aws:states:us-west-2:000000000000:activity:fault-activity";
3036+
3037+
assertSpanClientAttributes(
3038+
traces,
3039+
stepFunctionsSpanName("DescribeActivity"),
3040+
getStepFunctionsRpcServiceName(),
3041+
localService,
3042+
localOperation,
3043+
getStepFunctionsServiceName(),
3044+
"DescribeActivity",
3045+
type,
3046+
identifier,
3047+
cloudformationIdentifier,
3048+
"fault.test",
3049+
8080,
3050+
"http://fault.test:8080",
3051+
500,
3052+
List.of(
3053+
assertAttribute(
3054+
SemanticConventionsConstants.AWS_ACTIVITY_ARN,
3055+
"arn:aws:states:us-west-2:000000000000:activity:fault-activity")));
3056+
assertMetricClientAttributes(
3057+
metrics,
3058+
AppSignalsConstants.LATENCY_METRIC,
3059+
localService,
3060+
localOperation,
3061+
getStepFunctionsServiceName(),
3062+
"DescribeActivity",
3063+
type,
3064+
identifier,
3065+
cloudformationIdentifier,
3066+
5000.0);
3067+
assertMetricClientAttributes(
3068+
metrics,
3069+
AppSignalsConstants.FAULT_METRIC,
3070+
localService,
3071+
localOperation,
3072+
getStepFunctionsServiceName(),
3073+
"DescribeActivity",
3074+
type,
3075+
identifier,
3076+
cloudformationIdentifier,
3077+
1.0);
3078+
assertMetricClientAttributes(
3079+
metrics,
3080+
AppSignalsConstants.ERROR_METRIC,
3081+
localService,
3082+
localOperation,
3083+
getStepFunctionsServiceName(),
3084+
"DescribeActivity",
3085+
type,
3086+
identifier,
3087+
cloudformationIdentifier,
3088+
0.0);
3089+
}
27973090
}

appsignals-tests/contract-tests/src/test/java/software/amazon/opentelemetry/appsignals/test/awssdk/v1/AwsSdkV1Test.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ protected String getSecretsManagerSpanNamePrefix() {
8181
return "AWSSecretsManager";
8282
}
8383

84+
@Override
85+
protected String getStepFunctionsSpanNamePrefix() {
86+
return "AWSStepFunctions";
87+
}
88+
8489
protected String getS3RpcServiceName() {
8590
return "Amazon S3";
8691
}
@@ -100,6 +105,11 @@ protected String getSecretsManagerRpcServiceName() {
100105
return "AWSSecretsManager";
101106
}
102107

108+
@Override
109+
protected String getStepFunctionsRpcServiceName() {
110+
return "AWSStepFunctions";
111+
}
112+
103113
protected String getKinesisRpcServiceName() {
104114
return "AmazonKinesis";
105115
}
@@ -285,4 +295,24 @@ void testSecretsManagerError() throws Exception {
285295
void testSecretsManagerFault() throws Exception {
286296
doTestSecretsManagerFault();
287297
}
298+
299+
@Test
300+
void testStepFunctionsDescribeStateMachine() throws Exception {
301+
doTestStepFunctionsDescribeStateMachine();
302+
}
303+
304+
@Test
305+
void testStepFunctionsDescribeActivity() throws Exception {
306+
doTestStepFunctionsDescribeActivity();
307+
}
308+
309+
@Test
310+
void testStepFunctionsError() throws Exception {
311+
doTestStepFunctionsError();
312+
}
313+
314+
@Test
315+
void testStepFunctionsFault() throws Exception {
316+
doTestStepFunctionsFault();
317+
}
288318
}

0 commit comments

Comments
 (0)