From 2ba9451b46ac8df433c9d4f1101347f328efb026 Mon Sep 17 00:00:00 2001 From: Alan West <3676547+alanwest@users.noreply.github.com> Date: Fri, 3 May 2024 13:44:03 -0700 Subject: [PATCH] Simplify Ruby example --- .../ruby/{instrumented => }/Gemfile | 0 .../ruby/{instrumented => }/Gemfile.lock | 1 + getting-started-guides/ruby/README.md | 43 +++++++++++++++++++ .../ruby/{instrumented => }/app.rb | 0 .../ruby/{instrumented => }/config.ru | 0 .../ruby/{instrumented => }/fibonacci.rb | 0 .../ruby/instrumented/README.md | 42 ------------------ .../ruby/instrumented/call-app.ps1 | 14 ------ .../ruby/instrumented/call-app.sh | 21 --------- .../ruby/instrumented/load-generator.ps1 | 7 --- .../ruby/instrumented/load-generator.sh | 10 ----- .../ruby/{instrumented => }/opentelemetry.rb | 0 .../ruby/uninstrumented/Gemfile | 8 ---- .../ruby/uninstrumented/Gemfile.lock | 35 --------------- .../ruby/uninstrumented/README.md | 24 ----------- .../ruby/uninstrumented/app.rb | 35 --------------- .../ruby/uninstrumented/call-app.ps1 | 14 ------ .../ruby/uninstrumented/call-app.sh | 21 --------- .../ruby/uninstrumented/config.ru | 10 ----- .../ruby/uninstrumented/fibonacci.rb | 21 --------- .../ruby/uninstrumented/load-generator.ps1 | 7 --- .../ruby/uninstrumented/load-generator.sh | 10 ----- 22 files changed, 44 insertions(+), 279 deletions(-) rename getting-started-guides/ruby/{instrumented => }/Gemfile (100%) rename getting-started-guides/ruby/{instrumented => }/Gemfile.lock (99%) create mode 100644 getting-started-guides/ruby/README.md rename getting-started-guides/ruby/{instrumented => }/app.rb (100%) rename getting-started-guides/ruby/{instrumented => }/config.ru (100%) rename getting-started-guides/ruby/{instrumented => }/fibonacci.rb (100%) delete mode 100644 getting-started-guides/ruby/instrumented/README.md delete mode 100644 getting-started-guides/ruby/instrumented/call-app.ps1 delete mode 100755 getting-started-guides/ruby/instrumented/call-app.sh delete mode 100644 getting-started-guides/ruby/instrumented/load-generator.ps1 delete mode 100755 getting-started-guides/ruby/instrumented/load-generator.sh rename getting-started-guides/ruby/{instrumented => }/opentelemetry.rb (100%) delete mode 100644 getting-started-guides/ruby/uninstrumented/Gemfile delete mode 100644 getting-started-guides/ruby/uninstrumented/Gemfile.lock delete mode 100644 getting-started-guides/ruby/uninstrumented/README.md delete mode 100644 getting-started-guides/ruby/uninstrumented/app.rb delete mode 100644 getting-started-guides/ruby/uninstrumented/call-app.ps1 delete mode 100755 getting-started-guides/ruby/uninstrumented/call-app.sh delete mode 100644 getting-started-guides/ruby/uninstrumented/config.ru delete mode 100644 getting-started-guides/ruby/uninstrumented/fibonacci.rb delete mode 100644 getting-started-guides/ruby/uninstrumented/load-generator.ps1 delete mode 100755 getting-started-guides/ruby/uninstrumented/load-generator.sh diff --git a/getting-started-guides/ruby/instrumented/Gemfile b/getting-started-guides/ruby/Gemfile similarity index 100% rename from getting-started-guides/ruby/instrumented/Gemfile rename to getting-started-guides/ruby/Gemfile diff --git a/getting-started-guides/ruby/instrumented/Gemfile.lock b/getting-started-guides/ruby/Gemfile.lock similarity index 99% rename from getting-started-guides/ruby/instrumented/Gemfile.lock rename to getting-started-guides/ruby/Gemfile.lock index f94900fe..ba6005db 100644 --- a/getting-started-guides/ruby/instrumented/Gemfile.lock +++ b/getting-started-guides/ruby/Gemfile.lock @@ -217,6 +217,7 @@ GEM PLATFORMS arm64-darwin-22 + arm64-darwin-23 x86_64-darwin-22 x86_64-linux diff --git a/getting-started-guides/ruby/README.md b/getting-started-guides/ruby/README.md new file mode 100644 index 00000000..f107e5be --- /dev/null +++ b/getting-started-guides/ruby/README.md @@ -0,0 +1,43 @@ +# Getting Started Guide - Ruby + +This is a simple application instrumented with [OpenTelemetry Ruby](https://github.com/open-telemetry/opentelemetry-ruby). +It demonstrates how to configure OpenTelemetry Ruby to send data to New Relic. + +## Requirements + +* [Ruby 3.2.2](https://www.ruby-lang.org/en) +* [A New Relic account](https://one.newrelic.com/) +* [A New Relic license key](https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#license-key) + +## Running the application + +1. Set the following environment variables to configure OpenTelemetry to send + data to New Relic: + + ```shell + export OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.nr-data.net + export OTEL_EXPORTER_OTLP_HEADERS=api-key= + export OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT=4095 + export OTEL_SERVICE_NAME=getting-started-ruby + export OTEL_RESOURCE_ATTRIBUTES=service.instance.id=123 + ``` + + * If your account is based in the EU, set the endpoint to: [https://otlp.eu01.nr-data.net](https://otlp.eu01.nr-data.net) + +2. Run the following command to install dependencies: + + ```shell + bundle install + ``` + +3. Run the application with the following command and open + [http://localhost:8080/fibonacci?n=1](http://localhost:8080/fibonacci?n=1) + in your web browser to ensure it is working. + + ```shell + bundle exec rackup + ``` + +4. Experiment with providing different values for `n` in the query string. + Valid values are between 1 and 90. Values outside this range cause an error + which will show up in New Relic. diff --git a/getting-started-guides/ruby/instrumented/app.rb b/getting-started-guides/ruby/app.rb similarity index 100% rename from getting-started-guides/ruby/instrumented/app.rb rename to getting-started-guides/ruby/app.rb diff --git a/getting-started-guides/ruby/instrumented/config.ru b/getting-started-guides/ruby/config.ru similarity index 100% rename from getting-started-guides/ruby/instrumented/config.ru rename to getting-started-guides/ruby/config.ru diff --git a/getting-started-guides/ruby/instrumented/fibonacci.rb b/getting-started-guides/ruby/fibonacci.rb similarity index 100% rename from getting-started-guides/ruby/instrumented/fibonacci.rb rename to getting-started-guides/ruby/fibonacci.rb diff --git a/getting-started-guides/ruby/instrumented/README.md b/getting-started-guides/ruby/instrumented/README.md deleted file mode 100644 index 46323f7b..00000000 --- a/getting-started-guides/ruby/instrumented/README.md +++ /dev/null @@ -1,42 +0,0 @@ -# Getting Started Guide - Ruby - -This is the solution (completely instrumented with OpenTelemetry) for the Ruby demo application used in the Getting Started Guide - Ruby doc. - -Requires: - -* Ruby 3.2.2 -* Bundler -* [A New Relic account](https://one.newrelic.com/) - -To run this demo app via the CLI: - -1. Switch to the `getting-started-guides/ruby/instrumented` directory -2. Set these two environment variables to send data to your New Relic account: -``` -export OTEL_EXPORTER_OTLP_HEADERS=api-key= -export OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.nr-data.net -``` -* Make sure to use your [ingest license key](https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#license-key) -* If your account is based in the EU, set the endpoint to: https://otlp.eu01.nr-data.net - -3. Set this environment variable to name the demo app: -``` -export OTEL_SERVICE_NAME=getting-started-ruby -``` - -4. Install your gems using Bundler: -```shell -bundle install -``` - -5. Run the following command: -```shell -bundle exec rackup -``` - -4. To generate traffic, in a new terminal tab run the following command: -```shell -./load-generator.sh -``` - -5. To shut down the program, run the following in both shells or terminal tabs: `ctrl + c`. diff --git a/getting-started-guides/ruby/instrumented/call-app.ps1 b/getting-started-guides/ruby/instrumented/call-app.ps1 deleted file mode 100644 index 04e5d92d..00000000 --- a/getting-started-guides/ruby/instrumented/call-app.ps1 +++ /dev/null @@ -1,14 +0,0 @@ -Write-Output "GET $ENDPOINT/fibonacci?n=5" -Invoke-WebRequest -Uri "$ENDPOINT/fibonacci?n=5" | Select-Object -Expand Content - -Write-Output "GET $ENDPOINT/fibonacci?n=283" -Invoke-WebRequest -Uri "$ENDPOINT/fibonacci?n=283" | Select-Object -Expand Content - -Write-Output "GET $ENDPOINT/fibonacci?n=10" -Invoke-WebRequest -Uri "$ENDPOINT/fibonacci?n=10" | Select-Object -Expand Content - -Write-Output "GET $ENDPOINT/fibonacci?n=90" -Invoke-WebRequest -Uri "$ENDPOINT/fibonacci?n=90" | Select-Object -Expand Content - -Write-Output "GET $ENDPOINT/fibonacci?n=0" -Invoke-WebRequest -Uri "$ENDPOINT/fibonacci?n=0" | Select-Object -Expand Content diff --git a/getting-started-guides/ruby/instrumented/call-app.sh b/getting-started-guides/ruby/instrumented/call-app.sh deleted file mode 100755 index d63a747a..00000000 --- a/getting-started-guides/ruby/instrumented/call-app.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -echo "GET ${1}/fibonacci?n=5" -curl "${1}/fibonacci?n=5" || true -echo - -echo "GET ${1}/fibonacci?n=283" -curl "${1}/fibonacci?n=283" || true -echo - -echo "GET ${1}/fibonacci?n=10" -curl "${1}/fibonacci?n=10" || true -echo - -echo "GET ${1}/fibonacci?n=90" -curl "${1}/fibonacci?n=90" || true -echo - -echo "GET ${1}/fibonacci?n=0" -curl "${1}/fibonacci?n=0" || true -echo diff --git a/getting-started-guides/ruby/instrumented/load-generator.ps1 b/getting-started-guides/ruby/instrumented/load-generator.ps1 deleted file mode 100644 index 99a22bde..00000000 --- a/getting-started-guides/ruby/instrumented/load-generator.ps1 +++ /dev/null @@ -1,7 +0,0 @@ -$ENDPOINT="http://localhost:8080" - -while ($true) { - Write-Output "Calling fibonacci-ruby" - & ".\call-app.ps1" - Start-Sleep -s 2 -} diff --git a/getting-started-guides/ruby/instrumented/load-generator.sh b/getting-started-guides/ruby/instrumented/load-generator.sh deleted file mode 100755 index f6ec01c5..00000000 --- a/getting-started-guides/ruby/instrumented/load-generator.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -while : -do - echo "Calling fibonacci-ruby" - ./call-app.sh http://localhost:8080 || true - echo - - sleep 2 -done diff --git a/getting-started-guides/ruby/instrumented/opentelemetry.rb b/getting-started-guides/ruby/opentelemetry.rb similarity index 100% rename from getting-started-guides/ruby/instrumented/opentelemetry.rb rename to getting-started-guides/ruby/opentelemetry.rb diff --git a/getting-started-guides/ruby/uninstrumented/Gemfile b/getting-started-guides/ruby/uninstrumented/Gemfile deleted file mode 100644 index 5262ad43..00000000 --- a/getting-started-guides/ruby/uninstrumented/Gemfile +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -source 'https://rubygems.org' - -ruby '3.2.2' - -gem 'sinatra', '~> 3.0.6' -gem 'thin', '~> 1.8.2' diff --git a/getting-started-guides/ruby/uninstrumented/Gemfile.lock b/getting-started-guides/ruby/uninstrumented/Gemfile.lock deleted file mode 100644 index bd11c268..00000000 --- a/getting-started-guides/ruby/uninstrumented/Gemfile.lock +++ /dev/null @@ -1,35 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - daemons (1.4.1) - eventmachine (1.2.7) - mustermann (3.0.0) - ruby2_keywords (~> 0.0.1) - rack (2.2.8.1) - rack-protection (3.0.6) - rack - ruby2_keywords (0.0.5) - sinatra (3.0.6) - mustermann (~> 3.0) - rack (~> 2.2, >= 2.2.4) - rack-protection (= 3.0.6) - tilt (~> 2.0) - thin (1.8.2) - daemons (~> 1.0, >= 1.0.9) - eventmachine (~> 1.0, >= 1.0.4) - rack (>= 1, < 3) - tilt (2.2.0) - -PLATFORMS - x86_64-darwin-22 - x86_64-linux - -DEPENDENCIES - sinatra (~> 3.0.6) - thin (~> 1.8.2) - -RUBY VERSION - ruby 3.2.2p53 - -BUNDLED WITH - 2.4.10 diff --git a/getting-started-guides/ruby/uninstrumented/README.md b/getting-started-guides/ruby/uninstrumented/README.md deleted file mode 100644 index c1d77c68..00000000 --- a/getting-started-guides/ruby/uninstrumented/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# Uninstrumented Ruby demo app - -Requires: - -* Ruby 3.2.2 -* Bundler -* A New Relic account - -To run the uninstrumented Ruby app via the CLI, switch to the `getting-started-guides/ruby/uninstrumented` directory and run: -```shell -bundle install -``` - -To start the server, run: -```shell -bundle exec rackup -``` - -To exercise, in a new shell: -```shell -./load-generator.sh -``` - -To shut down the program, run the following in both shells or terminal tabs: `ctrl + c`. diff --git a/getting-started-guides/ruby/uninstrumented/app.rb b/getting-started-guides/ruby/uninstrumented/app.rb deleted file mode 100644 index c4d6bd56..00000000 --- a/getting-started-guides/ruby/uninstrumented/app.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -require 'json' -require 'sinatra/base' -require_relative 'fibonacci' - -class App < Sinatra::Base - MIN = 1 - MAX = 90 - - set :show_exceptions, :after_handler - - get '/' do - redirect '/fibonacci' - end - - get '/fibonacci' do - content_type :json - - n = params['n'].to_i - - if n.between?(MIN, MAX) - result = Fibonacci.calculate(n) - else - raise Fibonacci::RangeError - end - - JSON.generate({n: n, result: result}) - end - - error Fibonacci::RangeError do - status 400 - env['sinatra.error'].message - end -end diff --git a/getting-started-guides/ruby/uninstrumented/call-app.ps1 b/getting-started-guides/ruby/uninstrumented/call-app.ps1 deleted file mode 100644 index 04e5d92d..00000000 --- a/getting-started-guides/ruby/uninstrumented/call-app.ps1 +++ /dev/null @@ -1,14 +0,0 @@ -Write-Output "GET $ENDPOINT/fibonacci?n=5" -Invoke-WebRequest -Uri "$ENDPOINT/fibonacci?n=5" | Select-Object -Expand Content - -Write-Output "GET $ENDPOINT/fibonacci?n=283" -Invoke-WebRequest -Uri "$ENDPOINT/fibonacci?n=283" | Select-Object -Expand Content - -Write-Output "GET $ENDPOINT/fibonacci?n=10" -Invoke-WebRequest -Uri "$ENDPOINT/fibonacci?n=10" | Select-Object -Expand Content - -Write-Output "GET $ENDPOINT/fibonacci?n=90" -Invoke-WebRequest -Uri "$ENDPOINT/fibonacci?n=90" | Select-Object -Expand Content - -Write-Output "GET $ENDPOINT/fibonacci?n=0" -Invoke-WebRequest -Uri "$ENDPOINT/fibonacci?n=0" | Select-Object -Expand Content diff --git a/getting-started-guides/ruby/uninstrumented/call-app.sh b/getting-started-guides/ruby/uninstrumented/call-app.sh deleted file mode 100755 index d63a747a..00000000 --- a/getting-started-guides/ruby/uninstrumented/call-app.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -echo "GET ${1}/fibonacci?n=5" -curl "${1}/fibonacci?n=5" || true -echo - -echo "GET ${1}/fibonacci?n=283" -curl "${1}/fibonacci?n=283" || true -echo - -echo "GET ${1}/fibonacci?n=10" -curl "${1}/fibonacci?n=10" || true -echo - -echo "GET ${1}/fibonacci?n=90" -curl "${1}/fibonacci?n=90" || true -echo - -echo "GET ${1}/fibonacci?n=0" -curl "${1}/fibonacci?n=0" || true -echo diff --git a/getting-started-guides/ruby/uninstrumented/config.ru b/getting-started-guides/ruby/uninstrumented/config.ru deleted file mode 100644 index a5e42cee..00000000 --- a/getting-started-guides/ruby/uninstrumented/config.ru +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -require 'bundler' - -Bundler.require - -require './fibonacci' -require './app' - -Rack::Handler.default.run(App, :Port => 8080) diff --git a/getting-started-guides/ruby/uninstrumented/fibonacci.rb b/getting-started-guides/ruby/uninstrumented/fibonacci.rb deleted file mode 100644 index cd91e4a9..00000000 --- a/getting-started-guides/ruby/uninstrumented/fibonacci.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -module Fibonacci - class RangeError < StandardError - MESSAGE = JSON.generate(message: 'n must be 1 <= n <= 90.') - - def initialize(msg = MESSAGE) - super - end - end - - def self.calculate(n) - first_num, second_num = [0, 1] - - (n - 1).times do - first_num, second_num = second_num, first_num + second_num - end - - first_num - end -end diff --git a/getting-started-guides/ruby/uninstrumented/load-generator.ps1 b/getting-started-guides/ruby/uninstrumented/load-generator.ps1 deleted file mode 100644 index 99a22bde..00000000 --- a/getting-started-guides/ruby/uninstrumented/load-generator.ps1 +++ /dev/null @@ -1,7 +0,0 @@ -$ENDPOINT="http://localhost:8080" - -while ($true) { - Write-Output "Calling fibonacci-ruby" - & ".\call-app.ps1" - Start-Sleep -s 2 -} diff --git a/getting-started-guides/ruby/uninstrumented/load-generator.sh b/getting-started-guides/ruby/uninstrumented/load-generator.sh deleted file mode 100755 index f6ec01c5..00000000 --- a/getting-started-guides/ruby/uninstrumented/load-generator.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -while : -do - echo "Calling fibonacci-ruby" - ./call-app.sh http://localhost:8080 || true - echo - - sleep 2 -done