Quick Start

Requirements

SkyWalking Ruby agent requires SkyWalking 8.0+ and Ruby 3.0+

Installing the gem

The Ruby agent's gem is available from RubyGems as skywalking, we recommend you install and manage the skywalking gem dependency with Bundler, add the following line to your Gemfile, then run bundle install to install the gem.

# Gemfile
source "https://rubygems.org"

gem "skywalking"

Besides, you can also make installation as simple as gem install skywalking.

Installing from Source Code

Download the source tar from the official website, and run the following commands to build from source

Make sure you have Ruby 3.0+ and the gem command available

tar -zxf skywalking-ruby-src-<version>.tgz
cd skywalking-ruby-src-<version>
gem build skywalking.gemspec

If successful, the following will be displayed:

  Successfully built RubyGem
  Name: skywalking
  Version: <version>
  File: skywalking-<version>.gem

Then you can use skywalking-<version>.gem to your gemfile.

Getting started with Rails

You need to manually add Skywalking.start under config/initializers directory.

Optionally the command bundle exec rails generate skywalking:start, will create a config file config/initializers/skywalking.rb, and then you can configure the start parameters.

Getting started with Sinatra

You can list gem 'skywalking' after sinatra in your Gemfile and use Bundler.require during initialization or calling require 'skywalking' after sinatra gem is loaded, that is, skywalking gem needs to be after the other gems you require (e.g. redis, elasticsearch), like the following code:

require 'redis'
require 'sinatra'
require 'skywalking'

Skywalking.start

get '/sw' do
  "Hello, SkyWalking!"
end

Configuration

You can configure the SkyWalking Ruby agent in various ways, the Ruby agent follows this order of precedence for configuration:

  • Defaults (please see DEFAULTS)
  • Arguments to Skywalking.start
  • Configuration file (e.g. conifg/skywalking.yml)
  • Environment variables

The following is an example of configuration at start:

Skywalking.start(
  service_name: 'sw-srv',
  instance_name: 'sw-inst',
  collector_backend_services: 'oap:11800',
  meter_reporter_active: true,
  log_reporter_active: true,
  meter_report_period: 30,
  log_report_period: 10
)

The following is an example of a configuration file:

common: &defaults
  service_name: Ruby-Agent-Common
  log_level: debug
  meter_reporter_active: true
  log_reporter_active: true
  meter_report_period: 20
  log_report_period: 5

development:
  <<: *defaults
  service_name: Ruby-Agent-Development
  log_reporter_level: 0  # DEBUG

test:
  <<: *defaults
  service_name: Ruby-Agent-Test
  log_reporter_level: 1  # INFO

production:
  <<: *defaults
  service_name: Ruby-Agent-Production
  log_reporter_level: 2  # WARN

The following lists all the configuration options:

keyenvironment keydefault valuedescription
service_nameSW_AGENT_SERVICE_NAMEYour_ApplicationNameThe name of the service which showed in UI.
instance_nameSW_AGENT_INSTANCE_NAMEYour_InstanceNameTo obtain the environment variable key for the instance name, if it cannot be obtained, an instance name will be automatically generated.
namespaceSW_AGENT_NAMESPACENot setNamespace represents a subnet, such as kubernetes namespace, or 172.10..
environmentSW_AGENT_ENVIRONMENTNot setThe name of the environment this service is deployed in
collector_backend_servicesSW_AGENT_COLLECTOR_BACKEND_SERVICES127.0.0.1:11800Collector SkyWalking trace receiver service addresses.
config_fileSW_AGENT_CONFIG_FILENot setThe absolute path to the configuration file, if empty, it will automatically search for config/skywalking.yml in the root directory.
log_file_nameSW_AGENT_LOG_FILE_NAMEskywalkingThe name of the log file.
log_file_pathSW_AGENT_LOG_FILE_PATHNot setThe path to the log file.
log_levelSW_AGENT_LOG_LEVELinfoThe log level.
disable_pluginsSW_AGENT_DISABLE_PLUGINSNot setThe plugins to disable, multiple names should be split by comma, e.g. ‘redis5,elasticsearch’.
report_protocolSW_AGENT_REPORT_PROTOCOLgrpcThe protocol to use for reporting.
re_ignore_operationSW_AGENT_RE_IGNORE_OPERATIONNot setIgnore specific URL paths.
instance_properties_jsonSW_AGENT_INSTANCE_PROPERTIES_JSONNot setA custom JSON string to be reported as service instance properties, e.g. {"key": "value"}.
collector_heartbeat_periodSW_AGENT_COLLECTOR_HEARTBEAT_PERIOD30he agent will send heartbeat to OAP every collector_heartbeat_period seconds.
properties_report_period_factorSW_AGENT_PROPERTIES_REPORT_PERIOD_FACTOR10The agent will report service instance properties every collector_heartbeat_period * properties_report_period_factor seconds.
max_queue_sizeSW_AGENT_MAX_QUEUE_SIZE10000The maximum queue size for reporting data.
meter_reporter_activeSW_AGENT_METER_REPORTER_ACTIVEtrueEnable/disable meter reporter for runtime metrics collection.
meter_report_periodSW_AGENT_METER_REPORT_PERIOD60Meter report period in seconds.
max_meter_queue_sizeSW_AGENT_MAX_METER_QUEUE_SIZE1000Maximum meter queue size for buffering metrics data.
log_reporter_activeSW_AGENT_LOG_REPORTER_ACTIVEtrueEnable/disable log reporter for log collection.
log_reporter_levelSW_AGENT_LOG_REPORTER_LEVEL1 (INFO)Minimum log level to report (Logger::DEBUG=0, INFO=1, WARN=2, ERROR=3, FATAL=4).
log_report_periodSW_AGENT_LOG_REPORT_PERIOD5Log report period in seconds.
max_log_queue_sizeSW_AGENT_MAX_LOG_QUEUE_SIZE1000Maximum log queue size for buffering log data.