Class: LambdaLoadout::Handler
- Inherits:
-
Object
- Object
- LambdaLoadout::Handler
- Defined in:
- lib/lambda_loadout/middleware.rb
Overview
Decorator-style wrapper for Lambda handlers
Provides a simple DSL for wrapping Lambda handlers with observability.
Class Attribute Summary collapse
-
.capture_cold_start ⇒ Object
Returns the value of attribute capture_cold_start.
-
.log_level ⇒ Object
Returns the value of attribute log_level.
-
.namespace ⇒ Object
Returns the value of attribute namespace.
-
.service ⇒ Object
Returns the value of attribute service.
Class Method Summary collapse
-
.call(event, context, capture_cold_start: @capture_cold_start || true) {|logger, metrics| ... } ⇒ Object
Call handler with observability.
-
.configure {|self| ... } ⇒ void
Configure global handler defaults.
Class Attribute Details
.capture_cold_start ⇒ Object
Returns the value of attribute capture_cold_start.
86 87 88 |
# File 'lib/lambda_loadout/middleware.rb', line 86 def capture_cold_start @capture_cold_start end |
.log_level ⇒ Object
Returns the value of attribute log_level.
86 87 88 |
# File 'lib/lambda_loadout/middleware.rb', line 86 def log_level @log_level end |
.namespace ⇒ Object
Returns the value of attribute namespace.
86 87 88 |
# File 'lib/lambda_loadout/middleware.rb', line 86 def namespace @namespace end |
.service ⇒ Object
Returns the value of attribute service.
86 87 88 |
# File 'lib/lambda_loadout/middleware.rb', line 86 def service @service end |
Class Method Details
.call(event, context, capture_cold_start: @capture_cold_start || true) {|logger, metrics| ... } ⇒ Object
Call handler with observability
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/lambda_loadout/middleware.rb', line 103 def call(event, context, capture_cold_start: @capture_cold_start || true, &block) logger = LambdaLoadout::Logger.new( service: @service, level: @log_level || :info ) metrics = LambdaLoadout::Metrics.new( namespace: @namespace || 'LambdaLoadout', service: @service ) logger.inject_lambda_context(context) logger.info('Lambda invocation started', event_keys: event.keys) begin result = block.call(logger, metrics) metrics.add_cold_start_metric(context) if capture_cold_start logger.info('Lambda invocation completed successfully') result rescue StandardError => e logger.exception(e, message: 'Lambda invocation failed') metrics.add_metric(name: 'LambdaError', unit: 'Count', value: 1) metrics.add_dimension(name: 'error_type', value: e.class.name) raise ensure begin metrics.flush rescue StandardError nil end end end |
.configure {|self| ... } ⇒ void
This method returns an undefined value.
Configure global handler defaults
92 93 94 |
# File 'lib/lambda_loadout/middleware.rb', line 92 def configure yield self end |