diff --git a/.github/workflows/release-layer-ruby.yml b/.github/workflows/release-layer-ruby.yml index 74e0f13e0e..6605310c3b 100644 --- a/.github/workflows/release-layer-ruby.yml +++ b/.github/workflows/release-layer-ruby.yml @@ -18,38 +18,23 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.2.0' - - - name: Install SAM - run: | - sudo apt-get update && sudo apt-get install wget unzip make -y - wget https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip - unzip aws-sam-cli-linux-x86_64.zip -d sam-installation - sudo ./sam-installation/install --update - - name: Build id: save-ruby-sdk-version run: | - sam build -u -t template.yml - export GEM_PATH=$PWD/.aws-sam/build/OTelLayer/ruby/gems/3.2.0/ - RUBY_SDK_VERSION=$(ruby -e 'require "opentelemetry-sdk"; puts OpenTelemetry::SDK::VERSION') - echo "RUBY_SDK_VERSION=$RUBY_SDK_VERSION" >> $GITHUB_OUTPUT + ./build.sh + shell: bash working-directory: ruby/src - - name: Zip the layer file + - name: Show directory contents run: | - echo ${{ steps.save-ruby-sdk-version.outputs.RUBY_SDK_VERSION}} - ./zip_ruby_layer.sh - working-directory: ruby/src - shell: bash + ls -al + working-directory: ruby/src/build - uses: actions/upload-artifact@v4 name: Save assembled layer to build with: name: opentelemetry-ruby-layer.zip - path: ruby/src/opentelemetry-ruby-layer.zip + path: ruby/src/build/opentelemetry-ruby-layer.zip publish-layer: uses: ./.github/workflows/layer-publish.yml @@ -77,7 +62,7 @@ jobs: artifact-name: opentelemetry-ruby-layer.zip layer-name: opentelemetry-ruby component-version: ${{needs.build-layer.outputs.RUBY_SDK_VERSION}} - runtimes: ruby3.2 - release-group: prod + runtimes: ruby3.2 ruby3.3 + release-group: dev aws_region: ${{ matrix.aws_region }} secrets: inherit diff --git a/ruby/sample-apps/template.yml b/ruby/sample-apps/template.yml index 5627208f0f..41c94623a8 100644 --- a/ruby/sample-apps/template.yml +++ b/ruby/sample-apps/template.yml @@ -12,7 +12,7 @@ Resources: Properties: LayerName: !Ref LayerName Description: Opentelemetry Ruby layer - ContentUri: ./../src/layer + ContentUri: ./../src/otel/layer CompatibleRuntimes: - ruby3.2 Metadata: diff --git a/ruby/src/build.sh b/ruby/src/build.sh new file mode 100755 index 0000000000..01503ee944 --- /dev/null +++ b/ruby/src/build.sh @@ -0,0 +1,7 @@ +#!/bin/sh +set -e + +mkdir -p build + +docker build --progress plain -t aws-otel-lambda-ruby-layer otel +docker run --rm -v "$(pwd)/build:/out" aws-otel-lambda-ruby-layer diff --git a/ruby/src/otel/Dockerfile b/ruby/src/otel/Dockerfile new file mode 100644 index 0000000000..5374377990 --- /dev/null +++ b/ruby/src/otel/Dockerfile @@ -0,0 +1,51 @@ +FROM ubuntu:latest + +RUN mkdir /build + +COPY . /build + +RUN apt-get update && apt-get install -y git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev zip + +RUN git clone https://github.com/rbenv/rbenv.git ~/.rbenv \ + && git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build \ + && git clone https://github.com/rbenv/rbenv-default-gems.git ~/.rbenv/plugins/rbenv-default-gems \ + && echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.profile \ + && echo 'eval "$(rbenv init -)"' >> ~/.profile \ + && echo 'eval "$(rbenv init -)"' >> ~/.bashrc \ + && echo 'bundler' > ~/.rbenv/default-gems + +RUN echo 'alias be="bundle exec"' >> ~/.bashrc +RUN echo 'alias be="bundle exec"' >> ~/.profile + +# install rubies to build our gem against Gemfile +RUN . ~/.profile \ + && cd /root/.rbenv/plugins/ruby-build && git pull && cd - \ + && rbenv install 3.2.0 \ + && rbenv install 3.3.0 + +WORKDIR /build/layer + +RUN . ~/.profile && rbenv local 3.2.0 && bundle install +RUN . ~/.profile && rbenv local 3.3.0 && bundle install + +WORKDIR /root/.rbenv/versions/3.2.0/lib/ruby/gems/ +RUN zip -r gems-3.2.0.zip 3.2.0/ + +WORKDIR /root/.rbenv/versions/3.3.0/lib/ruby/gems/ +RUN zip -r gems-3.3.0.zip 3.3.0/ + +RUN ls -al /root/.rbenv/versions/3.2.0/lib/ruby/gems && ls -al /root/.rbenv/versions/3.3.0/lib/ruby/gems + +# copy gems to /build/ruby/gems for zipping +RUN mkdir /build/ruby && mkdir /build/ruby/gems +WORKDIR /build/ruby/gems +RUN cp /root/.rbenv/versions/3.2.0/lib/ruby/gems/gems-3.2.0.zip . && unzip gems-3.2.0.zip && rm gems-3.2.0.zip +RUN cp /root/.rbenv/versions/3.3.0/lib/ruby/gems/gems-3.3.0.zip . && unzip gems-3.3.0.zip && rm gems-3.3.0.zip +RUN ls -al /build/ruby/gems + +# zip all the gems +WORKDIR /build +RUN cp layer/otel-handler . && cp layer/wrapper.rb . +RUN zip -r opentelemetry-ruby-layer.zip ruby/ otel-handler wrapper.rb + +CMD cp /build/opentelemetry-ruby-layer.zip /out/opentelemetry-ruby-layer.zip diff --git a/ruby/src/layer/Gemfile b/ruby/src/otel/layer/Gemfile similarity index 100% rename from ruby/src/layer/Gemfile rename to ruby/src/otel/layer/Gemfile diff --git a/ruby/src/layer/Makefile b/ruby/src/otel/layer/Makefile similarity index 100% rename from ruby/src/layer/Makefile rename to ruby/src/otel/layer/Makefile diff --git a/ruby/src/layer/otel-handler b/ruby/src/otel/layer/otel-handler similarity index 91% rename from ruby/src/layer/otel-handler rename to ruby/src/otel/layer/otel-handler index 3586efd19c..a7994f48ed 100755 --- a/ruby/src/layer/otel-handler +++ b/ruby/src/otel/layer/otel-handler @@ -12,7 +12,7 @@ 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"; +export LAMBDA_RESOURCE_ATTRIBUTES="cloud.region=$AWS_REGION,cloud.provider=aws,faas.name=$AWS_LAMBDA_FUNCTION_NAME,faas.version=$AWS_LAMBDA_FUNCTION_VERSION,faas.instance=$AWS_LAMBDA_LOG_STREAM_NAME"; if [ -z "${OTEL_RESOURCE_ATTRIBUTES}" ]; then export OTEL_RESOURCE_ATTRIBUTES="$LAMBDA_RESOURCE_ATTRIBUTES"; else diff --git a/ruby/src/layer/wrapper.rb b/ruby/src/otel/layer/wrapper.rb similarity index 100% rename from ruby/src/layer/wrapper.rb rename to ruby/src/otel/layer/wrapper.rb diff --git a/ruby/src/template.yml b/ruby/src/template.yml index 6951404d5d..adfb9535af 100644 --- a/ruby/src/template.yml +++ b/ruby/src/template.yml @@ -12,7 +12,7 @@ Resources: Properties: LayerName: !Ref LayerName Description: Opentelemetry Ruby layer - ContentUri: ./layer + ContentUri: ./otel/layer CompatibleRuntimes: - ruby3.2 Metadata: