datadog-lambda 0.7.0 → 1.12.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: 300ec79cee959b800acfbb7db97f2495cd73357dbbf2982e3fa471912c21c4eb
4
- data.tar.gz: 8854a16bbafcaba922d387f6923fde1340ba788284c72ec6affc1afa373a1184
3
+ metadata.gz: f40ca893546c79c836081f4fb4a63aa6862e213f91453a7b630c25c59ca73ba3
4
+ data.tar.gz: 01e664333a8a5f114363a6b79d47efa46ba464d1c36372ab4178a35010058245
5
5
  SHA512:
6
- metadata.gz: 02aa89e21441a5d66ac6af0568e1fb9e441f04d392744ee0848b2b229a9e47305ac08120b8f18b0b68889c99c4e618ecad812667ff34244185e4ebd1fadb9f03
7
- data.tar.gz: fc9da6f32e2a9802bee2cfe29953ace582fbeda26a94fde8e6a1064ee80021e78783562d21d66b29c040fe6540c02808bcecc1594af73e1537c66f9f6009c0d4
6
+ metadata.gz: 6330bddce249fd6263c3858d447fbb4789f5f280517ad9a25fa669e0ce33728ed6a46e4ee03757d954c8de366d27e6db9b2602b5629f4cc0bcee3bbb18c0d777
7
+ data.tar.gz: b3e1c27fc86ce76afc6a7ceaed3161b26b34e21fac1eb38e211ec7c5c9668f5eb4ea4175ea88a3805c723054f9d2e1b0462951d9f08245296f39ad7e248b446f
@@ -7,12 +7,14 @@
7
7
  # This product includes software developed at Datadog (https://www.datadoghq.com/).
8
8
  # Copyright 2019 Datadog, Inc.
9
9
  #
10
+ # rubocop:disable Metrics/ModuleLength
10
11
 
11
12
  require 'datadog/lambda/trace/listener'
12
13
  require 'datadog/lambda/utils/logger'
13
14
  require 'datadog/lambda/trace/patch_http'
14
15
  require 'json'
15
16
  require 'time'
17
+ require 'datadog/lambda/version'
16
18
 
17
19
  module Datadog
18
20
  # Instruments AWS Lambda functions with Datadog distributed tracing and
@@ -36,6 +38,7 @@ module Datadog
36
38
  c.tracer writer: Datadog::SyncWriter.new(
37
39
  transport: Datadog::Transport::IO.default
38
40
  )
41
+ c.tags = { "_dd.origin": 'lambda' }
39
42
  yield(c) if block_given?
40
43
  end
41
44
  end
@@ -67,7 +70,6 @@ module Datadog
67
70
  # Gets the current tracing context
68
71
  def self.trace_context
69
72
  context = Hash[Datadog::Trace.trace_context]
70
- context.delete(:source)
71
73
  context
72
74
  end
73
75
 
@@ -81,34 +83,65 @@ module Datadog
81
83
  raise 'value must be a number' unless value.is_a?(Numeric)
82
84
 
83
85
  time ||= Time.now
84
- tag_list = ['dd_lambda_layer:datadog-ruby25']
86
+ time_ms = time.to_f.to_i
87
+
88
+ tag_list = ["dd_lambda_layer:datadog-ruby#{dd_lambda_layer_tag}"]
85
89
  tags.each do |tag|
86
90
  tag_list.push("#{tag[0]}:#{tag[1]}")
87
91
  end
88
- time_ms = time.to_f.to_i
89
- metric = { e: time_ms, m: name, t: tag_list, v: value }.to_json
90
- puts metric
92
+ metric = { e: time_ms, m: name, t: tag_list, v: value }
93
+ puts metric.to_json
94
+ end
95
+
96
+ def self.dd_lambda_layer_tag
97
+ RUBY_VERSION[0, 3].tr('.', '')
91
98
  end
92
99
 
93
100
  # Generate tags for enhanced metrics
94
101
  # @param context [Object] https://docs.aws.amazon.com/lambda/latest/dg/ruby-context.html
95
102
  # @return [hash] a hash of the enhanced metrics tags
103
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
96
104
  def self.gen_enhanced_tags(context)
97
105
  arn_parts = context.invoked_function_arn.split(':')
98
- {
106
+ # Check if we have an alias or version
107
+ function_alias = arn_parts[7].nil? ? nil : arn_parts[7]
108
+
109
+ tags = {
99
110
  functionname: context.function_name,
100
111
  region: arn_parts[3],
101
112
  account_id: arn_parts[4],
102
113
  memorysize: context.memory_limit_in_mb,
103
114
  cold_start: @is_cold_start,
104
- runtime: "Ruby #{RUBY_VERSION}"
115
+ runtime: "Ruby #{RUBY_VERSION}",
116
+ resource: context.function_name,
117
+ datadog_lambda: Datadog::Lambda::VERSION::STRING.to_sym
105
118
  }
119
+ begin
120
+ tags[:dd_trace] = Gem.loaded_specs['ddtrace'].version
121
+ rescue StandardError
122
+ Datadog::Utils.logger.debug 'dd-trace unavailable'
123
+ end
124
+ # If we have an alias...
125
+ unless function_alias.nil?
126
+ # If the alis version is $Latest, drop the $ for ddog tag convention.
127
+ if function_alias.start_with?('$')
128
+ function_alias[0] = ''
129
+ # If the alias is not a version number add the executed version tag
130
+ elsif !/\A\d+\z/.match(function_alias)
131
+ tags[:executedversion] = context.function_version
132
+ end
133
+ # Append the alias to the resource tag
134
+ tags[:resource] = context.function_name + ':' + function_alias
135
+ end
136
+
137
+ tags
106
138
  rescue StandardError => e
107
139
  Datadog::Utils.logger.error 'Unable to parse Lambda context' \
108
140
  "#{context}: #{e}"
109
141
  {}
110
142
  end
111
143
 
144
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
112
145
  # Format and add tags to enhanced metrics
113
146
  # This method wraps the metric method, checking the DD_ENHANCED_METRICS
114
147
  # environment variable, adding 'aws.lambda.enhanced' to the metric name,
@@ -116,7 +149,7 @@ module Datadog
116
149
  # @param metric_name [String] basic name of the metric
117
150
  # @param context [Object] AWS Ruby Lambda Context
118
151
  # @return [boolean] false if the metric was not added for some reason,
119
- # true otherwise (for ease of testing)
152
+ # true otherwise (for ease of testing
120
153
 
121
154
  def self.record_enhanced(metric_name, context)
122
155
  return false unless do_enhanced_metrics?
@@ -153,3 +186,4 @@ module Datadog
153
186
  end
154
187
  end
155
188
  end
189
+ # rubocop:enable Metrics/ModuleLength
@@ -37,22 +37,39 @@ module Datadog
37
37
  def on_end; end
38
38
 
39
39
  def on_wrap(request_context:, cold_start:, &block)
40
+ options = get_option_tags(
41
+ request_context: request_context,
42
+ cold_start: cold_start
43
+ )
44
+ context = Datadog::Trace.trace_context
45
+ source = context[:source] if context
46
+ options[:tags]['_dd.parent_source'] = source if source && source != 'ddtrace'
47
+ options[:resource] = @function_name
48
+ options[:service] = 'aws.lambda'
49
+ options[:span_type] = 'serverless'
50
+ Datadog::Trace.apply_datadog_trace_context(Datadog::Trace.trace_context)
51
+ Datadog::Trace.wrap_datadog(options) do
52
+ block.call
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def get_option_tags(request_context:, cold_start:)
59
+ function_arn = request_context.invoked_function_arn.downcase
60
+ tk = function_arn.split(':')
61
+ function_arn = tk.length > 7 ? tk[0, 7].join(':') : function_arn
62
+ function_version = tk.length > 7 ? tk[7] : '$LATEST'
40
63
  options = {
41
64
  tags: {
42
65
  cold_start: cold_start,
43
- function_arn: request_context.invoked_function_arn.downcase,
66
+ function_arn: function_arn,
67
+ function_version: function_version,
44
68
  request_id: request_context.aws_request_id,
45
69
  resource_names: request_context.function_name
46
70
  }
47
71
  }
48
-
49
- options[:resource] = @handler_name
50
- options[:service] = @function_name
51
- options[:span_type] = 'serverless'
52
- Datadog::Trace.apply_datadog_trace_context(Datadog::Trace.trace_context)
53
- Datadog::Trace.wrap_datadog(options) do
54
- block.call
55
- end
72
+ options
56
73
  end
57
74
  end
58
75
  end
@@ -30,25 +30,31 @@ module Datadog
30
30
  # NetExtensions contains patches which add tracing context to http calls
31
31
  module NetExtensions
32
32
  def request(req, body = nil, &block)
33
- logger = Datadog::Utils.logger
34
33
  begin
35
34
  context = Datadog::Trace.current_trace_context(
36
35
  Datadog::Trace.trace_context
37
36
  )
38
37
 
39
- req[Datadog::Trace::DD_SAMPLING_PRIORITY_HEADER.to_sym] =
40
- context[:sample_mode]
41
- req[Datadog::Trace::DD_PARENT_ID_HEADER.to_sym] = context[:parent_id]
42
- req[Datadog::Trace::DD_TRACE_ID_HEADER.to_sym] = context[:trace_id]
43
- logger.debug("added context #{context} to request")
38
+ req = add_ctx_to_req(req, context)
44
39
  rescue StandardError => e
45
40
  trace = e.backtrace.join("\n ")
46
- logger.debug(
41
+ Datadog::Utils.logger.debug(
47
42
  "couldn't add tracing context #{context} to request #{e}:\n#{trace}"
48
43
  )
49
44
  end
50
45
  super(req, body, &block)
51
46
  end
47
+
48
+ private
49
+
50
+ def add_ctx_to_req(req, context)
51
+ req[Datadog::Trace::DD_SAMPLING_PRIORITY_HEADER.to_sym] =
52
+ context[:sample_mode]
53
+ req[Datadog::Trace::DD_PARENT_ID_HEADER.to_sym] = context[:parent_id]
54
+ req[Datadog::Trace::DD_TRACE_ID_HEADER.to_sym] = context[:trace_id]
55
+ Datadog::Utils.logger.debug("added context #{context} to request")
56
+ req
57
+ end
52
58
  end
53
59
  end
54
60
  end
@@ -11,8 +11,8 @@
11
11
  module Datadog
12
12
  module Lambda
13
13
  module VERSION
14
- MAJOR = 0
15
- MINOR = 7
14
+ MAJOR = 1
15
+ MINOR = 12
16
16
  PATCH = 0
17
17
  PRE = nil
18
18
 
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: 0.7.0
4
+ version: 1.12.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: 2020-04-02 00:00:00.000000000 Z
11
+ date: 2020-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-xray-sdk
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.32'
33
+ version: '0.4'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.32'
40
+ version: '0.4'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -113,7 +113,7 @@ files:
113
113
  - lib/datadog/lambda/trace/xray.rb
114
114
  - lib/datadog/lambda/utils/logger.rb
115
115
  - lib/datadog/lambda/version.rb
116
- homepage: https://github.com/DataDog/dd-lambda-rb
116
+ homepage: https://github.com/DataDog/datadog-lambda-rb
117
117
  licenses:
118
118
  - Apache-2.0
119
119
  metadata:
@@ -133,8 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  - !ruby/object:Gem::Version
134
134
  version: '0'
135
135
  requirements: []
136
- rubyforge_project:
137
- rubygems_version: 2.7.6
136
+ rubygems_version: 3.0.3
138
137
  signing_key:
139
138
  specification_version: 4
140
139
  summary: Instruments your Ruby AWS Lambda functions with Datadog