Module: XRay::Plugins::EC2
- Includes:
- Logging
- Defined in:
- lib/aws-xray-sdk/plugins/ec2.rb
Overview
A plugin that gets the EC2 instance-id and AZ if running on an EC2 instance.
Constant Summary collapse
- ORIGIN =
'AWS::EC2::Instance'.freeze
- ID_ADDR =
'http://169.254.169.254/latest/meta-data/instance-id'.freeze
- AZ_ADDR =
'http://169.254.169.254/latest/meta-data/placement/availability-zone'.freeze
Class Method Summary collapse
Methods included from Logging
Class Method Details
.aws ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/aws-xray-sdk/plugins/ec2.rb', line 15 def self.aws @@aws ||= begin instance_id = open(ID_ADDR, open_timeout: 1).read az = open(AZ_ADDR, open_timeout: 1).read { ec2: { instance_id: instance_id, availability_zone: az } } rescue StandardError => e # Two attempts in total to get EC2 metadata @retries ||= 0 if @retries < 1 @retries += 1 retry else @@aws = {} Logging.logger.warn %(can not get the ec2 instance metadata due to: #{e.}.) end end end |