@@ -32,7 +32,6 @@ import {
32
32
MetricAttributeGenerator ,
33
33
SERVICE_METRIC ,
34
34
} from './metric-attribute-generator' ;
35
- import { RegionalResourceArnParser } from './regional-resource-arn-parser' ;
36
35
import { SqsUrlParser } from './sqs-url-parser' ;
37
36
import { LAMBDA_APPLICATION_SIGNALS_REMOTE_ENVIRONMENT } from './aws-opentelemetry-configurator' ;
38
37
@@ -113,20 +112,8 @@ export class AwsMetricAttributeGenerator implements MetricAttributeGenerator {
113
112
AwsMetricAttributeGenerator . setService ( resource , span , attributes ) ;
114
113
AwsMetricAttributeGenerator . setEgressOperation ( span , attributes ) ;
115
114
AwsMetricAttributeGenerator . setRemoteServiceAndOperation ( span , attributes ) ;
116
- const isRemoteResourceIdentifierPresent = AwsMetricAttributeGenerator . setRemoteResourceTypeAndIdentifier (
117
- span ,
118
- attributes
119
- ) ;
115
+ AwsMetricAttributeGenerator . setRemoteResourceTypeAndIdentifier ( span , attributes ) ;
120
116
AwsMetricAttributeGenerator . setRemoteEnvironment ( span , attributes ) ;
121
- if ( isRemoteResourceIdentifierPresent ) {
122
- const isAccountIdAndRegionPresent = AwsMetricAttributeGenerator . setRemoteResourceAccountIdAndRegion (
123
- span ,
124
- attributes
125
- ) ;
126
- if ( ! isAccountIdAndRegionPresent ) {
127
- AwsMetricAttributeGenerator . setRemoteResourceAccessKeyAndRegion ( span , attributes ) ;
128
- }
129
- }
130
117
AwsMetricAttributeGenerator . setSpanKindForDependency ( span , attributes ) ;
131
118
AwsMetricAttributeGenerator . setRemoteDbUser ( span , attributes ) ;
132
119
@@ -382,7 +369,7 @@ export class AwsMetricAttributeGenerator implements MetricAttributeGenerator {
382
369
* href="https://docs.aws.amazon.com/cloudcontrolapi/latest/userguide/supported-resources.html">AWS
383
370
* Cloud Control resource format</a>.
384
371
*/
385
- private static setRemoteResourceTypeAndIdentifier ( span : ReadableSpan , attributes : Attributes ) : boolean {
372
+ private static setRemoteResourceTypeAndIdentifier ( span : ReadableSpan , attributes : Attributes ) : void {
386
373
let remoteResourceType : AttributeValue | undefined ;
387
374
let remoteResourceIdentifier : AttributeValue | undefined ;
388
375
let cloudFormationIdentifier : AttributeValue | undefined ;
@@ -396,25 +383,11 @@ export class AwsMetricAttributeGenerator implements MetricAttributeGenerator {
396
383
) {
397
384
remoteResourceType = NORMALIZED_DYNAMO_DB_SERVICE_NAME + '::Table' ;
398
385
remoteResourceIdentifier = AwsMetricAttributeGenerator . escapeDelimiters ( awsTableNames [ 0 ] ) ;
399
- } else if ( AwsSpanProcessingUtil . isKeyPresent ( span , AWS_ATTRIBUTE_KEYS . AWS_DYNAMODB_TABLE_ARN ) ) {
400
- remoteResourceType = NORMALIZED_DYNAMO_DB_SERVICE_NAME + '::Table' ;
401
- remoteResourceIdentifier = AwsMetricAttributeGenerator . escapeDelimiters (
402
- RegionalResourceArnParser . extractDynamoDbTableNameFromArn (
403
- span . attributes [ AWS_ATTRIBUTE_KEYS . AWS_DYNAMODB_TABLE_ARN ]
404
- )
405
- ) ;
406
386
} else if ( AwsSpanProcessingUtil . isKeyPresent ( span , AWS_ATTRIBUTE_KEYS . AWS_KINESIS_STREAM_NAME ) ) {
407
387
remoteResourceType = NORMALIZED_KINESIS_SERVICE_NAME + '::Stream' ;
408
388
remoteResourceIdentifier = AwsMetricAttributeGenerator . escapeDelimiters (
409
389
span . attributes [ AWS_ATTRIBUTE_KEYS . AWS_KINESIS_STREAM_NAME ]
410
390
) ;
411
- } else if ( AwsSpanProcessingUtil . isKeyPresent ( span , AWS_ATTRIBUTE_KEYS . AWS_KINESIS_STREAM_ARN ) ) {
412
- remoteResourceType = NORMALIZED_KINESIS_SERVICE_NAME + '::Stream' ;
413
- remoteResourceIdentifier = AwsMetricAttributeGenerator . escapeDelimiters (
414
- RegionalResourceArnParser . extractKinesisStreamNameFromArn (
415
- span . attributes [ AWS_ATTRIBUTE_KEYS . AWS_KINESIS_STREAM_ARN ]
416
- )
417
- ) ;
418
391
} else if ( AwsSpanProcessingUtil . isKeyPresent ( span , AWS_ATTRIBUTE_KEYS . AWS_S3_BUCKET ) ) {
419
392
remoteResourceType = NORMALIZED_S3_SERVICE_NAME + '::Bucket' ;
420
393
remoteResourceIdentifier = AwsMetricAttributeGenerator . escapeDelimiters (
@@ -425,31 +398,31 @@ export class AwsMetricAttributeGenerator implements MetricAttributeGenerator {
425
398
426
399
remoteResourceType = NORMALIZED_SNS_SERVICE_NAME + '::Topic' ;
427
400
remoteResourceIdentifier = AwsMetricAttributeGenerator . escapeDelimiters (
428
- RegionalResourceArnParser . extractResourceNameFromArn ( snsArn )
401
+ this . extractResourceNameFromArn ( snsArn )
429
402
) ;
430
403
cloudFormationIdentifier = AwsMetricAttributeGenerator . escapeDelimiters ( snsArn ) ;
431
404
} else if ( AwsSpanProcessingUtil . isKeyPresent ( span , AWS_ATTRIBUTE_KEYS . AWS_SECRETSMANAGER_SECRET_ARN ) ) {
432
405
const secretsArn = span . attributes [ AWS_ATTRIBUTE_KEYS . AWS_SECRETSMANAGER_SECRET_ARN ] ;
433
406
434
407
remoteResourceType = NORMALIZED_SECRETSMANAGER_SERVICE_NAME + '::Secret' ;
435
408
remoteResourceIdentifier = AwsMetricAttributeGenerator . escapeDelimiters (
436
- RegionalResourceArnParser . extractResourceNameFromArn ( secretsArn )
409
+ this . extractResourceNameFromArn ( secretsArn )
437
410
) ;
438
411
cloudFormationIdentifier = AwsMetricAttributeGenerator . escapeDelimiters ( secretsArn ) ;
439
412
} else if ( AwsSpanProcessingUtil . isKeyPresent ( span , AWS_ATTRIBUTE_KEYS . AWS_STEPFUNCTIONS_STATEMACHINE_ARN ) ) {
440
413
const stateMachineArn = span . attributes [ AWS_ATTRIBUTE_KEYS . AWS_STEPFUNCTIONS_STATEMACHINE_ARN ] ;
441
414
442
415
remoteResourceType = NORMALIZED_STEPFUNCTIONS_SERVICE_NAME + '::StateMachine' ;
443
416
remoteResourceIdentifier = AwsMetricAttributeGenerator . escapeDelimiters (
444
- RegionalResourceArnParser . extractResourceNameFromArn ( stateMachineArn )
417
+ this . extractResourceNameFromArn ( stateMachineArn )
445
418
) ;
446
419
cloudFormationIdentifier = AwsMetricAttributeGenerator . escapeDelimiters ( stateMachineArn ) ;
447
420
} else if ( AwsSpanProcessingUtil . isKeyPresent ( span , AWS_ATTRIBUTE_KEYS . AWS_STEPFUNCTIONS_ACTIVITY_ARN ) ) {
448
421
const activityArn = span . attributes [ AWS_ATTRIBUTE_KEYS . AWS_STEPFUNCTIONS_ACTIVITY_ARN ] ;
449
422
450
423
remoteResourceType = NORMALIZED_STEPFUNCTIONS_SERVICE_NAME + '::Activity' ;
451
424
remoteResourceIdentifier = AwsMetricAttributeGenerator . escapeDelimiters (
452
- RegionalResourceArnParser . extractResourceNameFromArn ( activityArn )
425
+ this . extractResourceNameFromArn ( activityArn )
453
426
) ;
454
427
cloudFormationIdentifier = AwsMetricAttributeGenerator . escapeDelimiters ( activityArn ) ;
455
428
} else if ( AwsSpanProcessingUtil . isKeyPresent ( span , AWS_ATTRIBUTE_KEYS . AWS_LAMBDA_FUNCTION_NAME ) ) {
@@ -527,10 +500,7 @@ export class AwsMetricAttributeGenerator implements MetricAttributeGenerator {
527
500
attributes [ AWS_ATTRIBUTE_KEYS . AWS_REMOTE_RESOURCE_TYPE ] = remoteResourceType ;
528
501
attributes [ AWS_ATTRIBUTE_KEYS . AWS_REMOTE_RESOURCE_IDENTIFIER ] = remoteResourceIdentifier ;
529
502
attributes [ AWS_ATTRIBUTE_KEYS . AWS_CLOUDFORMATION_PRIMARY_IDENTIFIER ] = cloudFormationIdentifier ;
530
- return true ;
531
503
}
532
-
533
- return false ;
534
504
}
535
505
536
506
/**
@@ -552,56 +522,6 @@ export class AwsMetricAttributeGenerator implements MetricAttributeGenerator {
552
522
}
553
523
}
554
524
555
- private static setRemoteResourceAccountIdAndRegion ( span : ReadableSpan , attributes : Attributes ) : boolean {
556
- const ARN_ATTRIBUTES : string [ ] = [
557
- AWS_ATTRIBUTE_KEYS . AWS_DYNAMODB_TABLE_ARN ,
558
- AWS_ATTRIBUTE_KEYS . AWS_KINESIS_STREAM_ARN ,
559
- AWS_ATTRIBUTE_KEYS . AWS_SNS_TOPIC_ARN ,
560
- AWS_ATTRIBUTE_KEYS . AWS_SECRETSMANAGER_SECRET_ARN ,
561
- AWS_ATTRIBUTE_KEYS . AWS_STEPFUNCTIONS_STATEMACHINE_ARN ,
562
- AWS_ATTRIBUTE_KEYS . AWS_STEPFUNCTIONS_ACTIVITY_ARN ,
563
- AWS_ATTRIBUTE_KEYS . AWS_LAMBDA_FUNCTION_ARN ,
564
- AWS_ATTRIBUTE_KEYS . AWS_BEDROCK_GUARDRAIL_ARN ,
565
- ] ;
566
- let remoteResourceAccountId : string | undefined = undefined ;
567
- let remoteResourceRegion : string | undefined = undefined ;
568
-
569
- if ( AwsSpanProcessingUtil . isKeyPresent ( span , AWS_ATTRIBUTE_KEYS . AWS_SQS_QUEUE_URL ) ) {
570
- const sqsQueueUrl = AwsMetricAttributeGenerator . escapeDelimiters (
571
- span . attributes [ AWS_ATTRIBUTE_KEYS . AWS_SQS_QUEUE_URL ]
572
- ) ;
573
- remoteResourceAccountId = SqsUrlParser . getAccountId ( sqsQueueUrl ) ;
574
- remoteResourceRegion = SqsUrlParser . getRegion ( sqsQueueUrl ) ;
575
- } else {
576
- for ( const attributeKey of ARN_ATTRIBUTES ) {
577
- if ( AwsSpanProcessingUtil . isKeyPresent ( span , attributeKey ) ) {
578
- const arn = span . attributes [ attributeKey ] ;
579
- remoteResourceAccountId = RegionalResourceArnParser . getAccountId ( arn ) ;
580
- remoteResourceRegion = RegionalResourceArnParser . getRegion ( arn ) ;
581
- break ;
582
- }
583
- }
584
- }
585
-
586
- if ( remoteResourceAccountId !== undefined && remoteResourceRegion !== undefined ) {
587
- attributes [ AWS_ATTRIBUTE_KEYS . AWS_REMOTE_RESOURCE_ACCOUNT_ID ] = remoteResourceAccountId ;
588
- attributes [ AWS_ATTRIBUTE_KEYS . AWS_REMOTE_RESOURCE_REGION ] = remoteResourceRegion ;
589
- return true ;
590
- }
591
-
592
- return false ;
593
- }
594
-
595
- private static setRemoteResourceAccessKeyAndRegion ( span : ReadableSpan , attributes : Attributes ) : void {
596
- if ( AwsSpanProcessingUtil . isKeyPresent ( span , AWS_ATTRIBUTE_KEYS . AWS_AUTH_ACCOUNT_ACCESS_KEY ) ) {
597
- attributes [ AWS_ATTRIBUTE_KEYS . AWS_REMOTE_RESOURCE_ACCOUNT_ACCESS_KEY ] =
598
- span . attributes [ AWS_ATTRIBUTE_KEYS . AWS_AUTH_ACCOUNT_ACCESS_KEY ] ;
599
- }
600
- if ( AwsSpanProcessingUtil . isKeyPresent ( span , AWS_ATTRIBUTE_KEYS . AWS_AUTH_REGION ) ) {
601
- attributes [ AWS_ATTRIBUTE_KEYS . AWS_REMOTE_RESOURCE_REGION ] = span . attributes [ AWS_ATTRIBUTE_KEYS . AWS_AUTH_REGION ] ;
602
- }
603
- }
604
-
605
525
/**
606
526
* RemoteResourceIdentifier is populated with rule <code>
607
527
* ^[{db.name}|]?{address}[|{port}]?
@@ -729,6 +649,16 @@ export class AwsMetricAttributeGenerator implements MetricAttributeGenerator {
729
649
return rpcService === 'Lambda' && span . attributes [ SEMATTRS_RPC_METHOD ] === LAMBDA_INVOKE_OPERATION ;
730
650
}
731
651
652
+ // Extracts the name of the resource from an arn
653
+ private static extractResourceNameFromArn ( attribute : AttributeValue | undefined ) : string | undefined {
654
+ if ( typeof attribute === 'string' && attribute . startsWith ( 'arn:aws:' ) ) {
655
+ const split = attribute . split ( ':' ) ;
656
+ return split [ split . length - 1 ] ;
657
+ }
658
+
659
+ return undefined ;
660
+ }
661
+
732
662
/** Span kind is needed for differentiating metrics in the EMF exporter */
733
663
private static setSpanKindForService ( span : ReadableSpan , attributes : Attributes ) : void {
734
664
let spanKind : string = SpanKind [ span . kind ] ;
0 commit comments