diff --git a/apm-lambda-extension/testing/functions/ruby/Gemfile b/apm-lambda-extension/testing/functions/ruby/Gemfile new file mode 100644 index 00000000..1e933df9 --- /dev/null +++ b/apm-lambda-extension/testing/functions/ruby/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' + +gem 'elastic-apm' diff --git a/apm-lambda-extension/testing/functions/ruby/ruby_function_error.rb b/apm-lambda-extension/testing/functions/ruby/ruby_function_error.rb new file mode 100644 index 00000000..2c8bb5b5 --- /dev/null +++ b/apm-lambda-extension/testing/functions/ruby/ruby_function_error.rb @@ -0,0 +1,17 @@ +load_paths = Dir["vendor/bundle/ruby/2.7.0/bundler/gems/**/lib"] +load_paths += Dir["vendor/bundle/ruby/2.7.0/gems/**/lib"] +load_paths += Dir["vendor/bundle/ruby/2.7.0/extensions/x86_64-linux/2.7.0/*"] +load_paths += Dir["vendor/bundle/ruby/2.7.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby"] + +$LOAD_PATH.unshift(*load_paths) + +require 'json' +require 'elastic-apm' + +ElasticAPM.start(service_name: 'LocalLambdaTesting') + +def lambda_handler(event:, context:) + raise Exception +ensure + HTTP.post("http://localhost:8200/intake/v2/events", :params => {:flushed => "true"}) +end diff --git a/apm-lambda-extension/testing/templates/template.yml b/apm-lambda-extension/testing/templates/template.yml new file mode 100644 index 00000000..70f06f8d --- /dev/null +++ b/apm-lambda-extension/testing/templates/template.yml @@ -0,0 +1,43 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Description: > + sam-testing + + +# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst +Globals: + Function: + Timeout: 20 + +Parameters: + LayerArn: + Type: String + Description: Function Layer arn + ApmServerURL: + Type: String + Description: APM server URL + ApmSecretToken: + Type: String + Description: APM server secret token + +Resources: + TestFunction: + Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction + Properties: + CodeUri: ../functions/ruby + Handler: ruby_function_error.lambda_handler + Runtime: ruby2.7 + PackageType: Zip + Layers: + - !Ref LayerArn + Events: + Test: + Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api + Properties: + Path: / + Method: get + Environment: + Variables: + ELASTIC_APM_LAMBDA_APM_SERVER: !Ref ApmServerURL + ELASTIC_APM_SECRET_TOKEN: !Ref ApmSecretToken + GEM_PATH: vendor/bundle/ruby/2.7.0