aws-xray-sdk 0.13.0 → 0.15.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: 7519a013ac4db9cf9536638f8abc1d77dc71c4a7edbb5dbc2b43bfc6f1ab3296
4
- data.tar.gz: 58567280e37b1e041720d7cf1c86f1b55d38e992a2e6f19444950bc491d2ef7a
3
+ metadata.gz: d66dc2f94d7c560ccfcadf771798ece570a3adb37e14cbb6ee5df2c7c21e4493
4
+ data.tar.gz: 8a3a1bb4a8a401eaa76d5a5cd5f9147ede245749d4178d5e034e73beddd66a1d
5
5
  SHA512:
6
- metadata.gz: 38640d9e8aa2bf1f2328b26670878056713e9e916934ade89ca4ef1132b998f3544b89e01ae3fa7ab619582e2db4487719dd132228c9a51273e7bc27e91cca06
7
- data.tar.gz: b8d0aa1b3f0bc098cdd32e4f61ab810b4c1beee48aec785481edaf365c74174eda5a136e271b5b37c5aaed8ae6f8a74daeb2191f220d381520fe4ac6352fc03d
6
+ metadata.gz: ee957cc6062a09d99c3f2d2b009c3336b616efabedfba3f5f4aa61a65f1300d4bcb73a21d73c8d7056499ae72edf2212e9a45fa98afe05a844e6ea7eb6921622
7
+ data.tar.gz: 649c3ec1ecb12015f6ab6c8f7180d7569d97c21e704ee597c6b6c22297dcaa2517850f20afda61622818f34084eec77e661d70b435bf6cd80aedda976151c897
@@ -13,7 +13,7 @@ module XRay
13
13
  LOCAL_KEY = '_aws_xray_entity'.freeze
14
14
  CONTEXT_MISSING_KEY = 'AWS_XRAY_CONTEXT_MISSING'.freeze
15
15
  SUPPORTED_STRATEGY = %w[RUNTIME_ERROR LOG_ERROR IGNORE_ERROR].freeze
16
- DEFAULT_STRATEGY = SUPPORTED_STRATEGY[0]
16
+ DEFAULT_STRATEGY = SUPPORTED_STRATEGY[1]
17
17
 
18
18
  attr_reader :context_missing
19
19
 
@@ -345,6 +345,11 @@ module XRay
345
345
  request_parameters: %I[
346
346
  topic_arn
347
347
  ]
348
+ },
349
+ publish_batch: {
350
+ request_parameters: %I[
351
+ topic_arn
352
+ ]
348
353
  }
349
354
  }
350
355
  }
@@ -155,7 +155,8 @@ module XRay
155
155
  if (a = annotations.to_h) && !a.empty?
156
156
  h[:annotations] = a
157
157
  end
158
- if (m = @metadata) && !m.to_h.empty?
158
+ # make sure @metadata is defined before evaluating it, to prevent warning `variable @metadata not initialized`
159
+ if (defined?(@metadata) && m = @metadata) && !m.to_h.empty?
159
160
  h[:metadata] = m.to_h
160
161
  end
161
162
 
@@ -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
- @@aws ||= begin
15
- { ecs: { container: Socket.gethostname } }
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
@@ -1,3 +1,3 @@
1
1
  module XRay
2
- VERSION = '0.13.0'
2
+ VERSION = '0.15.0'
3
3
  end
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.13.0
4
+ version: 0.15.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: 2022-01-04 00:00:00.000000000 Z
11
+ date: 2023-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-xray