2323import java .util .List ;
2424import java .util .Map ;
2525import java .util .Set ;
26-
2726import org .assertj .core .api .ThrowingConsumer ;
2827import org .junit .jupiter .api .AfterAll ;
2928import org .junit .jupiter .api .BeforeAll ;
@@ -46,7 +45,8 @@ public abstract class AwsSdkBaseTest extends ContractTestBase {
4645 LocalStackContainer .Service .KINESIS ,
4746 LocalStackContainer .Service .SECRETSMANAGER ,
4847 LocalStackContainer .Service .IAM ,
49- LocalStackContainer .Service .STEPFUNCTIONS )
48+ LocalStackContainer .Service .STEPFUNCTIONS ,
49+ LocalStackContainer .Service .SNS )
5050 .withEnv ("DEFAULT_REGION" , "us-west-2" )
5151 .withNetwork (network )
5252 .withEnv ("LOCALSTACK_HOST" , "127.0.0.1" )
@@ -110,6 +110,8 @@ protected String getApplicationWaitPattern() {
110110
111111 protected abstract String getStepFunctionsSpanNamePrefix ();
112112
113+ protected abstract String getSnsSpanNamePrefix ();
114+
113115 protected abstract String getS3RpcServiceName ();
114116
115117 protected abstract String getDynamoDbRpcServiceName ();
@@ -128,6 +130,8 @@ protected String getApplicationWaitPattern() {
128130
129131 protected abstract String getSecretsManagerRpcServiceName ();
130132
133+ protected abstract String getSnsRpcServiceName ();
134+
131135 protected abstract String getStepFunctionsRpcServiceName ();
132136
133137 private String getS3ServiceName () {
@@ -166,7 +170,13 @@ private String getSecretsManagerServiceName() {
166170 return "AWS::SecretsManager" ;
167171 }
168172
169- private String getStepFunctionsServiceName () { return "AWS::StepFunctions" ; }
173+ private String getStepFunctionsServiceName () {
174+ return "AWS::StepFunctions" ;
175+ }
176+
177+ protected String getSnsServiceName () {
178+ return "AWS::SNS" ;
179+ }
170180
171181 private String s3SpanName (String operation ) {
172182 return String .format ("%s.%s" , getS3SpanNamePrefix (), operation );
@@ -208,6 +218,10 @@ private String stepFunctionsSpanName(String operation) {
208218 return String .format ("%s.%s" , getStepFunctionsSpanNamePrefix (), operation );
209219 }
210220
221+ private String snsSpanName (String operation ) {
222+ return String .format ("%s.%s" , getSnsSpanNamePrefix (), operation );
223+ }
224+
211225 protected ThrowingConsumer <KeyValue > assertAttribute (String key , String value ) {
212226 return (attribute ) -> {
213227 var actualKey = attribute .getKey ();
@@ -3087,4 +3101,173 @@ protected void doTestStepFunctionsFault() throws Exception {
30873101 cloudformationIdentifier ,
30883102 0.0 );
30893103 }
3104+
3105+ protected void doTestSnsGetTopicAttributes () throws Exception {
3106+ appClient .get ("/sns/gettopicattributes/test-topic" ).aggregate ().join ();
3107+ var traces = mockCollectorClient .getTraces ();
3108+ var metrics =
3109+ mockCollectorClient .getMetrics (
3110+ Set .of (
3111+ AppSignalsConstants .ERROR_METRIC ,
3112+ AppSignalsConstants .FAULT_METRIC ,
3113+ AppSignalsConstants .LATENCY_METRIC ));
3114+
3115+ var localService = getApplicationOtelServiceName ();
3116+ var localOperation = "GET /sns/gettopicattributes/:topicId" ;
3117+ var type = "AWS::SNS::Topic" ;
3118+ var identifier = "test-topic" ;
3119+ var cloudformationIdentifier = "arn:aws:sns:us-west-2:000000000000:test-topic" ;
3120+
3121+ assertSpanClientAttributes (
3122+ traces ,
3123+ snsSpanName ("GetTopicAttributes" ),
3124+ getSnsRpcServiceName (),
3125+ localService ,
3126+ localOperation ,
3127+ getSnsServiceName (),
3128+ "GetTopicAttributes" ,
3129+ type ,
3130+ identifier ,
3131+ cloudformationIdentifier ,
3132+ "localstack" ,
3133+ 4566 ,
3134+ "http://localstack:4566" ,
3135+ 200 ,
3136+ List .of (
3137+ assertAttribute (
3138+ SemanticConventionsConstants .AWS_TOPIC_ARN ,
3139+ "arn:aws:sns:us-west-2:000000000000:test-topic" )));
3140+ }
3141+
3142+ protected void doTestSnsError () throws Exception {
3143+ appClient .get ("/sns/error" ).aggregate ().join ();
3144+ var traces = mockCollectorClient .getTraces ();
3145+ var metrics =
3146+ mockCollectorClient .getMetrics (
3147+ Set .of (
3148+ AppSignalsConstants .ERROR_METRIC ,
3149+ AppSignalsConstants .FAULT_METRIC ,
3150+ AppSignalsConstants .LATENCY_METRIC ));
3151+
3152+ var localService = getApplicationOtelServiceName ();
3153+ var localOperation = "GET /sns/error" ;
3154+ assertSpanClientAttributes (
3155+ traces ,
3156+ snsSpanName ("GetTopicAttributes" ),
3157+ getSnsRpcServiceName (),
3158+ localService ,
3159+ localOperation ,
3160+ getSnsServiceName (),
3161+ "GetTopicAttributes" ,
3162+ null ,
3163+ null ,
3164+ null ,
3165+ "error.test" ,
3166+ 8080 ,
3167+ "http://error.test:8080" ,
3168+ 400 ,
3169+ List .of ());
3170+
3171+ assertMetricClientAttributes (
3172+ metrics ,
3173+ AppSignalsConstants .LATENCY_METRIC ,
3174+ localService ,
3175+ localOperation ,
3176+ getSnsServiceName (),
3177+ "GetTopicAttributes" ,
3178+ null ,
3179+ null ,
3180+ null ,
3181+ 5000.0 );
3182+
3183+ assertMetricClientAttributes (
3184+ metrics ,
3185+ AppSignalsConstants .FAULT_METRIC ,
3186+ localService ,
3187+ localOperation ,
3188+ getSnsServiceName (),
3189+ "GetTopicAttributes" ,
3190+ null ,
3191+ null ,
3192+ null ,
3193+ 0.0 );
3194+
3195+ assertMetricClientAttributes (
3196+ metrics ,
3197+ AppSignalsConstants .ERROR_METRIC ,
3198+ localService ,
3199+ localOperation ,
3200+ getSnsServiceName (),
3201+ "GetTopicAttributes" ,
3202+ null ,
3203+ null ,
3204+ null ,
3205+ 1.0 );
3206+ }
3207+
3208+ protected void doTestSnsFault () throws Exception {
3209+ appClient .get ("/sns/fault" ).aggregate ().join ();
3210+ var traces = mockCollectorClient .getTraces ();
3211+ var metrics =
3212+ mockCollectorClient .getMetrics (
3213+ Set .of (
3214+ AppSignalsConstants .ERROR_METRIC ,
3215+ AppSignalsConstants .FAULT_METRIC ,
3216+ AppSignalsConstants .LATENCY_METRIC ));
3217+
3218+ var localService = getApplicationOtelServiceName ();
3219+ var localOperation = "GET /sns/fault" ;
3220+ assertSpanClientAttributes (
3221+ traces ,
3222+ snsSpanName ("GetTopicAttributes" ),
3223+ getSnsRpcServiceName (),
3224+ localService ,
3225+ localOperation ,
3226+ getSnsServiceName (),
3227+ "GetTopicAttributes" ,
3228+ null ,
3229+ null ,
3230+ null ,
3231+ "fault.test" ,
3232+ 8080 ,
3233+ "http://fault.test:8080" ,
3234+ 500 ,
3235+ List .of ());
3236+
3237+ assertMetricClientAttributes (
3238+ metrics ,
3239+ AppSignalsConstants .LATENCY_METRIC ,
3240+ localService ,
3241+ localOperation ,
3242+ getSnsServiceName (),
3243+ "GetTopicAttributes" ,
3244+ null ,
3245+ null ,
3246+ null ,
3247+ 5000.0 );
3248+
3249+ assertMetricClientAttributes (
3250+ metrics ,
3251+ AppSignalsConstants .FAULT_METRIC ,
3252+ localService ,
3253+ localOperation ,
3254+ getSnsServiceName (),
3255+ "GetTopicAttributes" ,
3256+ null ,
3257+ null ,
3258+ null ,
3259+ 1.0 );
3260+
3261+ assertMetricClientAttributes (
3262+ metrics ,
3263+ AppSignalsConstants .ERROR_METRIC ,
3264+ localService ,
3265+ localOperation ,
3266+ getSnsServiceName (),
3267+ "GetTopicAttributes" ,
3268+ null ,
3269+ null ,
3270+ null ,
3271+ 0.0 );
3272+ }
30903273}
0 commit comments