OpenTelemetry Ruby Installation

Make sure to install the AppSignal collector before proceeding with these instructions.

Install the OpenTelemetry gems

Use Bundler to add the OpenTelemetry SDK, OTLP exporter and instrumentation packages to your application's Gemfile:

Shell
bundle add opentelemetry-sdk opentelemetry-exporter-otlp opentelemetry-instrumentation-all

The opentelemetry-instrumentation-all package installs instrumentations for most frameworks and libraries. You can check out a list of instrumented frameworks and libraries in the package's dependencies on RubyGems. You can also find additional instrumentations for frameworks and libraries in the OpenTelemetry Registry.

Configure OpenTelemetry in your application

Add this appsignal.rb file to your application with the OpenTelemetry exporter and AppSignal configuration. Then, require this file in your application.

For Rails applications, add it to an Rails initializer like config/initializers/appsignal.rb.

Make sure to update the values below with your AppSignal application name, environment and push API key, and to replace the exporter endpoint with the address of your AppSignal collector if needed.

appsignal.rb
require "socket" require "opentelemetry/sdk" require "opentelemetry/instrumentation/all" require "opentelemetry-exporter-otlp" # Replace these values with your AppSignal application name, environment # and push API key. These are used by the resource attributes configuration below. name = "My app" push_api_key = "0000-0000-0000-0000" environment = defined?(Rails) ? Rails.env.to_s : "development" # Set the name of the service that is being monitored. A common choice is the # name of the framework used. This is used to group traces and metrics in AppSignal. service_name = "My service name" # Replace `http://localhost:8099` with the address of your AppSignal collector # if it's running on another host. endpoint = "http://localhost:8099/v1/traces" revision = `git rev-parse --short HEAD`.strip OpenTelemetry::SDK.configure do |c| c.resource = OpenTelemetry::SDK::Resources::Resource.create( "appsignal.config.name" => name, "appsignal.config.environment" => environment, "appsignal.config.push_api_key" => push_api_key, "appsignal.config.revision" => revision, "appsignal.config.language_integration" => "ruby", "appsignal.config.app_path" => Dir.pwd, "host.name" => Socket.gethostname, ) c.service_name = service_name c.add_span_processor( OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new( OpenTelemetry::Exporter::OTLP::Exporter.new( :endpoint => endpoint, :compression => "none" ) ) ) c.use_all end

Test the app!

Now that all the components are connected, start your app and test if you see data arrive in AppSignal. Check the "Errors > Issue list" and "Performance > Traces" page specifically.

If after following our installation instructions you still don't see data in AppSignal, let us know and we'll help you finalize your OpenTelemetry installation!