datadog-lambda 2.23.1 → 3.24.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: 9cddc5701e2fd24ab4ae01089f2eb7a1beee75da183f2540060639a898279637
4
- data.tar.gz: 94ba04342ac432d6ab95d40bbfbbbfb44b2e186a84c8571e1e2c93514448b29b
3
+ metadata.gz: 95cfdc9d348ccc91adda2193dc1c42c6c7533154b2c845a9f7517ca8f35e7d45
4
+ data.tar.gz: 9770541d230535fd72916d237d647c63447ac5c0b563589dd011e0a9b1199336
5
5
  SHA512:
6
- metadata.gz: 784af632d4b1a84667eb6ff68a32cea62c92d3861237bc414eee868f6c39c9d257153330d691eb53c6e496ce5dadc366e18f03b4e79550b3ded5718692b49d64
7
- data.tar.gz: 720cfbdba885607139157881b78a3ce398368e96828d896b9782d57a5d75b45f8fe27e348f097732db65e36c7f5c250cc6160ae5db4ffebff9e7d6de1d8aa001
6
+ metadata.gz: 13dec18ab59eb3bea0a73a5a674d58350e008fe6bb9e4fbaae3952da0efc8a8607dc919bc0078ead238cb41844867045c29ba8258f1ebe1a8e5bae8d5390626d
7
+ data.tar.gz: edeb3616cd4a0d2a43183113069b5ed334930e34ddbb639ad5eead60e2c4593b6ca50289da301a498f933c0f703b2bfd91f9b79be74b7591176f765ef43c1f1a
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # `ddtrace`` is an optional dependency for the ruby package
3
+ # `datadog`` is an optional dependency for the ruby package
4
4
  begin
5
- require 'ddtrace'
5
+ require 'datadog'
6
6
  rescue LoadError
7
- Datadog::Utils.logger.debug 'dd-trace unavailable'
7
+ Datadog::Utils.logger.debug 'datadog unavailable'
8
8
  end
9
9
 
10
10
  module Datadog
@@ -38,10 +38,9 @@ module Datadog
38
38
  context = Datadog::Trace.trace_context
39
39
  source = context[:source] if context
40
40
  options[:tags]['_dd.parent_source'] = source if source && source != 'ddtrace'
41
- options[:resource] = @function_name
41
+ options[:resource] = 'dd-tracer-serverless-span'
42
42
  options[:service] = 'aws.lambda'
43
- options[:span_type] = 'serverless'
44
- Datadog::Trace.apply_datadog_trace_context(Datadog::Trace.trace_context)
43
+ options[:type] = 'serverless'
45
44
 
46
45
  trace_digest = Datadog::Utils.send_start_invocation_request(event:)
47
46
  # Only continue trace from a new one if it exist, or else,
@@ -49,11 +48,13 @@ module Datadog
49
48
  options[:continue_from] = trace_digest if trace_digest
50
49
 
51
50
  @trace = Datadog::Tracing.trace('aws.lambda', **options)
51
+
52
+ Datadog::Trace.apply_datadog_trace_context(Datadog::Trace.trace_context)
52
53
  end
53
54
  # rubocop:enable Metrics/AbcSize
54
55
 
55
56
  def on_end(response:)
56
- Datadog::Utils.send_end_invocation_request(response:)
57
+ Datadog::Utils.send_end_invocation_request(response:, span_id: @trace.id)
57
58
  @trace&.finish
58
59
  end
59
60
 
@@ -19,6 +19,9 @@ module Datadog
19
19
  START_INVOCATION_PATH = '/lambda/start-invocation'
20
20
  END_INVOCATION_PATH = '/lambda/end-invocation'
21
21
 
22
+ DD_SPAN_ID_HEADER = 'x-datadog-span-id'
23
+ DD_PARENT_ID_HEADER = Datadog::Tracing::Distributed::Datadog::PARENT_ID_KEY
24
+
22
25
  START_INVOCATION_URI = URI(EXTENSION_BASE_URL + START_INVOCATION_PATH).freeze
23
26
  END_INVOCATION_URI = URI(EXTENSION_BASE_URL + END_INVOCATION_PATH).freeze
24
27
 
@@ -49,7 +52,8 @@ module Datadog
49
52
  Datadog::Utils.logger.debug "failed on start invocation request to extension: #{e}"
50
53
  end
51
54
 
52
- def self.send_end_invocation_request(response:)
55
+ # rubocop:disable Metrics/AbcSize
56
+ def self.send_end_invocation_request(response:, span_id:)
53
57
  return unless extension_running?
54
58
 
55
59
  request = Net::HTTP::Post.new(END_INVOCATION_URI)
@@ -59,12 +63,20 @@ module Datadog
59
63
  trace_digest = Datadog::Tracing.active_trace&.to_digest
60
64
 
61
65
  PROPAGATOR.inject!(trace_digest, request)
66
+ # Propagator doesn't inject span_id, so we do it manually
67
+ # It is needed for the extension to take this span id
68
+ request[DD_SPAN_ID_HEADER] = span_id.to_s
69
+ # Remove Parent ID if it is the same as the Span ID
70
+ request.delete(DD_PARENT_ID_HEADER) if request[DD_PARENT_ID_HEADER] == span_id.to_s
71
+ Datadog::Utils.logger.debug "End invocation request headers: #{request.to_hash}"
72
+
62
73
  Net::HTTP.start(END_INVOCATION_URI.host, END_INVOCATION_URI.port) do |http|
63
74
  http.request(request)
64
75
  end
65
76
  rescue StandardError => e
66
77
  Datadog::Utils.logger.debug "failed on end invocation request to extension: #{e}"
67
78
  end
79
+ # rubocop:enable Metrics/AbcSize
68
80
 
69
81
  def self.request_headers
70
82
  {
@@ -14,21 +14,19 @@ 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)
18
- end
19
-
20
- def self.update_log_level
21
- log_level = (ENV['DD_LOG_LEVEL'] || 'error').downcase
22
- logger.level = case log_level
23
- when 'debug'
24
- Logger::DEBUG
25
- when 'info'
26
- Logger::INFO
27
- when 'warn'
28
- Logger::WARN
29
- else
30
- Logger::ERROR
31
- end
17
+ @logger ||= Logger.new($stderr).tap do |logger|
18
+ log_level = (ENV['DD_LOG_LEVEL'] || 'error').downcase
19
+ logger.level = case log_level
20
+ when 'debug'
21
+ Logger::DEBUG
22
+ when 'info'
23
+ Logger::INFO
24
+ when 'warn'
25
+ Logger::WARN
26
+ else
27
+ Logger::ERROR
28
+ end
29
+ end
32
30
  end
33
31
  end
34
32
  end
@@ -11,9 +11,9 @@
11
11
  module Datadog
12
12
  module Lambda
13
13
  module VERSION
14
- MAJOR = 2
15
- MINOR = 23
16
- PATCH = 1
14
+ MAJOR = 3
15
+ MINOR = 24
16
+ PATCH = 0
17
17
  PRE = nil
18
18
 
19
19
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
@@ -56,7 +56,6 @@ module Datadog
56
56
  # @param context [Object] lambda context
57
57
  # @param block [Proc] implementation of the handler function.
58
58
  def self.wrap(event, context, &block)
59
- Datadog::Utils.update_log_level
60
59
  @listener ||= initialize_listener
61
60
  record_enhanced('invocations', context)
62
61
  begin
@@ -115,9 +114,9 @@ module Datadog
115
114
  datadog_lambda: Datadog::Lambda::VERSION::STRING.to_sym
116
115
  }
117
116
  begin
118
- tags[:dd_trace] = Gem.loaded_specs['ddtrace'].version
117
+ tags[:dd_trace] = Gem.loaded_specs['datadog'].version
119
118
  rescue StandardError
120
- Datadog::Utils.logger.debug 'dd-trace unavailable'
119
+ Datadog::Utils.logger.debug 'datadog unavailable'
121
120
  end
122
121
  # If we have an alias...
123
122
  unless function_alias.nil?
@@ -188,7 +187,7 @@ module Datadog
188
187
 
189
188
  # Only initialize listener if Tracing enabled.
190
189
  unless Datadog::Tracing.enabled?
191
- Datadog::Utils.logger.debug 'dd-trace unavailable'
190
+ Datadog::Utils.logger.debug 'datadog unavailable'
192
191
  return nil
193
192
  end
194
193
 
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.23.1
4
+ version: 3.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Datadog, Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-25 00:00:00.000000000 Z
11
+ date: 2025-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-xray-sdk
@@ -53,19 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.16.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: ddtrace
56
+ name: datadog
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.23.3
61
+ version: '2.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 1.23.3
68
+ version: '2.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement