datadog-lambda 0.9.0 → 1.13.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: 15ddc462886c4a35ba66d327ebbc2be17c403b2d47cab973fa06e05d6df3d2d1
4
- data.tar.gz: b90918aa8b2372e2149e4b084b5ee97d9a8268ebff7ebb83a0e1a6a3751488c1
3
+ metadata.gz: ca6cf663eccb791efbd864d07e484ff8af81f167c287031168f5b2c73cf6a2be
4
+ data.tar.gz: 60ec7b7457d071b32c6f00460b0b0311c01353deb116aafd48410176f6cc2e08
5
5
  SHA512:
6
- metadata.gz: 71b82b6b3ec47c17fff39fb4f3bfd40c6d2ef7ba477baa82de83a87bc710fc0114fa7aadc84153908db40de6af8437248e9634b8838a6d60af54e44fefbe8e29
7
- data.tar.gz: ca9afd36577caa6b5efef5663add0b37e32bfa953b55ee2909bc2f104a139e0a6478fcddcdde67687537672ae88b2d50f81b3d79c4aefa2967c29cae4faf367b
6
+ metadata.gz: 1eb9090b949bbb8cd2ff4a94ee73d9dfba070268756edc511d471140e6d2f147ea59f462bfdfdc8f29b6b946fe29e8c247f60ee12ffd7f200825447ff78d1395
7
+ data.tar.gz: d91a50fb6ebe4d3c2cfc3146d25be43589bf06d36ea042f0c7e3d5493b8c5d15c641b8cacde3668d88e62b720a7687c876bee2d271c336f9b941a1326194c1e9
@@ -14,6 +14,7 @@ require 'datadog/lambda/utils/logger'
14
14
  require 'datadog/lambda/trace/patch_http'
15
15
  require 'json'
16
16
  require 'time'
17
+ require 'datadog/lambda/version'
17
18
 
18
19
  module Datadog
19
20
  # Instruments AWS Lambda functions with Datadog distributed tracing and
@@ -37,6 +38,7 @@ module Datadog
37
38
  c.tracer writer: Datadog::SyncWriter.new(
38
39
  transport: Datadog::Transport::IO.default
39
40
  )
41
+ c.tags = { "_dd.origin": 'lambda' }
40
42
  yield(c) if block_given?
41
43
  end
42
44
  end
@@ -68,7 +70,6 @@ module Datadog
68
70
  # Gets the current tracing context
69
71
  def self.trace_context
70
72
  context = Hash[Datadog::Trace.trace_context]
71
- context.delete(:source)
72
73
  context
73
74
  end
74
75
 
@@ -82,13 +83,18 @@ module Datadog
82
83
  raise 'value must be a number' unless value.is_a?(Numeric)
83
84
 
84
85
  time ||= Time.now
85
- 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}"]
86
89
  tags.each do |tag|
87
90
  tag_list.push("#{tag[0]}:#{tag[1]}")
88
91
  end
89
- time_ms = time.to_f.to_i
90
- metric = { e: time_ms, m: name, t: tag_list, v: value }.to_json
91
- 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('.', '')
92
98
  end
93
99
 
94
100
  # Generate tags for enhanced metrics
@@ -107,8 +113,14 @@ module Datadog
107
113
  memorysize: context.memory_limit_in_mb,
108
114
  cold_start: @is_cold_start,
109
115
  runtime: "Ruby #{RUBY_VERSION}",
110
- resource: context.function_name
116
+ resource: context.function_name,
117
+ datadog_lambda: Datadog::Lambda::VERSION::STRING.to_sym
111
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
112
124
  # If we have an alias...
113
125
  unless function_alias.nil?
114
126
  # If the alis version is $Latest, drop the $ for ddog tag convention.
@@ -41,8 +41,11 @@ module Datadog
41
41
  request_context: request_context,
42
42
  cold_start: cold_start
43
43
  )
44
- options[:resource] = @handler_name
45
- options[:service] = @function_name
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'
46
49
  options[:span_type] = 'serverless'
47
50
  Datadog::Trace.apply_datadog_trace_context(Datadog::Trace.trace_context)
48
51
  Datadog::Trace.wrap_datadog(options) do
@@ -53,17 +56,19 @@ module Datadog
53
56
  private
54
57
 
55
58
  def get_option_tags(request_context:, cold_start:)
56
- function_arn = request_context.invoked_function_arn.downcase
59
+ function_arn = request_context.invoked_function_arn.to_s.downcase
57
60
  tk = function_arn.split(':')
58
61
  function_arn = tk.length > 7 ? tk[0, 7].join(':') : function_arn
59
62
  function_version = tk.length > 7 ? tk[7] : '$LATEST'
63
+ function_name = request_context.function_name
60
64
  options = {
61
65
  tags: {
62
66
  cold_start: cold_start,
63
67
  function_arn: function_arn,
64
68
  function_version: function_version,
65
69
  request_id: request_context.aws_request_id,
66
- resource_names: request_context.function_name
70
+ functionname: function_name.nil? || function_name.empty? ? nil : function_name.downcase,
71
+ resource_names: function_name
67
72
  }
68
73
  }
69
74
  options
@@ -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 = 9
14
+ MAJOR = 1
15
+ MINOR = 13
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.9.0
4
+ version: 1.13.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-07-23 00:00:00.000000000 Z
11
+ date: 2021-08-20 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/datadog-lambda-layer-rb
116
+ homepage: https://github.com/DataDog/datadog-lambda-rb
117
117
  licenses:
118
118
  - Apache-2.0
119
119
  metadata:
@@ -133,7 +133,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  - !ruby/object:Gem::Version
134
134
  version: '0'
135
135
  requirements: []
136
- rubygems_version: 3.0.3
136
+ rubyforge_project:
137
+ rubygems_version: 2.7.6
137
138
  signing_key:
138
139
  specification_version: 4
139
140
  summary: Instruments your Ruby AWS Lambda functions with Datadog