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 +4 -4
- data/lib/datadog/lambda/trace/ddtrace.rb +3 -3
- data/lib/datadog/lambda/trace/listener.rb +5 -4
- data/lib/datadog/lambda/utils/extension.rb +13 -1
- data/lib/datadog/lambda/utils/logger.rb +13 -15
- data/lib/datadog/lambda/version.rb +3 -3
- data/lib/datadog/lambda.rb +3 -4
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95cfdc9d348ccc91adda2193dc1c42c6c7533154b2c845a9f7517ca8f35e7d45
|
4
|
+
data.tar.gz: 9770541d230535fd72916d237d647c63447ac5c0b563589dd011e0a9b1199336
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13dec18ab59eb3bea0a73a5a674d58350e008fe6bb9e4fbaae3952da0efc8a8607dc919bc0078ead238cb41844867045c29ba8258f1ebe1a8e5bae8d5390626d
|
7
|
+
data.tar.gz: edeb3616cd4a0d2a43183113069b5ed334930e34ddbb639ad5eead60e2c4593b6ca50289da301a498f933c0f703b2bfd91f9b79be74b7591176f765ef43c1f1a
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# `
|
3
|
+
# `datadog`` is an optional dependency for the ruby package
|
4
4
|
begin
|
5
|
-
require '
|
5
|
+
require 'datadog'
|
6
6
|
rescue LoadError
|
7
|
-
Datadog::Utils.logger.debug '
|
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] =
|
41
|
+
options[:resource] = 'dd-tracer-serverless-span'
|
42
42
|
options[:service] = 'aws.lambda'
|
43
|
-
options[:
|
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
|
-
|
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($
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
data/lib/datadog/lambda.rb
CHANGED
@@ -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['
|
117
|
+
tags[:dd_trace] = Gem.loaded_specs['datadog'].version
|
119
118
|
rescue StandardError
|
120
|
-
Datadog::Utils.logger.debug '
|
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 '
|
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:
|
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:
|
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:
|
56
|
+
name: datadog
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
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:
|
68
|
+
version: '2.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|