|
| 1 | +# Quick Start |
| 2 | + |
| 3 | +## Requirements |
| 4 | + |
| 5 | +**SkyWalking Ruby agent requires SkyWalking 8.0+ and Ruby 3.0+** |
| 6 | + |
| 7 | +## Installing the gem |
| 8 | + |
| 9 | +The Ruby agent's gem is available from [RubyGems](https://rubygems.org/) as `skywalking`, we recommend you install and |
| 10 | +manage the skywalking gem dependency with [Bundler](http://bundler.io/), add the following line to your `Gemfile`, then |
| 11 | +run `bundle install` to install the gem. |
| 12 | + |
| 13 | +~~~ruby |
| 14 | +# Gemfile |
| 15 | +source "https://rubygems.org" |
| 16 | + |
| 17 | +gem "skywalking" |
| 18 | +~~~ |
| 19 | + |
| 20 | +Besides, you can also make installation as simple as `gem install skywalking`. |
| 21 | + |
| 22 | +## Getting started with Rails |
| 23 | + |
| 24 | +You need to manually add `Skywalking.start` under config/initializers directory. |
| 25 | + |
| 26 | +Optionally the command `bundle exec rails generate skywalking:start`, will create a config file |
| 27 | +`config/initializers/skywalking.rb`, and then you can configure the start parameters. |
| 28 | + |
| 29 | +## Getting started with Sinatra |
| 30 | + |
| 31 | +You can list `gem 'skywalking'` after sinatra in your Gemfile and use `Bundler.require` during initialization or calling |
| 32 | +`require 'skywalking'` after sinatra gem is loaded, that is, skywalking gem needs to be after the other gems you |
| 33 | +require (e.g. redis, elasticsearch), like the following code: |
| 34 | + |
| 35 | +~~~ruby |
| 36 | +require 'redis' |
| 37 | +require 'sinatra' |
| 38 | +require 'skywalking' |
| 39 | + |
| 40 | +Skywalking.start |
| 41 | + |
| 42 | +get '/sw' do |
| 43 | + "Hello, SkyWalking!" |
| 44 | +end |
| 45 | +~~~ |
| 46 | + |
| 47 | +## Configuration |
| 48 | + |
| 49 | +You can configure the SkyWalking Ruby agent in various ways, the Ruby agent follows this order of precedence for |
| 50 | +configuration: |
| 51 | + |
| 52 | +- Defaults (please |
| 53 | + see [DEFAULTS](https://github.com/apache/skywalking-ruby/blob/main/lib/skywalking/configuration.rb#L21)) |
| 54 | +- Arguments to `Skywalking.start` |
| 55 | +- Configuration file (e.g. `conifg/skywalking.yml`) |
| 56 | +- Environment variables |
| 57 | + |
| 58 | +The following is an example of configuration at start: |
| 59 | + |
| 60 | +~~~ruby |
| 61 | +Skywalking.start( |
| 62 | + service_name: 'sw-srv', |
| 63 | + instance_name: 'sw-inst', |
| 64 | + collector_backend_services: 'oap:11800' |
| 65 | +) |
| 66 | +~~~ |
| 67 | + |
| 68 | +The following is an example of a configuration file: |
| 69 | +~~~yaml |
| 70 | +common: &defaults |
| 71 | + service_name: Ruby-Agent-Common |
| 72 | + log_level: debug |
| 73 | + |
| 74 | +development: |
| 75 | + <<: *defaults |
| 76 | + service_name: Ruby-Agent-Development |
| 77 | + |
| 78 | +test: |
| 79 | + <<: *defaults |
| 80 | + service_name: Ruby-Agent-Test |
| 81 | + |
| 82 | +production: |
| 83 | + <<: *defaults |
| 84 | + service_name: Ruby-Agent-Production |
| 85 | +~~~ |
| 86 | + |
| 87 | +The following lists all the configuration options: |
| 88 | + |
| 89 | +| key | environment key | default value | description | |
| 90 | +|---------------------------------|------------------------------------------|----------------------|-------------------------------------------------------------------------------------------------------------------------------------------| |
| 91 | +| service_name | SW_AGENT_SERVICE_NAME | Your_ApplicationName | The name of the service which showed in UI. | |
| 92 | +| instance_name | SW_AGENT_INSTANCE_NAME | Your_InstanceName | To obtain the environment variable key for the instance name, if it cannot be obtained, an instance name will be automatically generated. | |
| 93 | +| namespace | SW_AGENT_NAMESPACE | Not set | Namespace represents a subnet, such as kubernetes namespace, or 172.10.. | |
| 94 | +| environment | SW_AGENT_ENVIRONMENT | Not set | The name of the environment this service is deployed in | |
| 95 | +| collector_backend_services | SW_AGENT_COLLECTOR_BACKEND_SERVICES | 127.0.0.1:11800 | Collector SkyWalking trace receiver service addresses. | |
| 96 | +| config_file | SW_AGENT_CONFIG_FILE | Not set | The absolute path to the configuration file, if empty, it will automatically search for config/skywalking.yml in the root directory. | |
| 97 | +| log_file_name | SW_AGENT_LOG_FILE_NAME | skywalking | The name of the log file. | |
| 98 | +| log_file_path | SW_AGENT_LOG_FILE_PATH | Not set | The path to the log file. | |
| 99 | +| log_level | SW_AGENT_LOG_LEVEL | info | The log level. | |
| 100 | +| disable_plugins | SW_AGENT_DISABLE_PLUGINS | Not set | The plugins to disable. | |
| 101 | +| report_protocol | SW_AGENT_REPORT_PROTOCOL | grpc | The protocol to use for reporting. | |
| 102 | +| re_ignore_operation | SW_AGENT_RE_IGNORE_OPERATION | Not set | Ignore specific URL paths. | |
| 103 | +| instance_properties_json | SW_AGENT_INSTANCE_PROPERTIES_JSON | Not set | A custom JSON string to be reported as service instance properties, e.g. `{"key": "value"}`. | |
| 104 | +| collector_heartbeat_period | SW_AGENT_COLLECTOR_HEARTBEAT_PERIOD | 30 | he agent will send heartbeat to OAP every `collector_heartbeat_period` seconds. | |
| 105 | +| properties_report_period_factor | SW_AGENT_PROPERTIES_REPORT_PERIOD_FACTOR | 10 | The agent will report service instance properties every `collector_heartbeat_period * properties_report_period_factor` seconds. | |
| 106 | +| max_queue_size | SW_AGENT_MAX_QUEUE_SIZE | 10000 | The maximum queue size for reporting data. | |
0 commit comments