Skip to content

Commit

Permalink
feat: revision on fix sample test, update readme and add rubocop-perf…
Browse files Browse the repository at this point in the history
…ormance
  • Loading branch information
xuan-cao-swi committed Dec 12, 2023
1 parent 157f219 commit 432670a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions instrumentation/aws_lambda/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inherit_from: ../../.rubocop.yml
3 changes: 1 addition & 2 deletions instrumentation/aws_lambda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ Or, if you use [bundler][bundler-home], include `opentelemetry-instrumentation-a
From the Lambda Layer side, create the wrapper. More information can be found at https://github.com/open-telemetry/opentelemetry-lambda
```ruby
require 'opentelemetry/sdk'
require 'opentelemetry/instrumentation/all'
require 'opentelemetry/instrumentation/aws_lambda'
OpenTelemetry::SDK.configure do |c|
c.service_name = '<YOUR_SERVICE_NAME>'
c.use_all()
end

def otel_wrapper(event:, context:)
Expand Down
26 changes: 26 additions & 0 deletions instrumentation/aws_lambda/example/trace_demonstration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,32 @@ def initialize(aws_request_id:, invoked_function_arn:)
end
end

# To accommendate the test case, handler class doesn't need to require the sample file if it's required here
# In lambda environment, the env will find the handler file.
module OpenTelemetry
module Instrumentation
module AwsLambda
class Handler
def resolve_original_handler
original_handler = ENV['ORIG_HANDLER'] || ENV['_HANDLER'] || ''
original_handler_parts = original_handler.split('.')
if original_handler_parts.size == 2
handler_file, @handler_method = original_handler_parts
elsif original_handler_parts.size == 3
handler_file, @handler_class, @handler_method = original_handler_parts
else
OpenTelemetry.logger.warn("aws-lambda instrumentation: Invalid handler #{original_handler}, must be of form FILENAME.METHOD or FILENAME.CLASS.METHOD.")
end

# require handler_file #-> don't require file for this sample test

original_handler
end
end
end
end
end

def otel_wrapper(event:, context:)
otel_wrapper = OpenTelemetry::Instrumentation::AwsLambda::Handler.new()
otel_wrapper.call_wrapped(event: event, context: context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'pry-byebug' unless RUBY_ENGINE == 'jruby'
spec.add_development_dependency 'rspec-mocks'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.19'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down

0 comments on commit 432670a

Please sign in to comment.