@@ -7,9 +7,11 @@ package io.opentelemetry.instrumentation.awssdk.v2_2
7
7
8
8
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
9
9
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
10
+ import io.opentelemetry.testing.internal.armeria.common.HttpData
10
11
import io.opentelemetry.testing.internal.armeria.common.HttpResponse
11
12
import io.opentelemetry.testing.internal.armeria.common.HttpStatus
12
13
import io.opentelemetry.testing.internal.armeria.common.MediaType
14
+ import io.opentelemetry.testing.internal.armeria.common.ResponseHeaders
13
15
import io.opentelemetry.testing.internal.armeria.testing.junit5.server.mock.MockWebServerExtension
14
16
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials
15
17
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider
@@ -52,6 +54,7 @@ import software.amazon.awssdk.services.sqs.model.SendMessageRequest
52
54
import spock.lang.Shared
53
55
import spock.lang.Unroll
54
56
57
+ import java.nio.charset.StandardCharsets
55
58
import java.time.Duration
56
59
import java.util.concurrent.Future
57
60
@@ -326,7 +329,13 @@ abstract class AbstractAws2ClientTest extends InstrumentationSpecification {
326
329
.region(Region . AP_NORTHEAST_1 )
327
330
.credentialsProvider(CREDENTIALS_PROVIDER )
328
331
.build()
329
- server. enqueue(HttpResponse . of(HttpStatus . OK , MediaType . PLAIN_TEXT_UTF_8 , body))
332
+
333
+ if (body instanceof Closure ) {
334
+ server. enqueue(body. call())
335
+ } else {
336
+ server. enqueue(HttpResponse . of(HttpStatus . OK , MediaType . PLAIN_TEXT_UTF_8 , body))
337
+ }
338
+
330
339
def response = call. call(client)
331
340
332
341
if (response instanceof Future ) {
@@ -379,22 +388,54 @@ abstract class AbstractAws2ClientTest extends InstrumentationSpecification {
379
388
" S3" | " CreateBucket" | " PUT" | path(" somebucket" ) | " UNKNOWN" | S3Client . builder() | { c -> c. createBucket(CreateBucketRequest . builder(). bucket(" somebucket" ). build()) } | " "
380
389
" S3" | " GetObject" | " GET" | path(" somebucket" , " somekey" ) | " UNKNOWN" | S3Client . builder() | { c -> c. getObject(GetObjectRequest . builder(). bucket(" somebucket" ). key(" somekey" ). build()) } | " "
381
390
" Kinesis" | " DeleteStream" | " POST" | " " | " UNKNOWN" | KinesisClient . builder() | { c -> c. deleteStream(DeleteStreamRequest . builder(). streamName(" somestream" ). build()) } | " "
382
- " Sqs" | " CreateQueue" | " POST" | " " | " 7a62c49f-347e-4fc4-9331-6e8e7a96aa73" | SqsClient . builder() | { c -> c. createQueue(CreateQueueRequest . builder(). queueName(" somequeue" ). build()) } | """
383
- <CreateQueueResponse>
384
- <CreateQueueResult><QueueUrl>https://queue.amazonaws.com/123456789012/MyQueue</QueueUrl></CreateQueueResult>
385
- <ResponseMetadata><RequestId>7a62c49f-347e-4fc4-9331-6e8e7a96aa73</RequestId></ResponseMetadata>
386
- </CreateQueueResponse>
387
- """
388
- " Sqs" | " SendMessage" | " POST" | " " | " 27daac76-34dd-47df-bd01-1f6e873584a0" | SqsClient . builder() | { c -> c. sendMessage(SendMessageRequest . builder(). queueUrl(" someurl" ). messageBody(" " ). build()) } | """
389
- <SendMessageResponse>
390
- <SendMessageResult>
391
- <MD5OfMessageBody>d41d8cd98f00b204e9800998ecf8427e</MD5OfMessageBody>
392
- <MD5OfMessageAttributes>3ae8f24a165a8cedc005670c81a27295</MD5OfMessageAttributes>
393
- <MessageId>5fea7756-0ea4-451a-a703-a558b933e274</MessageId>
394
- </SendMessageResult>
395
- <ResponseMetadata><RequestId>27daac76-34dd-47df-bd01-1f6e873584a0</RequestId></ResponseMetadata>
396
- </SendMessageResponse>
397
- """
391
+ " Sqs" | " CreateQueue" | " POST" | " " | " 7a62c49f-347e-4fc4-9331-6e8e7a96aa73" | SqsClient . builder() | { c -> c. createQueue(CreateQueueRequest . builder(). queueName(" somequeue" ). build()) } | {
392
+ if (! Boolean . getBoolean(" testLatestDeps" )) {
393
+ def content = """
394
+ <CreateQueueResponse>
395
+ <CreateQueueResult><QueueUrl>https://queue.amazonaws.com/123456789012/MyQueue</QueueUrl></CreateQueueResult>
396
+ <ResponseMetadata><RequestId>7a62c49f-347e-4fc4-9331-6e8e7a96aa73</RequestId></ResponseMetadata>
397
+ </CreateQueueResponse>
398
+ """
399
+ return HttpResponse . of(HttpStatus . OK , MediaType . PLAIN_TEXT_UTF_8 , content)
400
+ }
401
+ def content = """
402
+ {
403
+ "QueueUrl":"https://queue.amazonaws.com/123456789012/MyQueue"
404
+ }
405
+ """
406
+ ResponseHeaders headers = ResponseHeaders . builder(HttpStatus . OK )
407
+ .contentType(MediaType . PLAIN_TEXT_UTF_8 )
408
+ .add(" x-amzn-RequestId" , " 7a62c49f-347e-4fc4-9331-6e8e7a96aa73" )
409
+ .build()
410
+ return HttpResponse . of(headers, HttpData . of(StandardCharsets . UTF_8 , content))
411
+ }
412
+ " Sqs" | " SendMessage" | " POST" | " " | " 27daac76-34dd-47df-bd01-1f6e873584a0" | SqsClient . builder() | { c -> c. sendMessage(SendMessageRequest . builder(). queueUrl(" someurl" ). messageBody(" " ). build()) } | {
413
+ if (! Boolean . getBoolean(" testLatestDeps" )) {
414
+ def content = """
415
+ <SendMessageResponse>
416
+ <SendMessageResult>
417
+ <MD5OfMessageBody>d41d8cd98f00b204e9800998ecf8427e</MD5OfMessageBody>
418
+ <MD5OfMessageAttributes>3ae8f24a165a8cedc005670c81a27295</MD5OfMessageAttributes>
419
+ <MessageId>5fea7756-0ea4-451a-a703-a558b933e274</MessageId>
420
+ </SendMessageResult>
421
+ <ResponseMetadata><RequestId>27daac76-34dd-47df-bd01-1f6e873584a0</RequestId></ResponseMetadata>
422
+ </SendMessageResponse>
423
+ """
424
+ return HttpResponse . of(HttpStatus . OK , MediaType . PLAIN_TEXT_UTF_8 , content)
425
+ }
426
+ def content = """
427
+ {
428
+ "MD5OfMessageBody":"d41d8cd98f00b204e9800998ecf8427e",
429
+ "MD5OfMessageAttributes":"3ae8f24a165a8cedc005670c81a27295",
430
+ "MessageId":"5fea7756-0ea4-451a-a703-a558b933e274"
431
+ }
432
+ """
433
+ ResponseHeaders headers = ResponseHeaders . builder(HttpStatus . OK )
434
+ .contentType(MediaType . PLAIN_TEXT_UTF_8 )
435
+ .add(" x-amzn-RequestId" , " 27daac76-34dd-47df-bd01-1f6e873584a0" )
436
+ .build()
437
+ return HttpResponse . of(headers, HttpData . of(StandardCharsets . UTF_8 , content))
438
+ }
398
439
" Ec2" | " AllocateAddress" | " POST" | " " | " 59dbff89-35bd-4eac-99ed-be587EXAMPLE" | Ec2Client . builder() | { c -> c. allocateAddress() } | """
399
440
<AllocateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
400
441
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
@@ -417,7 +458,13 @@ abstract class AbstractAws2ClientTest extends InstrumentationSpecification {
417
458
.region(Region . AP_NORTHEAST_1 )
418
459
.credentialsProvider(CREDENTIALS_PROVIDER )
419
460
.build()
420
- server. enqueue(HttpResponse . of(HttpStatus . OK , MediaType . PLAIN_TEXT_UTF_8 , body))
461
+
462
+ if (body instanceof Closure ) {
463
+ server. enqueue(body. call())
464
+ } else {
465
+ server. enqueue(HttpResponse . of(HttpStatus . OK , MediaType . PLAIN_TEXT_UTF_8 , body))
466
+ }
467
+
421
468
def response = call. call(client)
422
469
423
470
if (response instanceof Future ) {
@@ -470,22 +517,54 @@ abstract class AbstractAws2ClientTest extends InstrumentationSpecification {
470
517
" S3" | " GetObject" | " GET" | path(" somebucket" , " somekey" ) | " UNKNOWN" | S3AsyncClient . builder() | { c -> c. getObject(GetObjectRequest . builder(). bucket(" somebucket" ). key(" somekey" ). build(), AsyncResponseTransformer . toBytes()) } | " 1234567890"
471
518
// Kinesis seems to expect an http2 response which is incompatible with our test server.
472
519
// "Kinesis" | "DeleteStream" | "POST" | "/" | "UNKNOWN" | KinesisAsyncClient.builder() | { c -> c.deleteStream(DeleteStreamRequest.builder().streamName("somestream").build()) } | ""
473
- " Sqs" | " CreateQueue" | " POST" | " " | " 7a62c49f-347e-4fc4-9331-6e8e7a96aa73" | SqsAsyncClient . builder() | { c -> c. createQueue(CreateQueueRequest . builder(). queueName(" somequeue" ). build()) } | """
474
- <CreateQueueResponse>
475
- <CreateQueueResult><QueueUrl>https://queue.amazonaws.com/123456789012/MyQueue</QueueUrl></CreateQueueResult>
476
- <ResponseMetadata><RequestId>7a62c49f-347e-4fc4-9331-6e8e7a96aa73</RequestId></ResponseMetadata>
477
- </CreateQueueResponse>
478
- """
479
- " Sqs" | " SendMessage" | " POST" | " " | " 27daac76-34dd-47df-bd01-1f6e873584a0" | SqsAsyncClient . builder() | { c -> c. sendMessage(SendMessageRequest . builder(). queueUrl(" someurl" ). messageBody(" " ). build()) } | """
480
- <SendMessageResponse>
481
- <SendMessageResult>
482
- <MD5OfMessageBody>d41d8cd98f00b204e9800998ecf8427e</MD5OfMessageBody>
483
- <MD5OfMessageAttributes>3ae8f24a165a8cedc005670c81a27295</MD5OfMessageAttributes>
484
- <MessageId>5fea7756-0ea4-451a-a703-a558b933e274</MessageId>
485
- </SendMessageResult>
486
- <ResponseMetadata><RequestId>27daac76-34dd-47df-bd01-1f6e873584a0</RequestId></ResponseMetadata>
487
- </SendMessageResponse>
488
- """
520
+ " Sqs" | " CreateQueue" | " POST" | " " | " 7a62c49f-347e-4fc4-9331-6e8e7a96aa73" | SqsAsyncClient . builder() | { c -> c. createQueue(CreateQueueRequest . builder(). queueName(" somequeue" ). build()) } | {
521
+ if (! Boolean . getBoolean(" testLatestDeps" )) {
522
+ def content = """
523
+ <CreateQueueResponse>
524
+ <CreateQueueResult><QueueUrl>https://queue.amazonaws.com/123456789012/MyQueue</QueueUrl></CreateQueueResult>
525
+ <ResponseMetadata><RequestId>7a62c49f-347e-4fc4-9331-6e8e7a96aa73</RequestId></ResponseMetadata>
526
+ </CreateQueueResponse>
527
+ """
528
+ return HttpResponse . of(HttpStatus . OK , MediaType . PLAIN_TEXT_UTF_8 , content)
529
+ }
530
+ def content = """
531
+ {
532
+ "QueueUrl":"https://queue.amazonaws.com/123456789012/MyQueue"
533
+ }
534
+ """
535
+ ResponseHeaders headers = ResponseHeaders . builder(HttpStatus . OK )
536
+ .contentType(MediaType . PLAIN_TEXT_UTF_8 )
537
+ .add(" x-amzn-RequestId" , " 7a62c49f-347e-4fc4-9331-6e8e7a96aa73" )
538
+ .build()
539
+ return HttpResponse . of(headers, HttpData . of(StandardCharsets . UTF_8 , content))
540
+ }
541
+ " Sqs" | " SendMessage" | " POST" | " " | " 27daac76-34dd-47df-bd01-1f6e873584a0" | SqsAsyncClient . builder() | { c -> c. sendMessage(SendMessageRequest . builder(). queueUrl(" someurl" ). messageBody(" " ). build()) } | {
542
+ if (! Boolean . getBoolean(" testLatestDeps" )) {
543
+ def content = """
544
+ <SendMessageResponse>
545
+ <SendMessageResult>
546
+ <MD5OfMessageBody>d41d8cd98f00b204e9800998ecf8427e</MD5OfMessageBody>
547
+ <MD5OfMessageAttributes>3ae8f24a165a8cedc005670c81a27295</MD5OfMessageAttributes>
548
+ <MessageId>5fea7756-0ea4-451a-a703-a558b933e274</MessageId>
549
+ </SendMessageResult>
550
+ <ResponseMetadata><RequestId>27daac76-34dd-47df-bd01-1f6e873584a0</RequestId></ResponseMetadata>
551
+ </SendMessageResponse>
552
+ """
553
+ return HttpResponse . of(HttpStatus . OK , MediaType . PLAIN_TEXT_UTF_8 , content)
554
+ }
555
+ def content = """
556
+ {
557
+ "MD5OfMessageBody":"d41d8cd98f00b204e9800998ecf8427e",
558
+ "MD5OfMessageAttributes":"3ae8f24a165a8cedc005670c81a27295",
559
+ "MessageId":"5fea7756-0ea4-451a-a703-a558b933e274"
560
+ }
561
+ """
562
+ ResponseHeaders headers = ResponseHeaders . builder(HttpStatus . OK )
563
+ .contentType(MediaType . PLAIN_TEXT_UTF_8 )
564
+ .add(" x-amzn-RequestId" , " 27daac76-34dd-47df-bd01-1f6e873584a0" )
565
+ .build()
566
+ return HttpResponse . of(headers, HttpData . of(StandardCharsets . UTF_8 , content))
567
+ }
489
568
" Ec2" | " AllocateAddress" | " POST" | " " | " 59dbff89-35bd-4eac-99ed-be587EXAMPLE" | Ec2AsyncClient . builder() | { c -> c. allocateAddress() } | """
490
569
<AllocateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
491
570
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
0 commit comments