Module: Datadog::Lambda
- Defined in:
- lib/datadog/lambda.rb,
lib/datadog/lambda/version.rb
Overview
Instruments AWS Lambda functions with Datadog distributed tracing and custom metrics
Defined Under Namespace
Modules: VERSION
Class Method Summary collapse
-
.metric(name, value, time: nil, **tags) ⇒ Object
Send a custom distribution metric.
-
.trace_context ⇒ Object
Gets the current tracing context.
-
.wrap(event, _context, &block) ⇒ Object
Wrap the body of a lambda invocation.
Class Method Details
.metric(name, value, time: nil, **tags) ⇒ Object
Send a custom distribution metric
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/datadog/lambda.rb', line 48 def self.metric(name, value, time: nil, **) raise 'name must be a string' unless name.is_a?(String) raise 'value must be a number' unless value.is_a?(Numeric) time ||= Time.now tag_list = ['dd_lambda_layer:datadog-ruby25'] .each do |tag| tag_list.push("#{tag[0]}:#{tag[1]}") end time_ms = time.to_f.to_i metric = { e: time_ms, m: name, t: tag_list, v: value }.to_json puts metric end |
.trace_context ⇒ Object
Gets the current tracing context
39 40 41 |
# File 'lib/datadog/lambda.rb', line 39 def self.trace_context Datadog::Trace.trace_context end |
.wrap(event, _context, &block) ⇒ Object
Wrap the body of a lambda invocation
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/datadog/lambda.rb', line 25 def self.wrap(event, _context, &block) Datadog::Utils.update_log_level @listener ||= Trace::Listener.new @listener.on_start(event: event) begin res = block.call ensure @listener.on_end end res end |