From 5ef509efd635592d66a5fe6599924f953e6c9338 Mon Sep 17 00:00:00 2001 From: xuan-cao-swi Date: Mon, 13 May 2024 14:20:59 -0400 Subject: [PATCH 1/5] feat: add lambda ruby wrapper for layer --- ruby/sample-apps/function/lambda_function.rb | 1 - ruby/sample-apps/template.yml | 1 + ruby/src/layer/Gemfile | 2 +- ruby/src/layer/Makefile | 6 ++++-- ruby/src/layer/otel-handler | 10 +++++++++- ruby/src/layer/wrapper.rb | 15 +++++++++++++++ ruby/src/zip_ruby_layer.sh | 1 + 7 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 ruby/src/layer/wrapper.rb diff --git a/ruby/sample-apps/function/lambda_function.rb b/ruby/sample-apps/function/lambda_function.rb index 3b260932d5..b1e97ad188 100644 --- a/ruby/sample-apps/function/lambda_function.rb +++ b/ruby/sample-apps/function/lambda_function.rb @@ -1,5 +1,4 @@ require 'json' -require 'opentelemetry-sdk' def lambda_handler(event:, context:) if defined?(::OpenTelemetry::SDK) diff --git a/ruby/sample-apps/template.yml b/ruby/sample-apps/template.yml index b6410955df..5627208f0f 100644 --- a/ruby/sample-apps/template.yml +++ b/ruby/sample-apps/template.yml @@ -40,6 +40,7 @@ Resources: RestApiId: !Ref api Path: / Method: GET + Timeout: 60 Environment: Variables: AWS_LAMBDA_EXEC_WRAPPER: /opt/otel-handler diff --git a/ruby/src/layer/Gemfile b/ruby/src/layer/Gemfile index 915ac5e1d2..4df6c1e93c 100644 --- a/ruby/src/layer/Gemfile +++ b/ruby/src/layer/Gemfile @@ -2,4 +2,4 @@ source 'https://rubygems.org' gem 'opentelemetry-sdk' gem 'opentelemetry-exporter-otlp' -gem 'opentelemetry-instrumentation-all' +gem 'opentelemetry-instrumentation-aws_lambda' diff --git a/ruby/src/layer/Makefile b/ruby/src/layer/Makefile index 4e72c475a6..6a12b1e47e 100644 --- a/ruby/src/layer/Makefile +++ b/ruby/src/layer/Makefile @@ -1,8 +1,10 @@ build-OTelLayer: - mkdir -p ruby mkdir -p $(ARTIFACTS_DIR)/ruby/gems/3.2.0 - bundler install --path ruby + bundle config set --global silence_root_warning 1 + bundle config set --local path 'ruby' + bundle install cp -r ruby/ruby/3.2.0/* $(ARTIFACTS_DIR)/ruby/gems/3.2.0 cp otel-handler $(ARTIFACTS_DIR)/otel-handler + cp wrapper.rb $(ARTIFACTS_DIR)/wrapper.rb rm -rf $(ARTIFACTS_DIR)/ruby/gems/3.2.0/cache diff --git a/ruby/src/layer/otel-handler b/ruby/src/layer/otel-handler index fb783c9cb6..9d8f47ff56 100755 --- a/ruby/src/layer/otel-handler +++ b/ruby/src/layer/otel-handler @@ -1,9 +1,17 @@ #!/bin/sh +export ORIG_HANDLER=$_HANDLER; +export _HANDLER="/opt/wrapper.otel_wrapper"; + if [ -z "${OTEL_SERVICE_NAME}" ]; then export OTEL_SERVICE_NAME="$AWS_LAMBDA_FUNCTION_NAME"; fi +# disable HTTP NET by default - otherwise, lambda runtime gets instrumented yielding noise +if [ -z "${OTEL_RUBY_INSTRUMENTATION_NET_HTTP_ENABLED}" ]; then + export OTEL_RUBY_INSTRUMENTATION_NET_HTTP_ENABLED=false; +fi + export LAMBDA_RESOURCE_ATTRIBUTES="cloud.region=$AWS_REGION,cloud.provider=aws,faas.name=$AWS_LAMBDA_FUNCTION_NAME,faas.version=$AWS_LAMBDA_FUNCTION_VERSION"; if [ -z "${OTEL_RESOURCE_ATTRIBUTES}" ]; then export OTEL_RESOURCE_ATTRIBUTES="$LAMBDA_RESOURCE_ATTRIBUTES"; @@ -11,4 +19,4 @@ else export OTEL_RESOURCE_ATTRIBUTES="$LAMBDA_RESOURCE_ATTRIBUTES,$OTEL_RESOURCE_ATTRIBUTES"; fi -exec "$@" \ No newline at end of file +exec "$@" diff --git a/ruby/src/layer/wrapper.rb b/ruby/src/layer/wrapper.rb new file mode 100644 index 0000000000..3f6036ab06 --- /dev/null +++ b/ruby/src/layer/wrapper.rb @@ -0,0 +1,15 @@ +require 'opentelemetry/sdk' +require 'opentelemetry/exporter/otlp' +require 'opentelemetry/instrumentation/aws_lambda' + +OpenTelemetry::SDK.configure do |c| + c.use 'OpenTelemetry::Instrumentation::AwsLambda' +end + +::OpenTelemetry::Instrumentation.registry.register('OpenTelemetry::Instrumentation::AwsLambda') +::OpenTelemetry::Instrumentation.registry.install(['OpenTelemetry::Instrumentation::AwsLambda']) + +def otel_wrapper(event:, context:) + otel_wrapper = OpenTelemetry::Instrumentation::AwsLambda::Handler.new() + otel_wrapper.call_wrapped(event: event, context: context) +end \ No newline at end of file diff --git a/ruby/src/zip_ruby_layer.sh b/ruby/src/zip_ruby_layer.sh index 685587f8a0..dd5266d557 100755 --- a/ruby/src/zip_ruby_layer.sh +++ b/ruby/src/zip_ruby_layer.sh @@ -35,6 +35,7 @@ main() { cd .aws-sam/build/OTelLayer/ zip -qr ../../../"$layerName".zip ruby/ cd - + echo "Finished" } main "$@" From 4b4069022dc11721c6188a7f17aaf4f161ccaab7 Mon Sep 17 00:00:00 2001 From: xuan-cao-swi Date: Mon, 13 May 2024 14:27:13 -0400 Subject: [PATCH 2/5] double quote on env var --- ruby/src/layer/otel-handler | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/src/layer/otel-handler b/ruby/src/layer/otel-handler index 9d8f47ff56..3586efd19c 100755 --- a/ruby/src/layer/otel-handler +++ b/ruby/src/layer/otel-handler @@ -1,6 +1,6 @@ #!/bin/sh -export ORIG_HANDLER=$_HANDLER; +export ORIG_HANDLER="$_HANDLER"; export _HANDLER="/opt/wrapper.otel_wrapper"; if [ -z "${OTEL_SERVICE_NAME}" ]; then From 4c325830d28de110bfe8bbf8ce10c81042c66580 Mon Sep 17 00:00:00 2001 From: xuan-cao-swi Date: Tue, 21 May 2024 11:54:30 -0400 Subject: [PATCH 3/5] feat: revision --- ruby/src/layer/wrapper.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/ruby/src/layer/wrapper.rb b/ruby/src/layer/wrapper.rb index 3f6036ab06..68609f005e 100644 --- a/ruby/src/layer/wrapper.rb +++ b/ruby/src/layer/wrapper.rb @@ -6,9 +6,6 @@ c.use 'OpenTelemetry::Instrumentation::AwsLambda' end -::OpenTelemetry::Instrumentation.registry.register('OpenTelemetry::Instrumentation::AwsLambda') -::OpenTelemetry::Instrumentation.registry.install(['OpenTelemetry::Instrumentation::AwsLambda']) - def otel_wrapper(event:, context:) otel_wrapper = OpenTelemetry::Instrumentation::AwsLambda::Handler.new() otel_wrapper.call_wrapped(event: event, context: context) From 9b85a4590944943effb70691db3638b334cf3aec Mon Sep 17 00:00:00 2001 From: xuan-cao-swi Date: Wed, 22 May 2024 11:45:27 -0400 Subject: [PATCH 4/5] feat: change to dev --- .github/workflows/release-layer-ruby.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-layer-ruby.yml b/.github/workflows/release-layer-ruby.yml index 5a782ae19f..519f74b259 100644 --- a/.github/workflows/release-layer-ruby.yml +++ b/.github/workflows/release-layer-ruby.yml @@ -78,6 +78,6 @@ jobs: layer-name: opentelemetry-ruby component-version: ${{needs.build-layer.outputs.RUBY_SDK_VERSION}} runtimes: ruby3.2 - release-group: prod + release-group: dev aws_region: ${{ matrix.aws_region }} secrets: inherit From eefaea8bfe00af1c5a3753fcfa5b1bdab7cc3b0d Mon Sep 17 00:00:00 2001 From: xuan-cao-swi Date: Wed, 22 May 2024 12:13:11 -0400 Subject: [PATCH 5/5] feat: ensure version control --- ruby/src/layer/Gemfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ruby/src/layer/Gemfile b/ruby/src/layer/Gemfile index 4df6c1e93c..3a807e3ea5 100644 --- a/ruby/src/layer/Gemfile +++ b/ruby/src/layer/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -gem 'opentelemetry-sdk' -gem 'opentelemetry-exporter-otlp' -gem 'opentelemetry-instrumentation-aws_lambda' +gem 'opentelemetry-sdk', '~> 1.4.1' +gem 'opentelemetry-exporter-otlp', '~> 0.26.3' +gem 'opentelemetry-instrumentation-aws_lambda', '~> 0.1.0'