datadog-lambda 2.21.0 → 2.23.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: 6c867a4e0858e0ba773829993e4c60b2d84b26f8afe4e69a766ac75f6ef454c5
4
- data.tar.gz: feaa85e2d5d998b32602b74958792a656f692eab4950fdc7da0cccb7d12542bd
3
+ metadata.gz: d7d5f92e39c4579b9ac265f60f354a128a2f02c348e98127142081b3593ea28c
4
+ data.tar.gz: 19821c8a70157f6738a9a47dd4ccf3d69ef853322e261e15596af68041eb8959
5
5
  SHA512:
6
- metadata.gz: cd5062d00ae5f88a8c5021f6c76c3b87fa9236d035508e04dbd33113cf51a5b7bec006060ab6dc12ea27da46feaf78ae3eb98d9bd4c907b5a972c7176ca40ee7
7
- data.tar.gz: 823cc2efc44cfefd3e0829ca038e966f6b999fd5c2648131a91a2b8b805dbd8ae5aeb5cdba1c14d3c8579aafffb719679b8e1bdd60306f37c80c3bc176f154d2
6
+ metadata.gz: 48c653819b1eb3f353a183820310381e7ee5e67691d79988572bb9482054e74c71e683f359ce051d28c1239a0b8edd07c530e986f1f734b435b3d413a1d2f786
7
+ data.tar.gz: 3ce2f6c46406aaa8557f3a7ea01eeb3b62516edc0d4ee1d518141a444932dcdda6a0ad358a0c1a2c861be14a1d852602548074064552b9d89b902f141c3fd62a
@@ -17,6 +17,7 @@ module Datadog
17
17
  DD_TRACE_ID_HEADER = 'x-datadog-trace-id'
18
18
  DD_PARENT_ID_HEADER = 'x-datadog-parent-id'
19
19
  DD_SAMPLING_PRIORITY_HEADER = 'x-datadog-sampling-priority'
20
+ DD_ORIGIN = 'x-datadog-origin'
20
21
  DD_XRAY_SUBSEGMENT_NAME = 'datadog-metadata'
21
22
  DD_XRAY_SUBSEGMENT_KEY = 'trace'
22
23
  DD_XRAY_SUBSEGMENT_NAMESPACE = 'datadog'
@@ -10,15 +10,15 @@ end
10
10
  module Datadog
11
11
  # TraceListener tracks tracing context information
12
12
  module Trace
13
- class <<self
13
+ class << self
14
14
  def apply_datadog_trace_context(context)
15
15
  unless context.nil?
16
16
  trace_id = context[:trace_id].to_i
17
17
  span_id = context[:parent_id].to_i
18
18
  sampling_priority = context[:sample_mode]
19
19
  trace_digest = Datadog::Tracing::TraceDigest.new(
20
- span_id: span_id,
21
- trace_id: trace_id,
20
+ span_id:,
21
+ trace_id:,
22
22
  trace_sampling_priority: sampling_priority
23
23
  )
24
24
  Datadog::Tracing.continue_trace!(trace_digest)
@@ -32,8 +32,8 @@ module Datadog
32
32
  Datadog::Trace.trace_context = trace_context
33
33
  Datadog::Utils.logger.debug "extracted trace context #{trace_context}"
34
34
  options = get_option_tags(
35
- request_context: request_context,
36
- cold_start: cold_start
35
+ request_context:,
36
+ cold_start:
37
37
  )
38
38
  context = Datadog::Trace.trace_context
39
39
  source = context[:source] if context
@@ -42,13 +42,18 @@ module Datadog
42
42
  options[:service] = 'aws.lambda'
43
43
  options[:span_type] = 'serverless'
44
44
  Datadog::Trace.apply_datadog_trace_context(Datadog::Trace.trace_context)
45
+
46
+ trace_digest = Datadog::Utils.send_start_invocation_request(event:)
47
+ # Only continue trace from a new one if it exist, or else,
48
+ # it will create a new trace, which is not ideal here.
49
+ options[:continue_from] = trace_digest if trace_digest
50
+
45
51
  @trace = Datadog::Tracing.trace('aws.lambda', **options)
46
- Datadog::Utils.send_start_invocation_request(event: event)
47
52
  end
48
53
  # rubocop:enable Metrics/AbcSize
49
54
 
50
55
  def on_end(response:)
51
- Datadog::Utils.send_end_invocation_request(response: response)
56
+ Datadog::Utils.send_end_invocation_request(response:)
52
57
  @trace&.finish
53
58
  end
54
59
 
@@ -60,17 +65,16 @@ module Datadog
60
65
  function_arn = tk.length > 7 ? tk[0, 7].join(':') : function_arn
61
66
  function_version = tk.length > 7 ? tk[7] : '$LATEST'
62
67
  function_name = request_context.function_name
63
- options = {
68
+ {
64
69
  tags: {
65
- cold_start: cold_start,
66
- function_arn: function_arn,
67
- function_version: function_version,
70
+ cold_start:,
71
+ function_arn:,
72
+ function_version:,
68
73
  request_id: request_context.aws_request_id,
69
74
  functionname: function_name.nil? || function_name.empty? ? nil : function_name.downcase,
70
75
  resource_names: function_name
71
76
  }
72
77
  }
73
- options
74
78
  end
75
79
  end
76
80
  end
@@ -30,9 +30,9 @@ module Datadog
30
30
  return nil
31
31
  end
32
32
  {
33
- trace_id: trace_id,
34
- parent_id: parent_id,
35
- sample_mode: sample_mode,
33
+ trace_id:,
34
+ parent_id:,
35
+ sample_mode:,
36
36
  source: SOURCE_XRAY
37
37
  }
38
38
  end
@@ -95,7 +95,7 @@ module Datadog
95
95
  trace_id, parent_id, sampled = header.split(';')
96
96
  .map { |v| parse_assignment(v) }
97
97
 
98
- return nil if trace_id.nil? || parent_id.nil? || sampled. nil?
98
+ return nil if trace_id.nil? || parent_id.nil? || sampled.nil?
99
99
 
100
100
  {
101
101
  xray_trace_id: trace_id,
@@ -8,6 +8,7 @@
8
8
  # Copyright 2023 Datadog, Inc.
9
9
  #
10
10
  require 'net/http'
11
+ require 'datadog/tracing/contrib/http/distributed/fetcher'
11
12
 
12
13
  module Datadog
13
14
  # Utils contains utility functions shared between modules
@@ -21,6 +22,11 @@ module Datadog
21
22
  START_INVOCATION_URI = URI(EXTENSION_BASE_URL + START_INVOCATION_PATH).freeze
22
23
  END_INVOCATION_URI = URI(EXTENSION_BASE_URL + END_INVOCATION_PATH).freeze
23
24
 
25
+ # Internal communications use Datadog tracing headers
26
+ PROPAGATOR = Tracing::Distributed::Datadog.new(
27
+ fetcher: Tracing::Contrib::HTTP::Distributed::Fetcher
28
+ )
29
+
24
30
  def self.extension_running?
25
31
  return @is_extension_running unless @is_extension_running.nil?
26
32
 
@@ -35,11 +41,10 @@ module Datadog
35
41
  return unless extension_running?
36
42
 
37
43
  response = Net::HTTP.post(START_INVOCATION_URI, event.to_json, request_headers)
44
+ # Add origin, since tracer expects it for extraction
45
+ response[Datadog::Trace::DD_ORIGIN] = 'lambda'
38
46
 
39
- trace_digest = Tracing::Propagation::HTTP.extract(response)
40
- # Only continue trace from a new one if it exist, or else,
41
- # it will create a new trace, which is not ideal here.
42
- Tracing.continue_trace!(trace_digest) if trace_digest
47
+ PROPAGATOR.extract(response)
43
48
  rescue StandardError => e
44
49
  Datadog::Utils.logger.debug "failed on start invocation request to extension: #{e}"
45
50
  end
@@ -51,8 +56,9 @@ module Datadog
51
56
  request.body = response.to_json
52
57
  request[Datadog::Core::Transport::Ext::HTTP::HEADER_DD_INTERNAL_UNTRACED_REQUEST] = 1
53
58
 
54
- trace = Datadog::Tracing.active_trace
55
- Tracing::Propagation::HTTP.inject!(trace, request)
59
+ trace_digest = Datadog::Tracing.active_trace&.to_digest
60
+
61
+ PROPAGATOR.inject!(trace_digest, request)
56
62
  Net::HTTP.start(END_INVOCATION_URI.host, END_INVOCATION_URI.port) do |http|
57
63
  http.request(request)
58
64
  end
@@ -14,7 +14,7 @@ module Datadog
14
14
  # Utils contains utility functions shared between modules
15
15
  module Utils
16
16
  def self.logger
17
- @logger ||= Logger.new(STDOUT)
17
+ @logger ||= Logger.new($stdout)
18
18
  end
19
19
 
20
20
  def self.update_log_level
@@ -12,7 +12,7 @@ module Datadog
12
12
  module Lambda
13
13
  module VERSION
14
14
  MAJOR = 2
15
- MINOR = 21
15
+ MINOR = 23
16
16
  PATCH = 0
17
17
  PRE = nil
18
18
 
@@ -61,7 +61,7 @@ module Datadog
61
61
  record_enhanced('invocations', context)
62
62
  begin
63
63
  cold = @is_cold_start
64
- @listener&.on_start(event: event, request_context: context, cold_start: cold)
64
+ @listener&.on_start(event:, request_context: context, cold_start: cold)
65
65
  @response = block.call
66
66
  rescue StandardError => e
67
67
  record_enhanced('errors', context)
@@ -88,7 +88,7 @@ module Datadog
88
88
  raise 'name must be a string' unless name.is_a?(String)
89
89
  raise 'value must be a number' unless value.is_a?(Numeric)
90
90
 
91
- @metrics_client.distribution(name, value, time: time, **tags)
91
+ @metrics_client.distribution(name, value, time:, **tags)
92
92
  end
93
93
 
94
94
  def self.dd_lambda_layer_tag
@@ -129,7 +129,7 @@ module Datadog
129
129
  tags[:executedversion] = context.function_version
130
130
  end
131
131
  # Append the alias to the resource tag
132
- tags[:resource] = context.function_name + ':' + function_alias
132
+ tags[:resource] = "#{context.function_name}:#{function_alias}"
133
133
  end
134
134
 
135
135
  tags
@@ -196,7 +196,7 @@ module Datadog
196
196
  handler_name: handler,
197
197
  function_name: function,
198
198
  patch_http: @patch_http,
199
- merge_xray_traces: merge_xray_traces
199
+ merge_xray_traces:
200
200
  )
201
201
  end
202
202
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datadog-lambda
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.21.0
4
+ version: 2.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Datadog, Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-16 00:00:00.000000000 Z
11
+ date: 2024-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-xray-sdk
@@ -38,20 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.15.6
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.15.6
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: ddtrace
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: 1.15.0
61
+ version: 1.23.3
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: 1.15.0
68
+ version: 1.23.3
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +114,14 @@ dependencies:
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '0.74'
117
+ version: '1'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '0.74'
124
+ version: '1'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: solargraph
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -148,7 +162,7 @@ licenses:
148
162
  - Apache-2.0
149
163
  metadata:
150
164
  allowed_push_host: https://rubygems.org
151
- post_install_message:
165
+ post_install_message:
152
166
  rdoc_options: []
153
167
  require_paths:
154
168
  - lib
@@ -156,15 +170,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
156
170
  requirements:
157
171
  - - ">="
158
172
  - !ruby/object:Gem::Version
159
- version: 2.7.0
173
+ version: 3.2.0
160
174
  required_rubygems_version: !ruby/object:Gem::Requirement
161
175
  requirements:
162
176
  - - ">="
163
177
  - !ruby/object:Gem::Version
164
178
  version: '0'
165
179
  requirements: []
166
- rubygems_version: 3.1.6
167
- signing_key:
180
+ rubygems_version: 3.5.18
181
+ signing_key:
168
182
  specification_version: 4
169
183
  summary: Instruments your Ruby AWS Lambda functions with Datadog
170
184
  test_files: []