line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AWS::XRay::Plugin::EC2; |
2
|
2
|
|
|
2
|
|
9014
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
51
|
|
3
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
40
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
1096
|
use HTTP::Tiny; |
|
2
|
|
|
|
|
20387
|
|
|
2
|
|
|
|
|
559
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# for test |
8
|
|
|
|
|
|
|
our $_base_url = "http://169.254.169.254/latest"; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub ID_ADDR() { |
11
|
2
|
|
|
2
|
0
|
227
|
return "$_base_url/meta-data/instance-id"; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub AZ_ADDR() { |
15
|
2
|
|
|
2
|
0
|
92
|
return "$_base_url/meta-data/placement/availability-zone"; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $METADATA; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub apply_plugin { |
21
|
2
|
|
|
2
|
0
|
22
|
my ($class, $segment) = @_; |
22
|
|
|
|
|
|
|
|
23
|
2
|
|
33
|
|
|
39
|
$METADATA ||= do { |
24
|
2
|
|
|
|
|
87
|
my $ua = HTTP::Tiny->new(timeout => 1); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# get token for IMDSv2 |
27
|
2
|
|
|
|
|
415
|
my $token = do { |
28
|
2
|
|
|
|
|
42
|
my $res = $ua->request( |
29
|
|
|
|
|
|
|
"PUT", |
30
|
|
|
|
|
|
|
"$_base_url/api/token", { |
31
|
|
|
|
|
|
|
headers => { |
32
|
|
|
|
|
|
|
'X-aws-ec2-metadata-token-ttl-seconds' => '60', |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
); |
36
|
2
|
100
|
|
|
|
11602
|
$res->{success} ? $res->{content} : ''; |
37
|
|
|
|
|
|
|
}; |
38
|
2
|
|
|
|
|
7
|
my $opt = {}; |
39
|
2
|
100
|
|
|
|
7
|
if ($token ne '') { |
40
|
1
|
|
|
|
|
10
|
$opt->{headers}->{'X-aws-ec2-metadata-token'} = $token; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
2
|
|
|
|
|
4
|
my $instance_id = do { |
44
|
2
|
|
|
|
|
13
|
my $res = $ua->get(ID_ADDR, $opt); |
45
|
2
|
50
|
|
|
|
3478
|
$res->{success} ? $res->{content} : ''; |
46
|
|
|
|
|
|
|
}; |
47
|
2
|
|
|
|
|
5
|
my $az = do { |
48
|
2
|
|
|
|
|
8
|
my $res = $ua->get(AZ_ADDR, $opt); |
49
|
2
|
50
|
|
|
|
3217
|
$res->{success} ? $res->{content} : ''; |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
+{ |
53
|
2
|
|
|
|
|
77
|
instance_id => $instance_id, |
54
|
|
|
|
|
|
|
availability_zone => $az, |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
}; |
57
|
|
|
|
|
|
|
|
58
|
2
|
|
|
|
|
31
|
$segment->{origin} = 'AWS::EC2::Instance'; |
59
|
2
|
|
|
|
|
31
|
$segment->{aws}->{ec2} = $METADATA; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |