Module: SignalFx::Lambda
- Defined in:
- lib/signalfx/lambda.rb,
lib/signalfx/lambda/metrics.rb,
lib/signalfx/lambda/tracing.rb,
lib/signalfx/lambda/version.rb,
lib/signalfx/lambda/tracing/extractors.rb
Defined Under Namespace
Modules: Metrics, Tracing Classes: Error
Constant Summary collapse
- COMPONENT =
'ruby-lambda-wrapper'.freeze
- VERSION =
"0.2.2"
Class Attribute Summary collapse
-
.fields ⇒ Object
Returns the value of attribute fields.
Class Method Summary collapse
-
.build_wrapped_handler(wrappers) ⇒ Object
build a nested block depending on the wrappers enabled.
-
.fields_from_arn(arn = '') ⇒ Object
the arn packs useful data, including region, account id, resource type, and qualifier.
-
.gather_fields(context) ⇒ Object
build a map of useful properties from the context object.
- .register_handler(metrics: true, tracing: true, &handler) ⇒ Object
- .wrapped_handler(event:, context:) ⇒ Object
Class Attribute Details
.fields ⇒ Object
Returns the value of attribute fields.
12 13 14 |
# File 'lib/signalfx/lambda.rb', line 12 def fields @fields end |
Class Method Details
.build_wrapped_handler(wrappers) ⇒ Object
build a nested block depending on the wrappers enabled
34 35 36 37 38 39 40 |
# File 'lib/signalfx/lambda.rb', line 34 def build_wrapped_handler(wrappers) wrappers.inject do |inner, outer| proc do |event:, context:| outer.call(event: event, context: context, &inner) end end end |
.fields_from_arn(arn = '') ⇒ Object
the arn packs useful data, including region, account id, resource type, and qualifier
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/signalfx/lambda.rb', line 60 def fields_from_arn(arn = '') _, _, _, region, account_id, resource_type, _, qualifier = arn.split(':') fields = { 'aws_region' => region, 'aws_account_id' => account_id, } if qualifier case resource_type when 'function' fields['aws_function_qualifier'] = qualifier when 'event-source-mappings' fields['event_source_mappings'] = qualifier end end fields end |
.gather_fields(context) ⇒ Object
build a map of useful properties from the context object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/signalfx/lambda.rb', line 43 def gather_fields(context) fields = { 'lambda_arn' => context.invoked_function_arn, 'aws_request_id' => context.aws_request_id, 'aws_function_name' => context.function_name, 'aws_function_version' => context.function_version, 'aws_execution_env' => ENV['AWS_EXECUTION_ENV'], 'log_group_name' => context.log_group_name, 'log_stream_name' => context.log_stream_name, 'function_wrapper_version' => "signalfx-lambda-#{SignalFx::Lambda::VERSION}", } fields.merge!(fields_from_arn(context.invoked_function_arn)) end |
.register_handler(metrics: true, tracing: true, &handler) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/signalfx/lambda.rb', line 21 def register_handler(metrics: true, tracing: true, &handler) @handler = handler # the original handler # Add the wrappers needed wrappers = [] wrappers.push(@handler) wrappers.push(Tracing.method(:wrap_function)) if tracing wrappers.push(Metrics.method(:wrap_function)) if metrics @wrapped_handler = build_wrapped_handler(wrappers) if @wrapped_handler.nil? end |
.wrapped_handler(event:, context:) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/signalfx/lambda.rb', line 14 def wrapped_handler(event:, context:) # gather some useful information from the execution context and ARN and # make it available to the handlers @fields = gather_fields(context) @wrapped_handler.call(event: event, context: context) end |