@@ -45,7 +45,8 @@ public abstract class AwsSdkBaseTest extends ContractTestBase {
4545 LocalStackContainer .Service .KINESIS ,
4646 LocalStackContainer .Service .SECRETSMANAGER ,
4747 LocalStackContainer .Service .IAM ,
48- LocalStackContainer .Service .STEPFUNCTIONS )
48+ LocalStackContainer .Service .STEPFUNCTIONS ,
49+ LocalStackContainer .Service .SNS )
4950 .withEnv ("DEFAULT_REGION" , "us-west-2" )
5051 .withNetwork (network )
5152 .withEnv ("LOCALSTACK_HOST" , "127.0.0.1" )
@@ -109,6 +110,8 @@ protected String getApplicationWaitPattern() {
109110
110111 protected abstract String getStepFunctionsSpanNamePrefix ();
111112
113+ protected abstract String getSnsSpanNamePrefix ();
114+
112115 protected abstract String getS3RpcServiceName ();
113116
114117 protected abstract String getDynamoDbRpcServiceName ();
@@ -127,6 +130,8 @@ protected String getApplicationWaitPattern() {
127130
128131 protected abstract String getSecretsManagerRpcServiceName ();
129132
133+ protected abstract String getSnsRpcServiceName ();
134+
130135 protected abstract String getStepFunctionsRpcServiceName ();
131136
132137 private String getS3ServiceName () {
@@ -169,6 +174,10 @@ private String getStepFunctionsServiceName() {
169174 return "AWS::StepFunctions" ;
170175 }
171176
177+ protected String getSnsServiceName () {
178+ return "AWS::SNS" ;
179+ }
180+
172181 private String s3SpanName (String operation ) {
173182 return String .format ("%s.%s" , getS3SpanNamePrefix (), operation );
174183 }
@@ -209,6 +218,10 @@ private String stepFunctionsSpanName(String operation) {
209218 return String .format ("%s.%s" , getStepFunctionsSpanNamePrefix (), operation );
210219 }
211220
221+ private String snsSpanName (String operation ) {
222+ return String .format ("%s.%s" , getSnsSpanNamePrefix (), operation );
223+ }
224+
212225 protected ThrowingConsumer <KeyValue > assertAttribute (String key , String value ) {
213226 return (attribute ) -> {
214227 var actualKey = attribute .getKey ();
@@ -3088,4 +3101,170 @@ protected void doTestStepFunctionsFault() throws Exception {
30883101 cloudformationIdentifier ,
30893102 0.0 );
30903103 }
3104+
3105+ protected void doTestSnsGetTopicAttributes () throws Exception {
3106+ appClient .get ("/sns/gettopicattributes/test-topic" ).aggregate ().join ();
3107+ var traces = mockCollectorClient .getTraces ();
3108+ var metrics = mockCollectorClient .getMetrics (
3109+ Set .of (
3110+ AppSignalsConstants .ERROR_METRIC ,
3111+ AppSignalsConstants .FAULT_METRIC ,
3112+ AppSignalsConstants .LATENCY_METRIC ));
3113+
3114+ var localService = getApplicationOtelServiceName ();
3115+ var localOperation = "GET /sns/gettopicattributes/:topicId" ;
3116+ var type = "AWS::SNS::Topic" ;
3117+ var identifier = "test-topic" ;
3118+ var cloudformationIdentifier = "arn:aws:sns:us-west-2:000000000000:test-topic" ;
3119+
3120+ assertSpanClientAttributes (
3121+ traces ,
3122+ snsSpanName ("GetTopicAttributes" ),
3123+ getSnsRpcServiceName (),
3124+ localService ,
3125+ localOperation ,
3126+ getSnsServiceName (),
3127+ "GetTopicAttributes" ,
3128+ type ,
3129+ identifier ,
3130+ cloudformationIdentifier ,
3131+ "localstack" ,
3132+ 4566 ,
3133+ "http://localstack:4566" ,
3134+ 200 ,
3135+ List .of (
3136+ assertAttribute (
3137+ SemanticConventionsConstants .AWS_TOPIC_ARN ,
3138+ "arn:aws:sns:us-west-2:000000000000:test-topic" )));
3139+ }
3140+
3141+ protected void doTestSnsError () throws Exception {
3142+ appClient .get ("/sns/error" ).aggregate ().join ();
3143+ var traces = mockCollectorClient .getTraces ();
3144+ var metrics = mockCollectorClient .getMetrics (
3145+ Set .of (
3146+ AppSignalsConstants .ERROR_METRIC ,
3147+ AppSignalsConstants .FAULT_METRIC ,
3148+ AppSignalsConstants .LATENCY_METRIC ));
3149+
3150+ var localService = getApplicationOtelServiceName ();
3151+ var localOperation = "GET /sns/error" ;
3152+ assertSpanClientAttributes (
3153+ traces ,
3154+ snsSpanName ("GetTopicAttributes" ),
3155+ getSnsRpcServiceName (),
3156+ localService ,
3157+ localOperation ,
3158+ getSnsServiceName (),
3159+ "GetTopicAttributes" ,
3160+ null ,
3161+ null ,
3162+ null ,
3163+ "error.test" ,
3164+ 8080 ,
3165+ "http://error.test:8080" ,
3166+ 400 ,
3167+ List .of ());
3168+
3169+ assertMetricClientAttributes (
3170+ metrics ,
3171+ AppSignalsConstants .LATENCY_METRIC ,
3172+ localService ,
3173+ localOperation ,
3174+ getSnsServiceName (),
3175+ "GetTopicAttributes" ,
3176+ null ,
3177+ null ,
3178+ null ,
3179+ 5000.0 );
3180+
3181+ assertMetricClientAttributes (
3182+ metrics ,
3183+ AppSignalsConstants .FAULT_METRIC ,
3184+ localService ,
3185+ localOperation ,
3186+ getSnsServiceName (),
3187+ "GetTopicAttributes" ,
3188+ null ,
3189+ null ,
3190+ null ,
3191+ 0.0 );
3192+
3193+ assertMetricClientAttributes (
3194+ metrics ,
3195+ AppSignalsConstants .ERROR_METRIC ,
3196+ localService ,
3197+ localOperation ,
3198+ getSnsServiceName (),
3199+ "GetTopicAttributes" ,
3200+ null ,
3201+ null ,
3202+ null ,
3203+ 1.0 );
3204+ }
3205+
3206+ protected void doTestSnsFault () throws Exception {
3207+ appClient .get ("/sns/fault" ).aggregate ().join ();
3208+ var traces = mockCollectorClient .getTraces ();
3209+ var metrics = mockCollectorClient .getMetrics (
3210+ Set .of (
3211+ AppSignalsConstants .ERROR_METRIC ,
3212+ AppSignalsConstants .FAULT_METRIC ,
3213+ AppSignalsConstants .LATENCY_METRIC ));
3214+
3215+ var localService = getApplicationOtelServiceName ();
3216+ var localOperation = "GET /sns/fault" ;
3217+ assertSpanClientAttributes (
3218+ traces ,
3219+ snsSpanName ("GetTopicAttributes" ),
3220+ getSnsRpcServiceName (),
3221+ localService ,
3222+ localOperation ,
3223+ getSnsServiceName (),
3224+ "GetTopicAttributes" ,
3225+ null ,
3226+ null ,
3227+ null ,
3228+ "fault.test" ,
3229+ 8080 ,
3230+ "http://fault.test:8080" ,
3231+ 500 ,
3232+ List .of ());
3233+
3234+ assertMetricClientAttributes (
3235+ metrics ,
3236+ AppSignalsConstants .LATENCY_METRIC ,
3237+ localService ,
3238+ localOperation ,
3239+ getSnsServiceName (),
3240+ "GetTopicAttributes" ,
3241+ null ,
3242+ null ,
3243+ null ,
3244+ 5000.0 );
3245+
3246+ assertMetricClientAttributes (
3247+ metrics ,
3248+ AppSignalsConstants .FAULT_METRIC ,
3249+ localService ,
3250+ localOperation ,
3251+ getSnsServiceName (),
3252+ "GetTopicAttributes" ,
3253+ null ,
3254+ null ,
3255+ null ,
3256+ 1.0 );
3257+
3258+ assertMetricClientAttributes (
3259+ metrics ,
3260+ AppSignalsConstants .ERROR_METRIC ,
3261+ localService ,
3262+ localOperation ,
3263+ getSnsServiceName (),
3264+ "GetTopicAttributes" ,
3265+ null ,
3266+ null ,
3267+ null ,
3268+ 0.0 );
3269+ }
30913270}
0 commit comments