aws-xray-sdk 0.14.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc61d9c6666321d0823056381091a1b0ca2a3f342cb08bde2d7b580c111c5655
|
4
|
+
data.tar.gz: 2a386b6cf75fdba8750e5e96c9892ee2cd716c453177fc95478ff5712adaad4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a8f08ac7c0de83359f0d1e8eaf88e596f50d8440e320ee0e11b5fa0eb109af99901711f315de664db6bab750bcd96d78170cff419830e8c377cd86749dbaaa3
|
7
|
+
data.tar.gz: b4422f3ecdf07fd952e4351447777d03e9606003aa74ce1024402261f483814f0c0d2504792e641e2be20ada505ad9cfa4a54abe496d47ef47dcc7429b127a70
|
@@ -27,9 +27,11 @@ module XRay
|
|
27
27
|
subsegment = XRay.recorder.begin_subsegment name, namespace: 'remote'
|
28
28
|
# subsegment is nil in case of context missing
|
29
29
|
return if subsegment.nil?
|
30
|
-
|
30
|
+
# Rails 7.1 introduced time measurement in milliseconds instead seconds of causing xray-sdk to report wrong duration for transaction calls.
|
31
|
+
# This is being handled in rails 7.2 and later. https://github.com/rails/rails/pull/50779
|
32
|
+
subsegment.start_time = (::Rails::VERSION::MAJOR == 7 and ::Rails::VERSION::MINOR == 1) ? transaction.time.to_f/1000 : transaction.time.to_f
|
31
33
|
subsegment.sql = sql
|
32
|
-
XRay.recorder.end_subsegment end_time: transaction.end.to_f
|
34
|
+
XRay.recorder.end_subsegment end_time: (::Rails::VERSION::MAJOR == 7 and ::Rails::VERSION::MINOR == 1) ? transaction.end.to_f/1000 : transaction.end.to_f
|
33
35
|
end
|
34
36
|
|
35
37
|
private
|
@@ -3,19 +3,82 @@ require 'aws-xray-sdk/logger'
|
|
3
3
|
|
4
4
|
module XRay
|
5
5
|
module Plugins
|
6
|
-
# Due to lack of ECS container metadata service, the only host information
|
7
|
-
# available is the host name.
|
8
6
|
module ECS
|
9
7
|
include Logging
|
10
8
|
|
11
9
|
ORIGIN = 'AWS::ECS::Container'.freeze
|
12
10
|
|
11
|
+
# Only compatible with v4!
|
12
|
+
# The v3 metadata url does not contain cloudwatch informations
|
13
|
+
METADATA_ENV_KEY = 'ECS_CONTAINER_METADATA_URI_V4'
|
14
|
+
|
13
15
|
def self.aws
|
14
|
-
|
15
|
-
|
16
|
+
metadata = get_metadata()
|
17
|
+
|
18
|
+
begin
|
19
|
+
metadata[:ecs][:container] = Socket.gethostname
|
16
20
|
rescue StandardError => e
|
17
|
-
@@aws = {}
|
18
21
|
Logging.logger.warn %(cannot get the ecs container hostname due to: #{e.message}.)
|
22
|
+
metadata[:ecs][:container] = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
@@aws = {
|
26
|
+
ecs: metadata[:ecs],
|
27
|
+
cloudwatch_logs: metadata[:cloudwatch_logs]
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def self.get_metadata()
|
34
|
+
begin
|
35
|
+
metadata_uri = URI(ENV[METADATA_ENV_KEY])
|
36
|
+
req = Net::HTTP::Get.new(metadata_uri)
|
37
|
+
metadata_json = do_request(req)
|
38
|
+
return parse_metadata(metadata_json)
|
39
|
+
rescue StandardError => e
|
40
|
+
Logging.logger.warn %(cannot get the ecs instance metadata due to: #{e.message}. Make sure you are using Fargate platform version >=1.4.0)
|
41
|
+
{ ecs: {}, cloudwatch_logs: {} }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.parse_metadata(json_str)
|
46
|
+
data = JSON(json_str)
|
47
|
+
|
48
|
+
metadata = {
|
49
|
+
ecs: {
|
50
|
+
container_arn: data['ContainerARN'],
|
51
|
+
},
|
52
|
+
cloudwatch_logs: {
|
53
|
+
log_group: data["LogOptions"]['awslogs-group'],
|
54
|
+
log_region: data["LogOptions"]['awslogs-region'],
|
55
|
+
arn: data['ContainerARN']
|
56
|
+
}
|
57
|
+
}
|
58
|
+
metadata
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.do_request(request)
|
62
|
+
begin
|
63
|
+
response = Net::HTTP.start(request.uri.hostname, read_timeout: 1) { |http|
|
64
|
+
http.request(request)
|
65
|
+
}
|
66
|
+
|
67
|
+
if response.code == '200'
|
68
|
+
return response.body
|
69
|
+
else
|
70
|
+
raise(StandardError.new('Unsuccessful response::' + response.code + '::' + response.message))
|
71
|
+
end
|
72
|
+
rescue StandardError => e
|
73
|
+
# Two attempts in total to complete the request successfully
|
74
|
+
@retries ||= 0
|
75
|
+
if @retries < 1
|
76
|
+
@retries += 1
|
77
|
+
retry
|
78
|
+
else
|
79
|
+
Logging.logger.warn %(Failed to complete request due to: #{e.message}.)
|
80
|
+
raise e
|
81
|
+
end
|
19
82
|
end
|
20
83
|
end
|
21
84
|
end
|
data/lib/aws-xray-sdk/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-xray-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amazon Web Services
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-xray
|