From a9ee4be1d4581e4d5f71ae3121a936d8161764f3 Mon Sep 17 00:00:00 2001 From: fallwith Date: Wed, 27 Mar 2024 21:10:29 -0700 Subject: [PATCH 1/8] Introduce support for Ruby - Introduce runtime configuration values for Ruby (these do not yet power any automated checks) - Add sam and terraform examples (these are pretty much straight ports of the Python examples) --- checks/runtime_config.go | 14 ++++ examples/sam/ruby/README.md | 64 +++++++++++++++++++ examples/sam/ruby/deploy.sh | 21 ++++++ examples/sam/ruby/events/event.json | 62 ++++++++++++++++++ .../sam/ruby/newrelic_example_ruby/app.rb | 24 +++++++ examples/sam/ruby/template.yaml | 45 +++++++++++++ examples/sam/ruby/test/handler_test.rb | 33 ++++++++++ examples/terraform/ruby/README.md | 64 +++++++++++++++++++ examples/terraform/ruby/app.rb | 24 +++++++ examples/terraform/ruby/deploy.sh | 14 ++++ examples/terraform/ruby/events/event.json | 62 ++++++++++++++++++ .../ruby/lambda-assume-role-policy.json | 13 ++++ examples/terraform/ruby/lambda-policy.json | 17 +++++ examples/terraform/ruby/main.tf | 11 ++++ examples/terraform/ruby/vars.tf | 7 ++ 15 files changed, 475 insertions(+) create mode 100644 examples/sam/ruby/README.md create mode 100755 examples/sam/ruby/deploy.sh create mode 100644 examples/sam/ruby/events/event.json create mode 100644 examples/sam/ruby/newrelic_example_ruby/app.rb create mode 100644 examples/sam/ruby/template.yaml create mode 100755 examples/sam/ruby/test/handler_test.rb create mode 100644 examples/terraform/ruby/README.md create mode 100644 examples/terraform/ruby/app.rb create mode 100755 examples/terraform/ruby/deploy.sh create mode 100644 examples/terraform/ruby/events/event.json create mode 100644 examples/terraform/ruby/lambda-assume-role-policy.json create mode 100644 examples/terraform/ruby/lambda-policy.json create mode 100644 examples/terraform/ruby/main.tf create mode 100644 examples/terraform/ruby/vars.tf diff --git a/checks/runtime_config.go b/checks/runtime_config.go index 639740ec..2b1a2561 100644 --- a/checks/runtime_config.go +++ b/checks/runtime_config.go @@ -9,8 +9,10 @@ var ( "/opt/python/lib/python3.8/site-packages/newrelic", "/opt/python/lib/python3.9/site-packages/newrelic", } + layerAgentPathRuby = []string{"/opt/ruby/gems/3.2.0/gems/newrelic_rpm"} vendorAgentPathNode = "/var/task/node_modules/newrelic" vendorAgentPathPython = "/var/task/newrelic" + vendorAgentPathRuby = "/var/task/vendor/bundle/ruby/3.2.0/gems/newrelic_rpm" runtimeLookupPath = "/var/lang/bin" ) @@ -31,6 +33,7 @@ type Runtime string const ( Python Runtime = "python" Node Runtime = "node" + Ruby Runtime = "ruby" ) // Runtime static values @@ -55,4 +58,15 @@ var runtimeConfigs = map[Runtime]runtimeConfig{ agentVersionGitOrg: "newrelic", agentVersionGitRepo: "newrelic-python-agent", }, + Ruby: { + language: Ruby, + wrapperName: "newrelic_lambda_wrapper.handler", + fileType: "rb", + layerAgentPaths: layerAgentPathRuby, + vendorAgentPath: vendorAgentPathRuby, + // TODO: requires Ruby to parse out the version + agentVersionFile: "lib/new_relic/version.rb", + agentVersionGitOrg: "newrelic", + agentVersionGitRepo: "newrelic-ruby-agent", + }, } diff --git a/examples/sam/ruby/README.md b/examples/sam/ruby/README.md new file mode 100644 index 00000000..7f69c978 --- /dev/null +++ b/examples/sam/ruby/README.md @@ -0,0 +1,64 @@ +# Instrumented Ruby Lambda + +This is a "Hello, World" style Lambda function in Ruby, instrumented +with the New Relic agent. + +This example is both instructive and a diagnostic tool: if you can +deploy this Lambda function and see its events in NR One, you'll +know that all the telemetry plumbing is connected correctly. + +## Building and deploying + +### Prerequisites + +- The [AWS CLI v2](https://aws.amazon.com/cli/) +- [Docker](https://docs.docker.com/get-docker/) +- The [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) + +Make sure you've run the `newrelic-lambda integrations install` command in your +AWS Region, and included the `--enable-license-key-secret` flag. + +### deploy script + +From a command prompt, in this directory, run + + ./deploy.sh + +where `` is your New Relic account ID, and `` +is your AWS Region, like "us-west-2". + +This will package and deploy the CloudFormation stack for this example +function. + +At this point, you can invoke the function. As provided, the example +function doesn't pay attention to its invocation event. If everything +has gone well, each invocation gets reported to New Relic, and its +telemetry appears in NR One. + +## Code Structure + +Now is also a good time to look at the structure of the example code. + +### template.yaml + +This function is deployed using a SAM template, which is a CloudFormation +template with some extra syntactic sugar for Lambda functions. In it, we +tell CloudFormation where to find lambda function code, what layers to use, and +what IAM policies to add to the Lambda function's execution role. We also set +environment variables that are available to the handler function. + +### app.rb + +Lambda functions written in Ruby are involve a Ruby method at a mininum and can +optionally be found within a class and/or module based namespace. The runtime +loads the Ruby code, and then invokes the handler function method for each +invocation event. New Relic publishes a Lambda Layer that wraps your handler +function and initializes the New Relic agent, allowing us to collect telemetry. + +There are a couple examples here of how you might add custom events and attributes +to the default telemetry. + +Since Ruby is a dynamic, interpreted language, the Agent can inject instrumentation +into the various client libraries you might be using in your function. This happens +once, during cold start, and provides rich, detailed instrumentation out of the box, +with minimal developer effort. diff --git a/examples/sam/ruby/deploy.sh b/examples/sam/ruby/deploy.sh new file mode 100755 index 00000000..691805bf --- /dev/null +++ b/examples/sam/ruby/deploy.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +accountId=$1 +region=$2 + +echo "region set to ${region}" + +sam build --use-container + +bucket="newrelic-example-${region}-${accountId}" + +aws s3 mb --region "${region}" "s3://${bucket}" + +sam package --region "${region}" --s3-bucket "${bucket}" --output-template-file packaged.yaml + +aws cloudformation deploy \ + --region "${region}" \ + --template-file packaged.yaml \ + --stack-name NewrelicExamplePython \ + --capabilities CAPABILITY_IAM \ + --parameter-overrides "NRAccountId=${accountId}" diff --git a/examples/sam/ruby/events/event.json b/examples/sam/ruby/events/event.json new file mode 100644 index 00000000..070ad8e0 --- /dev/null +++ b/examples/sam/ruby/events/event.json @@ -0,0 +1,62 @@ +{ + "body": "{\"message\": \"hello world\"}", + "resource": "/{proxy+}", + "path": "/path/to/resource", + "httpMethod": "POST", + "isBase64Encoded": false, + "queryStringParameters": { + "foo": "bar" + }, + "pathParameters": { + "proxy": "/path/to/resource" + }, + "stageVariables": { + "baz": "qux" + }, + "headers": { + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Accept-Encoding": "gzip, deflate, sdch", + "Accept-Language": "en-US,en;q=0.8", + "Cache-Control": "max-age=0", + "CloudFront-Forwarded-Proto": "https", + "CloudFront-Is-Desktop-Viewer": "true", + "CloudFront-Is-Mobile-Viewer": "false", + "CloudFront-Is-SmartTV-Viewer": "false", + "CloudFront-Is-Tablet-Viewer": "false", + "CloudFront-Viewer-Country": "US", + "Host": "1234567890.execute-api.us-east-1.amazonaws.com", + "Upgrade-Insecure-Requests": "1", + "User-Agent": "Custom User Agent String", + "Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)", + "X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==", + "X-Forwarded-For": "127.0.0.1, 127.0.0.2", + "X-Forwarded-Port": "443", + "X-Forwarded-Proto": "https" + }, + "requestContext": { + "accountId": "123456789012", + "resourceId": "123456", + "stage": "prod", + "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", + "requestTime": "09/Apr/2015:12:34:56 +0000", + "requestTimeEpoch": 1428582896000, + "identity": { + "cognitoIdentityPoolId": null, + "accountId": null, + "cognitoIdentityId": null, + "caller": null, + "accessKey": null, + "sourceIp": "127.0.0.1", + "cognitoAuthenticationType": null, + "cognitoAuthenticationProvider": null, + "userArn": null, + "userAgent": "Custom User Agent String", + "user": null + }, + "path": "/prod/path/to/resource", + "resourcePath": "/{proxy+}", + "httpMethod": "POST", + "apiId": "1234567890", + "protocol": "HTTP/1.1" + } +} diff --git a/examples/sam/ruby/newrelic_example_ruby/app.rb b/examples/sam/ruby/newrelic_example_ruby/app.rb new file mode 100644 index 00000000..c0cfffa7 --- /dev/null +++ b/examples/sam/ruby/newrelic_example_ruby/app.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require 'net/http' +require 'uri' + +# Example Ruby Lambda function - module and/or class +# namespacing is optional +class App + def self.lambda_handler(event:, context:) + # instrumentation + uri = URI('https://newrelic.com') + 3.times { Net::HTTP.get(uri) } + + # custom attributes + # ::NewRelic::Agent.add_custom_attributes(server: 'less', current_time: Time.now.to_s) + + # As normal, anything you write to stdout ends up in CloudWatch + puts 'Hello, world' + puts "Event size: #{event.size}" + puts "Context size: #{context.size}" + + { statusCode: 200, body: JSON.generate('Hello from Ruby Lambda!') } + end +end diff --git a/examples/sam/ruby/template.yaml b/examples/sam/ruby/template.yaml new file mode 100644 index 00000000..60ef4159 --- /dev/null +++ b/examples/sam/ruby/template.yaml @@ -0,0 +1,45 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Description: And example of a simple instrumented Ruby Lambda + +Parameters: + NRAccountId: + Type: String + Description: Your New Relic account ID; necessary for distributed tracing. + AllowedPattern: '[0-9]+' + +Resources: + NewRelicExample: + Type: AWS::Serverless::Function + Properties: + # In this example, we're using the SAM CLI to package and deploy our lambda. SAM will transform this value during the publish step. + CodeUri: newrelic_example_ruby/ + Description: A simple Lambda, with New Relic telemetry + FunctionName: newrelic-example-ruby + # The handler for your function needs to be the one provided by the instrumentation layer, below. + Handler: newrelic_lambda_wrapper.handler + Runtime: ruby3.2 + # Currently, we don't support Image based PackageType + PackageType: Zip + Environment: + Variables: + # For the instrumentation handler to invoke your real handler, we need this value + NEW_RELIC_LAMBDA_HANDLER: app.lambda_handler + NEW_RELIC_ACCOUNT_ID: !Sub ${NRAccountId} + # NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS: true + # NEW_RELIC_EXTENSION_LOG_LEVEL: DEBUG + Layers: + # This layer includes the New Relic Lambda Extension, a sidecar process that sends telemetry, + # as well as the New Relic Agent for Ruby, and a handler wrapper that makes integration easy. + - !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:451483290750:layer:NewRelicRuby32:1 + Policies: + # This policy allows the lambda to know the value of the New Relic licence key. We need this so + # that we can send telemetry back to New Relic + - AWSSecretsManagerGetSecretValuePolicy: + SecretArn: !ImportValue NewRelicLicenseKeySecret-NewRelic-LicenseKeySecretARN + Logs: + Type: AWS::Logs::LogGroup + Properties: + LogGroupName: {"Fn::Join": ["", ["/aws/lambda/", {"Ref": "NewRelicExample"}]]} + # Lambda functions will auto-create their log group on first execution, but it retains logs forever, which can get expensive. + RetentionInDays: 7 diff --git a/examples/sam/ruby/test/handler_test.rb b/examples/sam/ruby/test/handler_test.rb new file mode 100755 index 00000000..3ba9dbec --- /dev/null +++ b/examples/sam/ruby/test/handler_test.rb @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# Unit tests +# To run, simply have Ruby v3.2+ and execute this script +# $ ./handler_test.rb + +require 'bundler/inline' +gemfile do + source 'https://rubygems.org' + gem 'minitest' +end + +require 'json' +require 'minitest/autorun' + +# Test the Lambda handler +class LambdaHandlerTest < Minitest::Test + EVENT_FILE = '../events/event.json' + + def setup + require_relative '../newrelic_example_ruby/app' + end + + def test_lambda_handler + event = JSON.parse(File.read(EVENT_FILE)) + result = App.lambda_handler(event:, context: {}) + + assert_kind_of Hash, result, 'Expected a hash result from the Lambda function' + assert_equal 200, result[:statusCode], 'Expected function result to have a 200 status code' + assert_match 'Hello', result[:body], "Expected function result message to match 'Hello'" + end +end diff --git a/examples/terraform/ruby/README.md b/examples/terraform/ruby/README.md new file mode 100644 index 00000000..3c37661d --- /dev/null +++ b/examples/terraform/ruby/README.md @@ -0,0 +1,64 @@ +# Instrumented Ruby Lambda + +This is a "Hello, World" style Lambda function in Ruby, instrumented +with the New Relic agent. + +This example is both instructive and a diagnostic tool: if you can +deploy this Lambda function and see its events in NR One, you'll +know that all the telemetry plumbing is connected correctly. + +## Building and deploying + +### Prerequisites + +- The [AWS CLI v2](https://aws.amazon.com/cli/) +- [Docker](https://docs.docker.com/get-docker/) +- The [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) + +Make sure you've run the `newrelic-lambda integrations install` command in your +AWS Region, and included the `--enable-license-key-secret` flag. + +### deploy script + +From a command prompt, in this directory, run + + ./deploy.sh + +where `` is your New Relic account ID, and `` +is your AWS Region, like "us-west-2". + +This will package and deploy the CloudFormation stack for this example +function. + +At this point, you can invoke the function. As provided, the example +function doesn't pay attention to its invocation event. If everything +has gone well, each invocation gets reported to New Relic, and its +telemetry appears in NR One. + +## Code Structure + +Now is also a good time to look at the structure of the example code. + +### main.tf + +This function is deployed using this Terraform script. In it, we +tell Terraform where to find lambda function code, what layers to use, and +what IAM policies to add to the Lambda function's execution role. We also set +environment variables that are available to the handler function. + +### app.rb + +Lambda functions written in Ruby are involve a Ruby method at a mininum and can +optionally be found within a class and/or module based namespace. The runtime +loads the Ruby code, and then invokes the handler function method for each +invocation event. New Relic publishes a Lambda Layer that wraps your handler +function and initializes the New Relic agent, allowing us to collect telemetry. + +There are a couple examples here of how you might add custom events and attributes +to the default telemetry. + +Since Ruby is a dynamic, interpreted language, the Agent can inject instrumentation +into the various client libraries you might be using in your function. This happens +once, during cold start, and provides rich, detailed instrumentation out of the box, +with minimal developer effort. + diff --git a/examples/terraform/ruby/app.rb b/examples/terraform/ruby/app.rb new file mode 100644 index 00000000..c0cfffa7 --- /dev/null +++ b/examples/terraform/ruby/app.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require 'net/http' +require 'uri' + +# Example Ruby Lambda function - module and/or class +# namespacing is optional +class App + def self.lambda_handler(event:, context:) + # instrumentation + uri = URI('https://newrelic.com') + 3.times { Net::HTTP.get(uri) } + + # custom attributes + # ::NewRelic::Agent.add_custom_attributes(server: 'less', current_time: Time.now.to_s) + + # As normal, anything you write to stdout ends up in CloudWatch + puts 'Hello, world' + puts "Event size: #{event.size}" + puts "Context size: #{context.size}" + + { statusCode: 200, body: JSON.generate('Hello from Ruby Lambda!') } + end +end diff --git a/examples/terraform/ruby/deploy.sh b/examples/terraform/ruby/deploy.sh new file mode 100755 index 00000000..b24b6818 --- /dev/null +++ b/examples/terraform/ruby/deploy.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +accountId=$1 +export TF_VAR_newrelic_account_id=$accountId + +region=$2 +export TF_VAR_aws_region=$region +echo "region set to ${region}" + +rm -f function.zip +zip -rq function.zip app.rb + +terraform validate . +terraform apply diff --git a/examples/terraform/ruby/events/event.json b/examples/terraform/ruby/events/event.json new file mode 100644 index 00000000..070ad8e0 --- /dev/null +++ b/examples/terraform/ruby/events/event.json @@ -0,0 +1,62 @@ +{ + "body": "{\"message\": \"hello world\"}", + "resource": "/{proxy+}", + "path": "/path/to/resource", + "httpMethod": "POST", + "isBase64Encoded": false, + "queryStringParameters": { + "foo": "bar" + }, + "pathParameters": { + "proxy": "/path/to/resource" + }, + "stageVariables": { + "baz": "qux" + }, + "headers": { + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Accept-Encoding": "gzip, deflate, sdch", + "Accept-Language": "en-US,en;q=0.8", + "Cache-Control": "max-age=0", + "CloudFront-Forwarded-Proto": "https", + "CloudFront-Is-Desktop-Viewer": "true", + "CloudFront-Is-Mobile-Viewer": "false", + "CloudFront-Is-SmartTV-Viewer": "false", + "CloudFront-Is-Tablet-Viewer": "false", + "CloudFront-Viewer-Country": "US", + "Host": "1234567890.execute-api.us-east-1.amazonaws.com", + "Upgrade-Insecure-Requests": "1", + "User-Agent": "Custom User Agent String", + "Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)", + "X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==", + "X-Forwarded-For": "127.0.0.1, 127.0.0.2", + "X-Forwarded-Port": "443", + "X-Forwarded-Proto": "https" + }, + "requestContext": { + "accountId": "123456789012", + "resourceId": "123456", + "stage": "prod", + "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", + "requestTime": "09/Apr/2015:12:34:56 +0000", + "requestTimeEpoch": 1428582896000, + "identity": { + "cognitoIdentityPoolId": null, + "accountId": null, + "cognitoIdentityId": null, + "caller": null, + "accessKey": null, + "sourceIp": "127.0.0.1", + "cognitoAuthenticationType": null, + "cognitoAuthenticationProvider": null, + "userArn": null, + "userAgent": "Custom User Agent String", + "user": null + }, + "path": "/prod/path/to/resource", + "resourcePath": "/{proxy+}", + "httpMethod": "POST", + "apiId": "1234567890", + "protocol": "HTTP/1.1" + } +} diff --git a/examples/terraform/ruby/lambda-assume-role-policy.json b/examples/terraform/ruby/lambda-assume-role-policy.json new file mode 100644 index 00000000..7dee58b2 --- /dev/null +++ b/examples/terraform/ruby/lambda-assume-role-policy.json @@ -0,0 +1,13 @@ +{ + "Version": "2012-10-17", + "Statement": [ + { + "Action": "sts:AssumeRole", + "Principal": { + "Service": "lambda.amazonaws.com" + }, + "Effect": "Allow", + "Sid": "" + } + ] +} diff --git a/examples/terraform/ruby/lambda-policy.json b/examples/terraform/ruby/lambda-policy.json new file mode 100644 index 00000000..cbb36337 --- /dev/null +++ b/examples/terraform/ruby/lambda-policy.json @@ -0,0 +1,17 @@ +{ + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "", + "Action": "logs:*", + "Effect": "Allow", + "Resource": "*" + }, + { + "Sid": "", + "Action": "s3:*", + "Effect": "Allow", + "Resource": "*" + } + ] +} diff --git a/examples/terraform/ruby/main.tf b/examples/terraform/ruby/main.tf new file mode 100644 index 00000000..fc294020 --- /dev/null +++ b/examples/terraform/ruby/main.tf @@ -0,0 +1,11 @@ +module "python_test_function" { + source = "../lambda" + aws_region = var.aws_region + lambda_function_handler = "app.lambda_handler" + wrapper_handler = "newrelic_lambda_wrapper.handler" + lambda_function_name = "newrelic-terraform-example-ruby" + lambda_runtime = "ruby3.2" + lambda_zip_filename = "function.zip" + newrelic_account_id = var.newrelic_account_id + newrelic_layer = "arn:aws:lambda:${var.aws_region}:451483290750:layer:NewRelicRuby32:1" +} diff --git a/examples/terraform/ruby/vars.tf b/examples/terraform/ruby/vars.tf new file mode 100644 index 00000000..46232bce --- /dev/null +++ b/examples/terraform/ruby/vars.tf @@ -0,0 +1,7 @@ +variable "aws_region" { + type = string +} + +variable "newrelic_account_id" { + type = string +} From ea82b6ad2060a253b58b82ebf7d068f496fc10e0 Mon Sep 17 00:00:00 2001 From: fallwith Date: Wed, 3 Apr 2024 14:23:32 -0700 Subject: [PATCH 2/8] the Ruby template should read 'ruby' .tf typo fix --- examples/terraform/ruby/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/terraform/ruby/main.tf b/examples/terraform/ruby/main.tf index fc294020..8305e070 100644 --- a/examples/terraform/ruby/main.tf +++ b/examples/terraform/ruby/main.tf @@ -1,4 +1,4 @@ -module "python_test_function" { +module "ruby_test_function" { source = "../lambda" aws_region = var.aws_region lambda_function_handler = "app.lambda_handler" From 06fc0f9ba7f6a8cdb0c15c600157f3ada02b159d Mon Sep 17 00:00:00 2001 From: fallwith Date: Thu, 4 Apr 2024 20:50:54 -0700 Subject: [PATCH 3/8] Ruby: runtime v3.3 is now the default AWS has introduced support for Ruby v3.3, made it the default, and retained support for v3.2 --- checks/runtime_config.go | 9 ++++++--- examples/sam/ruby/template.yaml | 2 +- examples/terraform/ruby/main.tf | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/checks/runtime_config.go b/checks/runtime_config.go index 2b1a2561..c7439315 100644 --- a/checks/runtime_config.go +++ b/checks/runtime_config.go @@ -9,10 +9,13 @@ var ( "/opt/python/lib/python3.8/site-packages/newrelic", "/opt/python/lib/python3.9/site-packages/newrelic", } - layerAgentPathRuby = []string{"/opt/ruby/gems/3.2.0/gems/newrelic_rpm"} + layerAgentPathsRuby = []string{ + "/opt/ruby/gems/3.2.0/gems/newrelic_rpm" + "/opt/ruby/gems/3.3.0/gems/newrelic_rpm" + } vendorAgentPathNode = "/var/task/node_modules/newrelic" vendorAgentPathPython = "/var/task/newrelic" - vendorAgentPathRuby = "/var/task/vendor/bundle/ruby/3.2.0/gems/newrelic_rpm" + vendorAgentPathRuby = "/var/task/vendor/bundle/ruby/3.3.0/gems/newrelic_rpm" runtimeLookupPath = "/var/lang/bin" ) @@ -63,7 +66,7 @@ var runtimeConfigs = map[Runtime]runtimeConfig{ wrapperName: "newrelic_lambda_wrapper.handler", fileType: "rb", layerAgentPaths: layerAgentPathRuby, - vendorAgentPath: vendorAgentPathRuby, + vendorAgentPath: vendorAgentPathsRuby, // TODO: requires Ruby to parse out the version agentVersionFile: "lib/new_relic/version.rb", agentVersionGitOrg: "newrelic", diff --git a/examples/sam/ruby/template.yaml b/examples/sam/ruby/template.yaml index 60ef4159..bc9d3a83 100644 --- a/examples/sam/ruby/template.yaml +++ b/examples/sam/ruby/template.yaml @@ -18,7 +18,7 @@ Resources: FunctionName: newrelic-example-ruby # The handler for your function needs to be the one provided by the instrumentation layer, below. Handler: newrelic_lambda_wrapper.handler - Runtime: ruby3.2 + Runtime: ruby3.3 # Currently, we don't support Image based PackageType PackageType: Zip Environment: diff --git a/examples/terraform/ruby/main.tf b/examples/terraform/ruby/main.tf index 8305e070..572f9cd5 100644 --- a/examples/terraform/ruby/main.tf +++ b/examples/terraform/ruby/main.tf @@ -4,7 +4,7 @@ module "ruby_test_function" { lambda_function_handler = "app.lambda_handler" wrapper_handler = "newrelic_lambda_wrapper.handler" lambda_function_name = "newrelic-terraform-example-ruby" - lambda_runtime = "ruby3.2" + lambda_runtime = "ruby3.3" lambda_zip_filename = "function.zip" newrelic_account_id = var.newrelic_account_id newrelic_layer = "arn:aws:lambda:${var.aws_region}:451483290750:layer:NewRelicRuby32:1" From 3a7fc88a4ae5aa8b77d90b546853725c50dac739 Mon Sep 17 00:00:00 2001 From: fallwith Date: Thu, 4 Apr 2024 20:55:58 -0700 Subject: [PATCH 4/8] Ruby runtimes needed a comma separator typo fix --- checks/runtime_config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checks/runtime_config.go b/checks/runtime_config.go index c7439315..041e6d96 100644 --- a/checks/runtime_config.go +++ b/checks/runtime_config.go @@ -10,7 +10,7 @@ var ( "/opt/python/lib/python3.9/site-packages/newrelic", } layerAgentPathsRuby = []string{ - "/opt/ruby/gems/3.2.0/gems/newrelic_rpm" + "/opt/ruby/gems/3.2.0/gems/newrelic_rpm", "/opt/ruby/gems/3.3.0/gems/newrelic_rpm" } vendorAgentPathNode = "/var/task/node_modules/newrelic" From 8ea5ba7ba8082f6fd5f6498924b310d850b1c163 Mon Sep 17 00:00:00 2001 From: fallwith Date: Wed, 17 Apr 2024 10:52:05 -0700 Subject: [PATCH 5/8] runtime config: add missing comma to ruby list Add trailing array comma --- checks/runtime_config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checks/runtime_config.go b/checks/runtime_config.go index 041e6d96..334f431f 100644 --- a/checks/runtime_config.go +++ b/checks/runtime_config.go @@ -11,7 +11,7 @@ var ( } layerAgentPathsRuby = []string{ "/opt/ruby/gems/3.2.0/gems/newrelic_rpm", - "/opt/ruby/gems/3.3.0/gems/newrelic_rpm" + "/opt/ruby/gems/3.3.0/gems/newrelic_rpm", } vendorAgentPathNode = "/var/task/node_modules/newrelic" vendorAgentPathPython = "/var/task/newrelic" From 732a7d32e722f5bf5a94a6de70834caed9863fd5 Mon Sep 17 00:00:00 2001 From: fallwith Date: Wed, 17 Apr 2024 10:54:39 -0700 Subject: [PATCH 6/8] path -> paths for Ruby 2 runtimes are supported now --- checks/runtime_config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checks/runtime_config.go b/checks/runtime_config.go index 334f431f..b285f166 100644 --- a/checks/runtime_config.go +++ b/checks/runtime_config.go @@ -65,7 +65,7 @@ var runtimeConfigs = map[Runtime]runtimeConfig{ language: Ruby, wrapperName: "newrelic_lambda_wrapper.handler", fileType: "rb", - layerAgentPaths: layerAgentPathRuby, + layerAgentPaths: layerAgentPathsRuby, vendorAgentPath: vendorAgentPathsRuby, // TODO: requires Ruby to parse out the version agentVersionFile: "lib/new_relic/version.rb", From a4c8d877f64ee48dce6fc49b841c97c803cd7dd5 Mon Sep 17 00:00:00 2001 From: fallwith Date: Wed, 17 Apr 2024 11:00:01 -0700 Subject: [PATCH 7/8] single Ruby vendor path two runtimes, but a single expected vendor path --- checks/runtime_config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checks/runtime_config.go b/checks/runtime_config.go index b285f166..d4ce37c5 100644 --- a/checks/runtime_config.go +++ b/checks/runtime_config.go @@ -66,7 +66,7 @@ var runtimeConfigs = map[Runtime]runtimeConfig{ wrapperName: "newrelic_lambda_wrapper.handler", fileType: "rb", layerAgentPaths: layerAgentPathsRuby, - vendorAgentPath: vendorAgentPathsRuby, + vendorAgentPath: vendorAgentPathRuby, // TODO: requires Ruby to parse out the version agentVersionFile: "lib/new_relic/version.rb", agentVersionGitOrg: "newrelic", From 330328aa3862515d685521f90de70f23c3dc296b Mon Sep 17 00:00:00 2001 From: fallwith Date: Thu, 9 May 2024 10:11:13 -0700 Subject: [PATCH 8/8] Ruby: fix "Python" copy/paste typo "Python" -> "Ruby" --- examples/sam/ruby/deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/sam/ruby/deploy.sh b/examples/sam/ruby/deploy.sh index 691805bf..c08428be 100755 --- a/examples/sam/ruby/deploy.sh +++ b/examples/sam/ruby/deploy.sh @@ -16,6 +16,6 @@ sam package --region "${region}" --s3-bucket "${bucket}" --output-template-file aws cloudformation deploy \ --region "${region}" \ --template-file packaged.yaml \ - --stack-name NewrelicExamplePython \ + --stack-name NewrelicExampleRuby \ --capabilities CAPABILITY_IAM \ --parameter-overrides "NRAccountId=${accountId}"