datadog-lambda 0.4.0 → 0.5.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.rb +53 -2
- data/lib/datadog/lambda/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8037783498999fb1a3291a4b6c72d13933efc9c4056b08f96e560debf804797d
|
4
|
+
data.tar.gz: 8f1f8794b9fd7a7886715afe3d41e9398e0d110ace2279c5bec2e2a34d2d60d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98545e61a901be1b3441ba52d197ea69dfe6eee9469d571b2a77e979d4f73c56e133cc0d9502c003342a5a78ee50fea4ca4fb0af6ad7bd3a47d9bd8d5aede373
|
7
|
+
data.tar.gz: d27d0e7a1a9774347fa5865ce508b09f91137b56e400614ad15c06ba3492a977e1734b2015d380f1d14c36b896ace3bfc64e4e4839b2533280c8d411c30503c7
|
data/lib/datadog/lambda.rb
CHANGED
@@ -18,19 +18,24 @@ module Datadog
|
|
18
18
|
# Instruments AWS Lambda functions with Datadog distributed tracing and
|
19
19
|
# custom metrics
|
20
20
|
module Lambda
|
21
|
+
@is_cold_start = true
|
21
22
|
# Wrap the body of a lambda invocation
|
22
23
|
# @param event [Object] event sent to lambda
|
23
24
|
# @param context [Object] lambda context
|
24
25
|
# @param block [Proc] implementation of the handler function.
|
25
|
-
def self.wrap(event,
|
26
|
+
def self.wrap(event, context, &block)
|
26
27
|
Datadog::Utils.update_log_level
|
27
|
-
|
28
28
|
@listener ||= Trace::Listener.new
|
29
29
|
@listener.on_start(event: event)
|
30
|
+
record_enhanced('invocations', context)
|
30
31
|
begin
|
31
32
|
res = block.call
|
33
|
+
rescue StandardError => e
|
34
|
+
record_enhanced('errors', context)
|
35
|
+
raise e
|
32
36
|
ensure
|
33
37
|
@listener.on_end
|
38
|
+
@is_cold_start = false
|
34
39
|
end
|
35
40
|
res
|
36
41
|
end
|
@@ -58,5 +63,51 @@ module Datadog
|
|
58
63
|
metric = { e: time_ms, m: name, t: tag_list, v: value }.to_json
|
59
64
|
puts metric
|
60
65
|
end
|
66
|
+
|
67
|
+
# Generate tags for enhanced metrics
|
68
|
+
# @param context [Object] https://docs.aws.amazon.com/lambda/latest/dg/ruby-context.html
|
69
|
+
# @return [hash] a hash of the enhanced metrics tags
|
70
|
+
def self.gen_enhanced_tags(context)
|
71
|
+
arn_parts = context.invoked_function_arn.split(':')
|
72
|
+
{
|
73
|
+
functionname: context.function_name,
|
74
|
+
region: arn_parts[3],
|
75
|
+
account_id: arn_parts[4],
|
76
|
+
memorysize: context.memory_limit_in_mb,
|
77
|
+
cold_start: @is_cold_start,
|
78
|
+
runtime: "Ruby #{RUBY_VERSION}"
|
79
|
+
}
|
80
|
+
rescue StandardError => e
|
81
|
+
Datadog::Utils.logger.error 'Unable to parse Lambda context' \
|
82
|
+
"#{context}: #{e}"
|
83
|
+
{}
|
84
|
+
end
|
85
|
+
|
86
|
+
# Format and add tags to enhanced metrics
|
87
|
+
# This method wraps the metric method, checking the DD_ENHANCED_METRICS
|
88
|
+
# environment variable, adding 'aws.lambda.enhanced' to the metric name,
|
89
|
+
# and adding the enhanced metric tags to the enhanced metrics.
|
90
|
+
# @param metric_name [String] basic name of the metric
|
91
|
+
# @param context [Object] AWS Ruby Lambda Context
|
92
|
+
# @return [boolean] false if the metric was not added for some reason,
|
93
|
+
# true otherwise (for ease of testing)
|
94
|
+
|
95
|
+
def self.record_enhanced(metric_name, context)
|
96
|
+
return false unless do_enhanced_metrics?
|
97
|
+
|
98
|
+
etags = gen_enhanced_tags(context)
|
99
|
+
metric("aws.lambda.enhanced.#{metric_name}", 1, etags)
|
100
|
+
true
|
101
|
+
end
|
102
|
+
|
103
|
+
# Check the DD_ENHANCED_METRICS environment variable
|
104
|
+
# @reurn [boolean] true if this lambda should have
|
105
|
+
# enhanced metrics
|
106
|
+
def self.do_enhanced_metrics?
|
107
|
+
dd_enhanced_metrics = ENV['DD_ENHANCED_METRICS']
|
108
|
+
return false if dd_enhanced_metrics.nil?
|
109
|
+
|
110
|
+
dd_enhanced_metrics.downcase == 'true'
|
111
|
+
end
|
61
112
|
end
|
62
113
|
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: 0.
|
4
|
+
version: 0.5.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: 2020-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-xray-sdk
|