13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
+
16
17
import {
17
18
AwsInstrumentation ,
18
19
AwsSdkRequestHookInformation ,
@@ -31,26 +32,16 @@ import {
31
32
S3 ,
32
33
S3Client ,
33
34
} from '@aws-sdk/client-s3' ;
34
- import { SQS } from '@aws-sdk/client-sqs' ;
35
35
import { SpanKind } from '@opentelemetry/api' ;
36
36
37
37
// set aws environment variables, so tests in non aws environment are able to run
38
38
process . env . AWS_ACCESS_KEY_ID = 'testing' ;
39
39
process . env . AWS_SECRET_ACCESS_KEY = 'testing' ;
40
40
41
41
import 'mocha' ;
42
- import { ReadableSpan } from '@opentelemetry/sdk-trace-base' ;
43
- import { context , SpanStatusCode , trace , Span } from '@opentelemetry/api' ;
42
+ import { SpanStatusCode , Span } from '@opentelemetry/api' ;
44
43
import {
45
- MESSAGINGDESTINATIONKINDVALUES_QUEUE ,
46
- MESSAGINGOPERATIONVALUES_RECEIVE ,
47
44
SEMATTRS_HTTP_STATUS_CODE ,
48
- SEMATTRS_MESSAGING_DESTINATION ,
49
- SEMATTRS_MESSAGING_DESTINATION_KIND ,
50
- SEMATTRS_MESSAGING_MESSAGE_ID ,
51
- SEMATTRS_MESSAGING_OPERATION ,
52
- SEMATTRS_MESSAGING_SYSTEM ,
53
- SEMATTRS_MESSAGING_URL ,
54
45
SEMATTRS_RPC_METHOD ,
55
46
SEMATTRS_RPC_SERVICE ,
56
47
SEMATTRS_RPC_SYSTEM ,
@@ -62,7 +53,7 @@ import * as nock from 'nock';
62
53
63
54
const region = 'us-east-1' ;
64
55
65
- describe ( 'instrumentation-aws-sdk-v3' , ( ) => {
56
+ describe ( 'instrumentation-aws-sdk-v3 (client-s3) ' , ( ) => {
66
57
const s3Client = new S3 ( { region } ) ;
67
58
68
59
describe ( 'functional' , ( ) => {
@@ -285,189 +276,4 @@ describe('instrumentation-aws-sdk-v3', () => {
285
276
} ) ;
286
277
} ) ;
287
278
} ) ;
288
-
289
- describe ( 'custom service behavior' , ( ) => {
290
- describe ( 'SQS' , ( ) => {
291
- const sqsClient = new SQS ( { region } ) ;
292
-
293
- it ( 'sqs send add messaging attributes' , async ( ) => {
294
- nock ( `https://sqs.${ region } .amazonaws.com/` )
295
- . matchHeader ( 'content-type' , 'application/x-www-form-urlencoded' )
296
- . post ( '/' )
297
- . reply (
298
- 200 ,
299
- fs . readFileSync ( './test/mock-responses/sqs-send.xml' , 'utf8' )
300
- ) ;
301
- // @aws -sdk/client-sqs >=3.446.0 uses a new JSON protocol.
302
- nock ( `https://sqs.${ region } .amazonaws.com/` )
303
- . matchHeader ( 'content-type' , 'application/x-amz-json-1.0' )
304
- . post ( '/' )
305
- . reply (
306
- 200 ,
307
- fs . readFileSync ( './test/mock-responses/sqs-send.json' , 'utf8' )
308
- ) ;
309
-
310
- const params = {
311
- QueueUrl :
312
- 'https://sqs.us-east-1.amazonaws.com/731241200085/otel-demo-aws-sdk' ,
313
- MessageBody : 'payload example from v3 without batch' ,
314
- } ;
315
- const response = await sqsClient . sendMessage ( params ) ;
316
- expect ( getTestSpans ( ) . length ) . toBe ( 1 ) ;
317
- const [ span ] = getTestSpans ( ) ;
318
-
319
- // make sure we have the general aws attributes:
320
- expect ( span . attributes [ SEMATTRS_RPC_SYSTEM ] ) . toEqual ( 'aws-api' ) ;
321
- expect ( span . attributes [ SEMATTRS_RPC_METHOD ] ) . toEqual ( 'SendMessage' ) ;
322
- expect ( span . attributes [ SEMATTRS_RPC_SERVICE ] ) . toEqual ( 'SQS' ) ;
323
- expect ( span . attributes [ AttributeNames . AWS_REGION ] ) . toEqual ( region ) ;
324
-
325
- // custom messaging attributes
326
- expect ( span . attributes [ SEMATTRS_MESSAGING_SYSTEM ] ) . toEqual ( 'aws.sqs' ) ;
327
- expect ( span . attributes [ SEMATTRS_MESSAGING_DESTINATION_KIND ] ) . toEqual (
328
- MESSAGINGDESTINATIONKINDVALUES_QUEUE
329
- ) ;
330
- expect ( span . attributes [ SEMATTRS_MESSAGING_DESTINATION ] ) . toEqual (
331
- 'otel-demo-aws-sdk'
332
- ) ;
333
- expect ( span . attributes [ SEMATTRS_MESSAGING_URL ] ) . toEqual (
334
- params . QueueUrl
335
- ) ;
336
- expect ( span . attributes [ SEMATTRS_MESSAGING_MESSAGE_ID ] ) . toEqual (
337
- response . MessageId
338
- ) ;
339
- expect ( span . attributes [ SEMATTRS_HTTP_STATUS_CODE ] ) . toEqual ( 200 ) ;
340
- } ) ;
341
-
342
- it ( 'sqs send message batch attributes' , async ( ) => {
343
- nock ( `https://sqs.${ region } .amazonaws.com/` )
344
- . matchHeader ( 'content-type' , 'application/x-www-form-urlencoded' )
345
- . post ( '/' )
346
- . reply (
347
- 200 ,
348
- fs . readFileSync ( './test/mock-responses/sqs-send-batch.xml' , 'utf8' )
349
- ) ;
350
- nock ( `https://sqs.${ region } .amazonaws.com/` )
351
- . matchHeader ( 'content-type' , 'application/x-amz-json-1.0' )
352
- . post ( '/' )
353
- . reply (
354
- 200 ,
355
- fs . readFileSync ( './test/mock-responses/sqs-send-batch.json' , 'utf8' )
356
- ) ;
357
-
358
- const params = {
359
- QueueUrl :
360
- 'https://sqs.us-east-1.amazonaws.com/731241200085/otel-demo-aws-sdk' ,
361
- MessageBody : 'payload example from v3 without batch' ,
362
- Entries : [
363
- {
364
- Id : '1000' ,
365
- MessageBody : 'msg body for 1000' ,
366
- } ,
367
- {
368
- Id : '1001' ,
369
- MessageBody : 'msg body for 1001' ,
370
- } ,
371
- ] ,
372
- } ;
373
- await sqsClient . sendMessageBatch ( params ) ;
374
- expect ( getTestSpans ( ) . length ) . toBe ( 1 ) ;
375
- const [ span ] = getTestSpans ( ) ;
376
-
377
- // make sure we have the general aws attributes:
378
- expect ( span . attributes [ SEMATTRS_RPC_SYSTEM ] ) . toEqual ( 'aws-api' ) ;
379
- expect ( span . attributes [ SEMATTRS_RPC_METHOD ] ) . toEqual (
380
- 'SendMessageBatch'
381
- ) ;
382
- expect ( span . attributes [ SEMATTRS_RPC_SERVICE ] ) . toEqual ( 'SQS' ) ;
383
- expect ( span . attributes [ AttributeNames . AWS_REGION ] ) . toEqual ( region ) ;
384
-
385
- // messaging semantic attributes
386
- expect ( span . attributes [ SEMATTRS_MESSAGING_SYSTEM ] ) . toEqual ( 'aws.sqs' ) ;
387
- expect ( span . attributes [ SEMATTRS_MESSAGING_DESTINATION_KIND ] ) . toEqual (
388
- MESSAGINGDESTINATIONKINDVALUES_QUEUE
389
- ) ;
390
- expect ( span . attributes [ SEMATTRS_MESSAGING_DESTINATION ] ) . toEqual (
391
- 'otel-demo-aws-sdk'
392
- ) ;
393
- expect ( span . attributes [ SEMATTRS_MESSAGING_URL ] ) . toEqual (
394
- params . QueueUrl
395
- ) ;
396
- expect ( span . attributes [ SEMATTRS_HTTP_STATUS_CODE ] ) . toEqual ( 200 ) ;
397
- } ) ;
398
-
399
- it ( 'sqs receive add messaging attributes' , done => {
400
- nock ( `https://sqs.${ region } .amazonaws.com/` )
401
- . matchHeader ( 'content-type' , 'application/x-www-form-urlencoded' )
402
- . post ( '/' )
403
- . reply (
404
- 200 ,
405
- fs . readFileSync ( './test/mock-responses/sqs-receive.xml' , 'utf8' )
406
- ) ;
407
- nock ( `https://sqs.${ region } .amazonaws.com/` )
408
- . matchHeader ( 'content-type' , 'application/x-amz-json-1.0' )
409
- . post ( '/' )
410
- . reply (
411
- 200 ,
412
- fs . readFileSync ( './test/mock-responses/sqs-receive.json' , 'utf8' )
413
- ) ;
414
-
415
- const params = {
416
- QueueUrl :
417
- 'https://sqs.us-east-1.amazonaws.com/731241200085/otel-demo-aws-sdk' ,
418
- MaxNumberOfMessages : 3 ,
419
- } ;
420
- sqsClient . receiveMessage ( params ) . then ( res => {
421
- expect ( getTestSpans ( ) . length ) . toBe ( 1 ) ;
422
- const [ span ] = getTestSpans ( ) ;
423
-
424
- // make sure we have the general aws attributes:
425
- expect ( span . attributes [ SEMATTRS_RPC_SYSTEM ] ) . toEqual ( 'aws-api' ) ;
426
- expect ( span . attributes [ SEMATTRS_RPC_METHOD ] ) . toEqual (
427
- 'ReceiveMessage'
428
- ) ;
429
- expect ( span . attributes [ SEMATTRS_RPC_SERVICE ] ) . toEqual ( 'SQS' ) ;
430
- expect ( span . attributes [ AttributeNames . AWS_REGION ] ) . toEqual ( region ) ;
431
- expect ( span . attributes [ SEMATTRS_HTTP_STATUS_CODE ] ) . toEqual ( 200 ) ;
432
- done ( ) ;
433
- } ) ;
434
- } ) ;
435
-
436
- // Propagating span context to SQS ReceiveMessage promise handler is
437
- // broken with `@aws-sdk/client-sqs` v3.316.0 and later.
438
- // https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1477
439
- it . skip ( 'sqs receive context' , done => {
440
- nock ( `https://sqs.${ region } .amazonaws.com/` )
441
- . matchHeader ( 'content-type' , 'application/x-www-form-urlencoded' )
442
- . post ( '/' )
443
- . reply (
444
- 200 ,
445
- fs . readFileSync ( './test/mock-responses/sqs-receive.xml' , 'utf8' )
446
- ) ;
447
- nock ( `https://sqs.${ region } .amazonaws.com/` )
448
- . matchHeader ( 'content-type' , 'application/x-amz-json-1.0' )
449
- . post ( '/' )
450
- . reply (
451
- 200 ,
452
- fs . readFileSync ( './test/mock-responses/sqs-receive.json' , 'utf8' )
453
- ) ;
454
-
455
- const params = {
456
- QueueUrl :
457
- 'https://sqs.us-east-1.amazonaws.com/731241200085/otel-demo-aws-sdk' ,
458
- MaxNumberOfMessages : 3 ,
459
- } ;
460
- sqsClient . receiveMessage ( params ) . then ( res => {
461
- const receiveCallbackSpan = trace . getSpan ( context . active ( ) ) ;
462
- expect ( receiveCallbackSpan ) . toBeDefined ( ) ;
463
- const attributes = ( receiveCallbackSpan as unknown as ReadableSpan )
464
- . attributes ;
465
- expect ( attributes [ SEMATTRS_MESSAGING_OPERATION ] ) . toMatch (
466
- MESSAGINGOPERATIONVALUES_RECEIVE
467
- ) ;
468
- done ( ) ;
469
- } ) ;
470
- } ) ;
471
- } ) ;
472
- } ) ;
473
279
} ) ;
0 commit comments