@@ -20,27 +20,29 @@ import * as sinon from 'sinon';
2020import { awsEcsDetector , AwsEcsDetectorSync } from '../../src' ;
2121import {
2222 assertEmptyResource ,
23- assertCloudResource ,
2423 assertContainerResource ,
2524} from '@opentelemetry/contrib-test-utils' ;
2625import { Resource } from '@opentelemetry/resources' ;
2726import {
28- SEMRESATTRS_CLOUD_PLATFORM ,
29- SEMRESATTRS_AWS_ECS_CONTAINER_ARN ,
30- SEMRESATTRS_AWS_ECS_CLUSTER_ARN ,
31- SEMRESATTRS_AWS_ECS_LAUNCHTYPE ,
32- SEMRESATTRS_AWS_ECS_TASK_ARN ,
33- SEMRESATTRS_AWS_ECS_TASK_REVISION ,
34- SEMRESATTRS_AWS_ECS_TASK_FAMILY ,
35- SEMRESATTRS_AWS_LOG_GROUP_NAMES ,
36- SEMRESATTRS_AWS_LOG_GROUP_ARNS ,
37- SEMRESATTRS_AWS_LOG_STREAM_NAMES ,
38- SEMRESATTRS_AWS_LOG_STREAM_ARNS ,
39- CLOUDPROVIDERVALUES_AWS ,
40- CLOUDPLATFORMVALUES_AWS_ECS ,
41- } from '@opentelemetry/semantic-conventions' ;
42- // Patch until the OpenTelemetry SDK is updated to ship this attribute
43- import { SemanticResourceAttributes as AdditionalSemanticResourceAttributes } from '../../src/detectors/SemanticResourceAttributes' ;
27+ ATTR_AWS_ECS_CLUSTER_ARN ,
28+ ATTR_AWS_ECS_CONTAINER_ARN ,
29+ ATTR_AWS_ECS_LAUNCHTYPE ,
30+ ATTR_AWS_ECS_TASK_ARN ,
31+ ATTR_AWS_ECS_TASK_FAMILY ,
32+ ATTR_AWS_ECS_TASK_REVISION ,
33+ ATTR_AWS_LOG_GROUP_ARNS ,
34+ ATTR_AWS_LOG_GROUP_NAMES ,
35+ ATTR_AWS_LOG_STREAM_ARNS ,
36+ ATTR_AWS_LOG_STREAM_NAMES ,
37+ ATTR_CLOUD_ACCOUNT_ID ,
38+ ATTR_CLOUD_AVAILABILITY_ZONE ,
39+ ATTR_CLOUD_PLATFORM ,
40+ ATTR_CLOUD_PROVIDER ,
41+ ATTR_CLOUD_REGION ,
42+ ATTR_CLOUD_RESOURCE_ID ,
43+ CLOUD_PROVIDER_VALUE_AWS ,
44+ CLOUD_PLATFORM_VALUE_AWS_ECS ,
45+ } from '../../src/semconv' ;
4446import { readFileSync } from 'fs' ;
4547import * as os from 'os' ;
4648import { join } from 'path' ;
@@ -65,70 +67,96 @@ const assertEcsResource = (
6567 resource : Resource ,
6668 validations : EcsResourceAttributes
6769) => {
68- assertCloudResource ( resource , {
69- provider : CLOUDPROVIDERVALUES_AWS ,
70- accountId : validations . accountId ,
71- region : validations . region ,
72- zone : validations . zone ,
73- } ) ;
7470 assert . strictEqual (
75- resource . attributes [ SEMRESATTRS_CLOUD_PLATFORM ] ,
76- CLOUDPLATFORMVALUES_AWS_ECS
71+ resource . attributes [ ATTR_CLOUD_PROVIDER ] ,
72+ CLOUD_PROVIDER_VALUE_AWS
73+ ) ;
74+ assert . strictEqual (
75+ resource . attributes [ ATTR_CLOUD_PLATFORM ] ,
76+ CLOUD_PLATFORM_VALUE_AWS_ECS
7777 ) ;
78- if ( validations . containerArn )
78+ if ( validations . accountId ) {
79+ assert . strictEqual (
80+ resource . attributes [ ATTR_CLOUD_ACCOUNT_ID ] ,
81+ validations . accountId
82+ ) ;
83+ }
84+ if ( validations . region ) {
85+ assert . strictEqual (
86+ resource . attributes [ ATTR_CLOUD_REGION ] ,
87+ validations . region
88+ ) ;
89+ }
90+ if ( validations . zone ) {
7991 assert . strictEqual (
80- resource . attributes [ SEMRESATTRS_AWS_ECS_CONTAINER_ARN ] ,
92+ resource . attributes [ ATTR_CLOUD_AVAILABILITY_ZONE ] ,
93+ validations . zone
94+ ) ;
95+ }
96+ if ( validations . containerArn ) {
97+ assert . strictEqual (
98+ resource . attributes [ ATTR_AWS_ECS_CONTAINER_ARN ] ,
8199 validations . containerArn
82100 ) ;
83- assert . strictEqual (
84- resource . attributes [ AdditionalSemanticResourceAttributes . CLOUD_RESOURCE_ID ] ,
85- validations . containerArn
86- ) ;
87- if ( validations . clusterArn )
88101 assert . strictEqual (
89- resource . attributes [ SEMRESATTRS_AWS_ECS_CLUSTER_ARN ] ,
102+ resource . attributes [ ATTR_CLOUD_RESOURCE_ID ] ,
103+ validations . containerArn
104+ ) ;
105+ }
106+ if ( validations . clusterArn ) {
107+ assert . strictEqual (
108+ resource . attributes [ ATTR_AWS_ECS_CLUSTER_ARN ] ,
90109 validations . clusterArn
91110 ) ;
92- if ( validations . launchType )
111+ }
112+ if ( validations . launchType ) {
93113 assert . strictEqual (
94- resource . attributes [ SEMRESATTRS_AWS_ECS_LAUNCHTYPE ] ,
114+ resource . attributes [ ATTR_AWS_ECS_LAUNCHTYPE ] ,
95115 validations . launchType
96116 ) ;
97- if ( validations . taskArn )
117+ }
118+ if ( validations . taskArn ) {
98119 assert . strictEqual (
99- resource . attributes [ SEMRESATTRS_AWS_ECS_TASK_ARN ] ,
120+ resource . attributes [ ATTR_AWS_ECS_TASK_ARN ] ,
100121 validations . taskArn
101122 ) ;
102- if ( validations . taskFamily )
123+ }
124+ if ( validations . taskFamily ) {
103125 assert . strictEqual (
104- resource . attributes [ SEMRESATTRS_AWS_ECS_TASK_FAMILY ] ,
126+ resource . attributes [ ATTR_AWS_ECS_TASK_FAMILY ] ,
105127 validations . taskFamily
106128 ) ;
107- if ( validations . taskRevision )
129+ }
130+ if ( validations . taskRevision ) {
108131 assert . strictEqual (
109- resource . attributes [ SEMRESATTRS_AWS_ECS_TASK_REVISION ] ,
132+ resource . attributes [ ATTR_AWS_ECS_TASK_REVISION ] ,
110133 validations . taskRevision
111134 ) ;
112- if ( validations . logGroupNames )
135+ }
136+ if ( validations . logGroupNames ) {
113137 assert . deepEqual (
114- resource . attributes [ SEMRESATTRS_AWS_LOG_GROUP_NAMES ] ,
138+ resource . attributes [ ATTR_AWS_LOG_GROUP_NAMES ] ,
115139 validations . logGroupNames
116140 ) ;
117- if ( validations . logGroupArns )
141+ }
142+ if ( validations . logGroupArns ) {
118143 assert . deepEqual (
119- resource . attributes [ SEMRESATTRS_AWS_LOG_GROUP_ARNS ] ,
144+ resource . attributes [ ATTR_AWS_LOG_GROUP_ARNS ] ,
120145 validations . logGroupArns
121146 ) ;
122- if ( validations . logStreamNames )
147+ }
148+ if ( validations . logStreamNames ) {
123149 assert . deepEqual (
124- resource . attributes [ SEMRESATTRS_AWS_LOG_STREAM_NAMES ] ,
150+ resource . attributes [ ATTR_AWS_LOG_STREAM_NAMES ] ,
125151 validations . logStreamNames
126152 ) ;
127- if ( validations . logStreamArns )
153+ }
154+ if ( validations . logStreamArns ) {
128155 assert . deepEqual (
129- resource . attributes [ SEMRESATTRS_AWS_LOG_STREAM_ARNS ] ,
156+ resource . attributes [ ATTR_AWS_LOG_STREAM_ARNS ] ,
130157 validations . logStreamArns
131158 ) ;
159+ }
132160} ;
133161
134162describe ( 'AwsEcsResourceDetector' , ( ) => {
0 commit comments