Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: remove duplicate hostname resource attribute #433

Merged
merged 3 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Detectors
module GoogleCloudPlatform
extend self

def detect # rubocop:disable Metrics/AbcSize
def detect # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
gcp_env = Google::Cloud::Env.new
resource_attributes = {}
resource_constants = OpenTelemetry::SDK::Resources::Constants
Expand All @@ -24,15 +24,16 @@ def detect # rubocop:disable Metrics/AbcSize
resource_attributes[resource_constants::CLOUD_RESOURCE[:region]] = gcp_env.instance_attribute('cluster-location')
resource_attributes[resource_constants::CLOUD_RESOURCE[:zone]] = gcp_env.instance_zone

resource_attributes[resource_constants::HOST_RESOURCE[:hostname]] = hostname
resource_attributes[resource_constants::HOST_RESOURCE[:id]] = gcp_env.lookup_metadata('instance', 'id')
resource_attributes[resource_constants::HOST_RESOURCE[:name]] = gcp_env.lookup_metadata('instance', 'hostname')
resource_attributes[resource_constants::HOST_RESOURCE[:name]] = ENV['HOSTNAME'] ||
gcp_env.lookup_metadata('instance', 'hostname') ||
safe_gethostname
end

if gcp_env.kubernetes_engine?
resource_attributes[resource_constants::K8S_RESOURCE[:cluster_name]] = gcp_env.instance_attribute('cluster-name')
resource_attributes[resource_constants::K8S_RESOURCE[:namespace_name]] = gcp_env.kubernetes_engine_namespace_id
resource_attributes[resource_constants::K8S_RESOURCE[:pod_name]] = hostname
resource_attributes[resource_constants::K8S_RESOURCE[:pod_name]] = ENV['HOSTNAME'] || safe_gethostname

resource_attributes[resource_constants::CONTAINER_RESOURCE[:name]] = ENV['CONTAINER_NAME']
end
Expand All @@ -43,8 +44,8 @@ def detect # rubocop:disable Metrics/AbcSize

private

def hostname
ENV['HOSTNAME'] || Socket.gethostname
def safe_gethostname
Socket.gethostname
rescue StandardError
''
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
'cloud.account.id' => 'opentelemetry',
'cloud.region' => 'us-central1',
'cloud.zone' => 'us-central1-a',
'host.hostname' => 'opentelemetry-test',
'host.id' => 'opentelemetry-test',
'host.name' => 'opentelemetry-test',
'k8s.cluster.name' => 'opentelemetry-cluster',
Expand Down
4 changes: 0 additions & 4 deletions sdk/lib/opentelemetry/sdk/resources/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ module Constants

# Attributes defining a computing instance (e.g. host).
HOST_RESOURCE = {
# Hostname of the host. It contains what the hostname command returns on the
# host machine.
hostname: 'host.hostname',

# Unique host id. For Cloud this must be the instance_id assigned by the
# cloud provider
id: 'host.id',
Expand Down