Module: OpenTelemetry::Resource::Detector::AWS::EKS

Extended by:
EKS
Included in:
EKS
Defined in:
lib/opentelemetry/resource/detector/aws/eks.rb

Overview

EKS contains detect class method for determining EKS resource attributes

Constant Summary collapse

CONTAINER_ID_LENGTH =

Container ID length from cgroup file

64
HTTP_TIMEOUT =

HTTP request timeout in seconds

5
TOKEN_PATH =

Kubernetes token and certificate paths

'/var/run/secrets/kubernetes.io/serviceaccount/token'
CERT_PATH =
'/var/run/secrets/kubernetes.io/serviceaccount/ca.crt'
AWS_AUTH_PATH =

Kubernetes API paths

'/api/v1/namespaces/kube-system/configmaps/aws-auth'
CLUSTER_INFO_PATH =
'/api/v1/namespaces/amazon-cloudwatch/configmaps/cluster-info'
RESOURCE =

Create a constant for resource semantic conventions

OpenTelemetry::SemanticConventions::Resource

Instance Method Summary collapse

Instance Method Details

#detectObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/opentelemetry/resource/detector/aws/eks.rb', line 39

def detect
  # Return empty resource if not running on K8s
  return OpenTelemetry::SDK::Resources::Resource.create({}) unless k8s?

  resource_attributes = {}

  begin
    # Get K8s credentials
    cred_value = k8s_cred_value

    # Verify this is an EKS cluster
    unless eks?(cred_value)
      OpenTelemetry.logger.debug('Could not confirm process is running on EKS')
      return OpenTelemetry::SDK::Resources::Resource.create({})
    end

    # Get cluster name and container ID
    cluster_name_val = cluster_name(cred_value)
    container_id_val = container_id

    if container_id_val.empty? && cluster_name_val.empty?
      OpenTelemetry.logger.debug('Neither cluster name nor container ID found on EKS process')
      return OpenTelemetry::SDK::Resources::Resource.create({})
    end

    # Set resource attributes
    resource_attributes[RESOURCE::CLOUD_PROVIDER] = 'aws'
    resource_attributes[RESOURCE::CLOUD_PLATFORM] = 'aws_eks'
    resource_attributes[RESOURCE::K8S_CLUSTER_NAME] = cluster_name_val unless cluster_name_val.empty?
    resource_attributes[RESOURCE::CONTAINER_ID] = container_id_val unless container_id_val.empty?
  rescue StandardError => e
    OpenTelemetry.logger.debug("EKS resource detection failed: #{e.message}")
    return OpenTelemetry::SDK::Resources::Resource.create({})
  end

  resource_attributes.delete_if { |_key, value| value.nil? || value.empty? }
  OpenTelemetry::SDK::Resources::Resource.create(resource_attributes)
end