Skip to content

Commit 4be5c7c

Browse files
committed
fix: No ruby 3.1 shorthand
1 parent d532587 commit 4be5c7c

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

instrumentation/aws_lambda/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,32 @@ def otel_wrapper(event:, context:)
2828
end
2929
```
3030

31+
### Alternative Usage
32+
33+
If using a Lambda Layer is not an option for your given setup, you can programatically instrument a handler by using the `OpenTelemetry::Instrumentation::AwsLambda::Wrap` module.
34+
35+
```ruby
36+
require 'opentelemetry/sdk'
37+
require 'opentelemetry/instrumentation/aws_lambda'
38+
39+
OpenTelemetry::SDK.configure do |c|
40+
c.service_name = '<YOUR_SERVICE_NAME>'
41+
c.use 'OpenTelemetry::Instrumentation::AwsLambda'
42+
end
43+
44+
# Lambda Handler
45+
module Example
46+
class Handler
47+
extend OpenTelemetry::Instrumentation::AwsLambda::Wrap
48+
49+
def self.process(event:, context:)
50+
puts event.inspect
51+
end
52+
instrument_handler :process
53+
end
54+
end
55+
```
56+
3157
## Example
3258

3359
To run the example:

instrumentation/aws_lambda/lib/opentelemetry/instrumentation/aws_lambda/handler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def initialize
2828
# Try to record and re-raise any exception from the wrapped function handler
2929
# Instrumentation should never raise its own exception
3030
def call_wrapped(event:, context:)
31-
self.class.wrap_lambda(event:, context:, handler: @original_handler, flush_timeout: @flush_timeout) do
31+
self.class.wrap_lambda(event: event, context: context, handler: @original_handler, flush_timeout: @flush_timeout) do
3232
call_original_handler(event: event, context: context)
3333
end
3434
end

instrumentation/aws_lambda/lib/opentelemetry/instrumentation/aws_lambda/wrap.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def instrument_handler(method, flush_timeout: DEFAULT_FLUSH_TIMEOUT)
2121
handler = "#{name}.#{method}"
2222

2323
define_singleton_method(method) do |event:, context:|
24-
wrap_lambda(event:, context:, handler:, flush_timeout:) { public_send(uninstrumented_method, event:, context:) }
24+
wrap_lambda(event: event, context: context, handler: handler, flush_timeout: flush_timeout) { public_send(uninstrumented_method, event: event, context: context) }
2525
end
2626
end
2727

0 commit comments

Comments
 (0)