@@ -16,27 +16,26 @@ module GoogleCloudPlatform
1616 def detect # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
1717 gcp_env = Google ::Cloud ::Env . new
1818 resource_attributes = { }
19- resource_constants = OpenTelemetry ::SDK ::Resources ::Constants
2019
2120 if gcp_env . compute_engine?
22- resource_attributes [ resource_constants :: CLOUD_RESOURCE [ :provider ] ] = 'gcp'
23- resource_attributes [ resource_constants :: CLOUD_RESOURCE [ :account_id ] ] = gcp_env . project_id
24- resource_attributes [ resource_constants :: CLOUD_RESOURCE [ :region ] ] = gcp_env . instance_attribute ( 'cluster-location' )
25- resource_attributes [ resource_constants :: CLOUD_RESOURCE [ :availability_zone ] ] = gcp_env . instance_zone
26-
27- resource_attributes [ resource_constants :: HOST_RESOURCE [ :id ] ] = gcp_env . lookup_metadata ( 'instance' , 'id' )
28- resource_attributes [ resource_constants :: HOST_RESOURCE [ :name ] ] = ENV [ 'HOSTNAME' ] ||
29- gcp_env . lookup_metadata ( 'instance' , 'hostname' ) ||
30- safe_gethostname
21+ resource_attributes [ OpenTelemetry :: SemanticConventions :: Resource :: CLOUD_PROVIDER ] = 'gcp'
22+ resource_attributes [ OpenTelemetry :: SemanticConventions :: Resource :: CLOUD_ACCOUNT_ID ] = gcp_env . project_id
23+ resource_attributes [ OpenTelemetry :: SemanticConventions :: Resource :: CLOUD_REGION ] = gcp_env . instance_attribute ( 'cluster-location' )
24+ resource_attributes [ OpenTelemetry :: SemanticConventions :: Resource :: CLOUD_AVAILABILITY_ZONE ] = gcp_env . instance_zone
25+
26+ resource_attributes [ OpenTelemetry :: SemanticConventions :: Resource :: HOST_ID ] = gcp_env . lookup_metadata ( 'instance' , 'id' )
27+ resource_attributes [ OpenTelemetry :: SemanticConventions :: Resource :: HOST_NAME ] = ENV [ 'HOSTNAME' ] ||
28+ gcp_env . lookup_metadata ( 'instance' , 'hostname' ) ||
29+ safe_gethostname
3130 end
3231
3332 if gcp_env . kubernetes_engine?
34- resource_attributes [ resource_constants :: K8S_RESOURCE [ :cluster_name ] ] = gcp_env . instance_attribute ( 'cluster-name' )
35- resource_attributes [ resource_constants :: K8S_RESOURCE [ :namespace_name ] ] = gcp_env . kubernetes_engine_namespace_id
36- resource_attributes [ resource_constants :: K8S_RESOURCE [ :pod_name ] ] = ENV [ 'HOSTNAME' ] || safe_gethostname
37- resource_attributes [ resource_constants :: K8S_RESOURCE [ :node_name ] ] = gcp_env . lookup_metadata ( 'instance' , 'hostname' )
33+ resource_attributes [ OpenTelemetry :: SemanticConventions :: Resource :: K8S_CLUSTER_NAME ] = gcp_env . instance_attribute ( 'cluster-name' )
34+ resource_attributes [ OpenTelemetry :: SemanticConventions :: Resource :: K8S_NAMESPACE_NAME ] = gcp_env . kubernetes_engine_namespace_id
35+ resource_attributes [ OpenTelemetry :: SemanticConventions :: Resource :: K8S_POD_NAME ] = ENV [ 'HOSTNAME' ] || safe_gethostname
36+ resource_attributes [ OpenTelemetry :: SemanticConventions :: Resource :: K8S_NODE_NAME ] = gcp_env . lookup_metadata ( 'instance' , 'hostname' )
3837
39- resource_attributes [ resource_constants :: CONTAINER_RESOURCE [ :name ] ] = ENV [ 'CONTAINER_NAME' ]
38+ resource_attributes [ OpenTelemetry :: SemanticConventions :: Resource :: CONTAINER_NAME ] = ENV [ 'CONTAINER_NAME' ]
4039 end
4140
4241 resource_attributes . delete_if { |_key , value | value . nil? || value . empty? }
0 commit comments