2222import java .io .OutputStream ;
2323import java .io .UnsupportedEncodingException ;
2424import java .net .URI ;
25- import java .util .Arrays ;
26- import java .util .HashMap ;
27- import java .util .Map ;
25+ import java .util .*;
2826import org .apache .http .Header ;
2927import org .apache .http .HttpEntity ;
3028import org .apache .http .HttpResponse ;
4139import org .skyscreamer .jsonassert .JSONAssert ;
4240import org .skyscreamer .jsonassert .JSONCompareMode ;
4341import org .skyscreamer .jsonassert .comparator .CustomComparator ;
42+ import software .amazon .awssdk .core .interceptor .ExecutionAttributes ;
43+ import software .amazon .awssdk .core .interceptor .InterceptorContext ;
44+ import software .amazon .awssdk .core .interceptor .SdkExecutionAttribute ;
45+ import software .amazon .awssdk .http .SdkHttpMethod ;
46+ import software .amazon .awssdk .http .SdkHttpRequest ;
47+ import software .amazon .awssdk .http .SdkHttpResponse ;
48+ import software .amazon .awssdk .services .sns .model .PublishRequest ;
49+ import software .amazon .awssdk .services .sns .model .PublishResponse ;
4450
4551class SpansContainerTest {
4652 private static final char ch = '*' ;
@@ -378,7 +384,9 @@ void add_aws_http_span_with_spnid_from_header_amzn() throws Exception {
378384 "{\n "
379385 + " \" started\" :1559127760071,\n "
380386 + " \" ended\" :1559127760085,\n "
381- + " \" id\" :\" cc9ceb9c-dad2-4762-8f0c-147408bdc063\" ,\n "
387+ + " \" id\" :"
388+ + actualSpan .getId ()
389+ + ",\n "
382390 + " \" type\" :\" http\" ,\n "
383391 + " \" transactionId\" :\" 3\" ,\n "
384392 + " \" account\" :\" 1111\" ,\n "
@@ -489,17 +497,39 @@ void add_aws_http_span_with_spnid_from_header_amz() throws Exception {
489497 @ DisplayName ("AWS SDK V2 request" )
490498 @ Test
491499 void add_aws_sdk_v2_http_span () throws Exception {
492- Map <String , String > headers = new HashMap <>();
493- headers .put ("x-amz-requestid" , "id123" );
500+ Map <String , List <String >> headers = new HashMap <>();
501+ headers .put ("x-amz-requestid" , Collections .singletonList ("id123" ));
502+
503+ PublishRequest request = PublishRequest .builder ().topicArn ("topic" ).build ();
504+ PublishResponse response =
505+ PublishResponse .builder ().messageId ("fee47356-6f6a-58c8-96dc-26d8aaa4631a" ).build ();
506+
507+ SdkHttpRequest sdkHttpRequest =
508+ SdkHttpRequest .builder ()
509+ .uri (new URI ("https://sns.amazonaws.com" ))
510+ .headers (headers )
511+ .method (SdkHttpMethod .GET )
512+ .build ();
513+
514+ SdkHttpResponse sdkHttpResponse =
515+ SdkHttpResponse .builder ().headers (headers ).statusCode (200 ).build ();
516+
517+ software .amazon .awssdk .core .interceptor .Context .AfterExecution requestContext =
518+ InterceptorContext .builder ()
519+ .request (request )
520+ .httpRequest (sdkHttpRequest )
521+ .response (response )
522+ .httpResponse (sdkHttpResponse )
523+ .build ();
524+ ExecutionAttributes executionAttributes =
525+ ExecutionAttributes .builder ()
526+ .put (SdkExecutionAttribute .SERVICE_NAME , "Sns" )
527+ .build ();
494528
495529 spansContainer .init (createMockedEnv (), reporter , context , null );
496- when (awsRequest .getEndpoint ()).thenReturn (URI .create ("https://sns.amazonaws.com" ));
497- when (awsRequest .getHttpMethod ()).thenReturn (HttpMethodName .GET );
498- when (awsHttpResponse .getStatusCode ()).thenReturn (200 );
499- when (awsHttpResponse .getHeaders ()).thenReturn (headers );
500- Response <String > awsResponse = new Response <>("awsResponse" , awsHttpResponse );
501530 long startTime = System .currentTimeMillis ();
502- spansContainer .addHttpSpan (startTime , awsRequest , awsResponse );
531+
532+ spansContainer .addHttpSpan (startTime , requestContext , executionAttributes );
503533
504534 HttpSpan actualSpan = spansContainer .getHttpSpans ().get (0 );
505535 String expectedSpan =
@@ -522,15 +552,15 @@ void add_aws_sdk_v2_http_span() throws Exception {
522552 + " \" httpInfo\" :{\n "
523553 + " \" host\" :\" sns.amazonaws.com\" ,\n "
524554 + " \" request\" :{\n "
525- + " \" headers\" :\" {}\" ,\n "
555+ + " \" headers\" :\" {\\ \" x-amz-requestid \\ \" :[ \\ \" id123 \\ \" ] }\" ,\n "
526556 + " \" body\" :null,\n "
527557 + " \" uri\" :\" https://sns.amazonaws.com\" ,\n "
528558 + " \" statusCode\" :null,\n "
529559 + " \" method\" :GET\n "
530560 + " },\n "
531561 + " \" response\" :{\n "
532- + " \" headers\" :\" {\\ \" x-amz-requestid\\ \" :\\ \" id123\\ \" }\" ,\n "
533- + " \" body\" :\" awsResponse \" , \n "
562+ + " \" headers\" :\" {\\ \" x-amz-requestid\\ \" :[ \\ \" id123\\ \" ] }\" ,\n "
563+ + " \" body\" :\" { \\ \" messageId \\ \" : \\ \" fee47356-6f6a-58c8-96dc-26d8aaa4631a \\ \" , \\ \" sequenceNumber \\ \" :null} \" , \n "
534564 + " \" uri\" :null,\n "
535565 + " \" statusCode\" :200,\n "
536566 + " \" method\" :null\n "
@@ -539,6 +569,7 @@ void add_aws_sdk_v2_http_span() throws Exception {
539569 + " },\n "
540570 + " \" parentId\" :\" 3n2783hf7823hdui32\" \n "
541571 + "}" ;
572+
542573 JSONAssert .assertEquals (
543574 expectedSpan ,
544575 JsonUtils .getObjectAsJsonString (actualSpan ),
0 commit comments