aws-xray-sdk 0.11.2 → 0.11.3

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
- SHA1:
3
- metadata.gz: 12bf7fe4479fe58271466a730e04d20a38d125aa
4
- data.tar.gz: bd3f3df33fd65ea9f82aa5579316dd8d526d75e2
2
+ SHA256:
3
+ metadata.gz: cfc85964249b62a758e08922f43b94e994b38b85a0f220177744deb62ed4be1d
4
+ data.tar.gz: 301d7594d8e1863335108b6904c05a00806830ce2765d8a1ea099271023af0ae
5
5
  SHA512:
6
- metadata.gz: f515f1e1016a02f04ad8fee38848fd95ed432dad394befc512781cd66d7c26b6bd0191c0a7895f1bc98cd5c864722fe01ed93b536d56557e167c94a81233ff80
7
- data.tar.gz: 9527449a4c4aaccb8496bc6ff5d764609a287d986144538f3821576c44989bee3b8982387f1d9afab8d0663c09618c2f0e202c2abbb0343563c918fb2beba690
6
+ metadata.gz: a4dbd429616dcb4e9b0372c7f4909894ffb0eba783091a89d36e824138703ea9d67fac332fbde372b2774f268b76060d14f66f1d02416e1517c383a44de7fde3
7
+ data.tar.gz: 19b1591a2bd2ef1afddfd676db64701d73a71253a5f6378366440b708b8e46672d485b89050f6bad31052284724ef47bb8f52f7023c6c5aeb99ca646cd844345
@@ -28,4 +28,7 @@ module XRay
28
28
 
29
29
  class UnsupportedPatchingTargetError < AwsXRaySdkError
30
30
  end
31
+
32
+ class UnsupportedOperationError < AwsXRaySdkError
33
+ end
31
34
  end
@@ -20,8 +20,21 @@ module XRay
20
20
  super(*options)
21
21
  end
22
22
 
23
+ # HTTP requests to AWS Lambda Ruby Runtime will begin with the
24
+ # value set in ENV['AWS_LAMBDA_RUNTIME_API']
25
+ def lambda_runtime_request?(req)
26
+ ENV['AWS_LAMBDA_RUNTIME_API'] &&
27
+ req.uri &&
28
+ req.uri.to_s.start_with?('http://'+ENV['AWS_LAMBDA_RUNTIME_API']+'/')
29
+ end
30
+
31
+ def xray_sampling_request?(req)
32
+ req.path && (req.path == ('/GetSamplingRules') || req.path == ('/SamplingTargets'))
33
+ end
34
+
23
35
  def request(req, body = nil, &block)
24
- if req.path && (req.path == ('/GetSamplingRules') || req.path == ('/SamplingTargets'))
36
+ # Do not trace requests to xray or aws lambda runtime
37
+ if xray_sampling_request?(req) || lambda_runtime_request?(req)
25
38
  return super
26
39
  end
27
40
 
@@ -0,0 +1,35 @@
1
+ # AWS Lambda functions should require this file to configure the XRay.recorder
2
+ # for use within the function.
3
+
4
+ require_relative 'lambda/lambda_recorder'
5
+ require_relative 'lambda/facade_segment'
6
+ require_relative 'lambda/lambda_context'
7
+ require_relative 'lambda/lambda_streamer'
8
+
9
+ module XRay
10
+ @recorder = LambdaRecorder.new
11
+
12
+ # provide an instance of LambdaRecorder as the global XRay.recorder
13
+ def self.recorder
14
+ @recorder
15
+ end
16
+ end
17
+
18
+
19
+ # Set `XRAY_LAMBDA_PATCH_CONFIG` before requiring `aws-xray-sdk/lambda`
20
+ # to configure which libraries (if any) to instrument.
21
+ #
22
+ # By default, both `net_http` and `aws_sdk` will be instrumented
23
+ unless defined? XRAY_LAMBDA_PATCH_CONFIG
24
+ XRAY_LAMBDA_PATCH_CONFIG = %I[net_http aws_sdk]
25
+ end
26
+
27
+ # Configure the XRay.recorder with Lambda specific config.
28
+ #
29
+ # From here, a lambda may create subsegments manually, or via
30
+ # the instrumented libraries setup by XRAY_LAMBDA_PATCH_CONFIG
31
+ XRay.recorder.configure(
32
+ patch: XRAY_LAMBDA_PATCH_CONFIG,
33
+ context: XRay::LambdaContext.new,
34
+ streamer: XRay::LambdaStreamer.new
35
+ )
@@ -0,0 +1,109 @@
1
+ module XRay
2
+ class FacadeSegment < XRay::Segment
3
+
4
+ class ImmutableEmptyCollection
5
+ def [](key)
6
+ nil
7
+ end
8
+
9
+ def []=(k, v)
10
+ raise UnsupportedOperationError
11
+ end
12
+
13
+ def update(h)
14
+ raise UnsupportedOperationError
15
+ end
16
+
17
+ def to_h
18
+ {}
19
+ end
20
+ end
21
+
22
+
23
+ def initialize(trace_id: nil, name: nil, parent_id: nil, id: nil, sampled: true)
24
+ super(trace_id: trace_id, name: name, parent_id: parent_id)
25
+ @id = id
26
+ @sampled = sampled
27
+ @empty_collection = ImmutableEmptyCollection.new
28
+ end
29
+
30
+ def ready_to_send?
31
+ false #never send this facade. AWS Lambda has already created a Segment with these ids
32
+ end
33
+
34
+ #
35
+ #Methods from Entity that are not supported
36
+ #
37
+ def close(end_time: nil)
38
+ raise UnsupportedOperationError
39
+ end
40
+ def apply_status_code(status:)
41
+ raise UnsupportedOperationError
42
+ end
43
+ def merge_http_request(request:)
44
+ raise UnsupportedOperationError
45
+ end
46
+ def merge_http_response(response:)
47
+ raise UnsupportedOperationError
48
+ end
49
+ def add_exception(exception:, remote: false)
50
+ raise UnsupportedOperationError
51
+ end
52
+
53
+ #
54
+ # Mutation accessors from Entity that are not supported
55
+ #
56
+ def parent=(value)
57
+ raise UnsupportedOperationError
58
+ end
59
+ def throttle=(value)
60
+ raise UnsupportedOperationError
61
+ end
62
+ def error=(value)
63
+ raise UnsupportedOperationError
64
+ end
65
+ def fault=(value)
66
+ raise UnsupportedOperationError
67
+ end
68
+ def sampled=(value)
69
+ raise UnsupportedOperationError
70
+ end
71
+ def aws=(value)
72
+ raise UnsupportedOperationError
73
+ end
74
+ def start_time=(value)
75
+ raise UnsupportedOperationError
76
+ end
77
+ def end_time=(value)
78
+ raise UnsupportedOperationError
79
+ end
80
+
81
+ #
82
+ # Mutation accessors from Segment that are not supported
83
+ #
84
+ def origin=(value)
85
+ raise UnsupportedOperationError
86
+ end
87
+ def user=(value)
88
+ raise UnsupportedOperationError
89
+ end
90
+ def service=(value)
91
+ raise UnsupportedOperationError
92
+ end
93
+
94
+ #
95
+ # Annotations are read only
96
+ #
97
+ def annotations
98
+ @empty_collection
99
+ end
100
+
101
+ #
102
+ # Metadata is read only
103
+ #
104
+ def metadata(namespace: :default)
105
+ @empty_collection
106
+ end
107
+
108
+ end
109
+ end
@@ -0,0 +1,37 @@
1
+ require_relative '../model/trace_header'
2
+
3
+ module XRay
4
+ # LambdaContext extends the default context so that
5
+ # we can provide an appropriate FacadeSegment as the
6
+ # root context for each function invocation.
7
+ class LambdaContext < XRay::DefaultContext
8
+
9
+ TRACE_ID_ENV_VAR = '_X_AMZN_TRACE_ID'.freeze
10
+
11
+ def lambda_trace_id
12
+ ENV[TRACE_ID_ENV_VAR]
13
+ end
14
+
15
+ # If the environment trace id changes, create a new facade for that
16
+ # segment and make it the context's current entity
17
+ def check_context
18
+ #Create a new FacadeSegment if the _X_AMZN_TRACE_ID changes.
19
+ return if lambda_trace_id == @current_trace_id
20
+
21
+ @current_trace_id = lambda_trace_id
22
+ trace_header = XRay::TraceHeader.from_header_string(header_str: @current_trace_id)
23
+ segment = FacadeSegment.new(trace_id: trace_header.root,
24
+ parent_id: trace_header.parent_id,
25
+ id: trace_header.parent_id,
26
+ name: 'lambda_context',
27
+ sampled: trace_header.sampled == 1
28
+ )
29
+ store_entity(entity: segment)
30
+ end
31
+
32
+ def current_entity
33
+ check_context #ensure the FacadeSegment is current whenever the current_entity is retrieved
34
+ super
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,19 @@
1
+ require 'aws-xray-sdk/recorder'
2
+
3
+ module XRay
4
+ class LambdaRecorder < Recorder
5
+ include Logging
6
+
7
+ def begin_segment(name, trace_id: nil, parent_id: nil, sampled: nil)
8
+ # no-op
9
+ logger.warn('Cannot create segments inside Lambda function. Returning current segment.')
10
+ return current_segment
11
+ end
12
+
13
+ def end_segment(end_time: nil)
14
+ # no-op
15
+ logger.warn('Cannot end segment inside Lambda function. Ignored.')
16
+ nil
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ module XRay
2
+ # LambdaStreamer extends DefaultStreamer so that subsegments
3
+ # are sent to the XRay endpoint as they are available.
4
+ class LambdaStreamer < XRay::DefaultStreamer
5
+ def initialize
6
+ @stream_threshold = 1 #Stream every subsegment as it is available
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module XRay
2
- VERSION = '0.11.2'
2
+ VERSION = '0.11.3'
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.11.2
4
+ version: 0.11.3
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: 2019-07-18 00:00:00.000000000 Z
11
+ date: 2019-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-xray
@@ -188,6 +188,11 @@ files:
188
188
  - lib/aws-xray-sdk/facets/rails/railtie.rb
189
189
  - lib/aws-xray-sdk/facets/resources/aws_params_whitelist.rb
190
190
  - lib/aws-xray-sdk/facets/resources/aws_services_whitelist.rb
191
+ - lib/aws-xray-sdk/lambda.rb
192
+ - lib/aws-xray-sdk/lambda/facade_segment.rb
193
+ - lib/aws-xray-sdk/lambda/lambda_context.rb
194
+ - lib/aws-xray-sdk/lambda/lambda_recorder.rb
195
+ - lib/aws-xray-sdk/lambda/lambda_streamer.rb
191
196
  - lib/aws-xray-sdk/logger.rb
192
197
  - lib/aws-xray-sdk/model/annotations.rb
193
198
  - lib/aws-xray-sdk/model/cause.rb
@@ -239,8 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
244
  - !ruby/object:Gem::Version
240
245
  version: '0'
241
246
  requirements: []
242
- rubyforge_project:
243
- rubygems_version: 2.6.14
247
+ rubygems_version: 3.0.3
244
248
  signing_key:
245
249
  specification_version: 4
246
250
  summary: AWS X-Ray SDK for Ruby