@@ -29,6 +29,9 @@ module EC2
2929 # Timeout in seconds for HTTP requests
3030 HTTP_TIMEOUT = 1
3131
32+ # Create a constant for resource semantic conventions
33+ RESOURCE = OpenTelemetry ::SemanticConventions ::Resource
34+
3235 def detect
3336 # Implementation for EC2 detection supporting both IMDSv1 and IMDSv2
3437 resource_attributes = { }
@@ -46,15 +49,15 @@ def detect
4649 hostname = fetch_hostname ( token )
4750
4851 # Set resource attributes from the identity document
49- resource_attributes [ OpenTelemetry :: SemanticConventions :: Resource ::CLOUD_PROVIDER ] = 'aws'
50- resource_attributes [ OpenTelemetry :: SemanticConventions :: Resource ::CLOUD_PLATFORM ] = 'aws_ec2'
51- resource_attributes [ OpenTelemetry :: SemanticConventions :: Resource ::CLOUD_ACCOUNT_ID ] = identity [ 'accountId' ]
52- resource_attributes [ OpenTelemetry :: SemanticConventions :: Resource ::CLOUD_REGION ] = identity [ 'region' ]
53- resource_attributes [ OpenTelemetry :: SemanticConventions :: Resource ::CLOUD_AVAILABILITY_ZONE ] = identity [ 'availabilityZone' ]
54-
55- resource_attributes [ OpenTelemetry :: SemanticConventions :: Resource ::HOST_ID ] = identity [ 'instanceId' ]
56- resource_attributes [ OpenTelemetry :: SemanticConventions :: Resource ::HOST_TYPE ] = identity [ 'instanceType' ]
57- resource_attributes [ OpenTelemetry :: SemanticConventions :: Resource ::HOST_NAME ] = hostname
52+ resource_attributes [ RESOURCE ::CLOUD_PROVIDER ] = 'aws'
53+ resource_attributes [ RESOURCE ::CLOUD_PLATFORM ] = 'aws_ec2'
54+ resource_attributes [ RESOURCE ::CLOUD_ACCOUNT_ID ] = identity [ 'accountId' ]
55+ resource_attributes [ RESOURCE ::CLOUD_REGION ] = identity [ 'region' ]
56+ resource_attributes [ RESOURCE ::CLOUD_AVAILABILITY_ZONE ] = identity [ 'availabilityZone' ]
57+
58+ resource_attributes [ RESOURCE ::HOST_ID ] = identity [ 'instanceId' ]
59+ resource_attributes [ RESOURCE ::HOST_TYPE ] = identity [ 'instanceType' ]
60+ resource_attributes [ RESOURCE ::HOST_NAME ] = hostname
5861 rescue StandardError => e
5962 OpenTelemetry . logger . debug ( "EC2 resource detection failed: #{ e . message } " )
6063 return OpenTelemetry ::SDK ::Resources ::Resource . create ( { } )
0 commit comments