Ruby
Supported Technologies
Confirm that the tCell agent supports your Ruby configuration, as shown below:
Version | App Servers | Web Frameworks | OS | Authentication Frameworks |
---|---|---|---|---|
2.x, 3.x | Puma 3.11, 4.x, 5.x Unicorn 5.x, 6.x Passenger 6.x | Rails 5.x, 6.x** | Ubuntu 14+ Debian 8+ Alpine 3.7.1+ | Devise 3.x, 4.x* Authlogic 3.5.x, 4.x, 5.x, 6.x |
Ruby Support Legend
* - In Devise 4.7+, Session Hijacking is not available.
** - Rails appfirewall events and certain account takeover features display an ID (integer) for the user_id instead of the username/email. You must manually query the application's database to get those values. For example, if ID=1 and you want the corresponding username in the database (for example, 'User'):> rails console
$ User.find(1) # Depends on the model, but 'User' is most common.
Prerequisites
- tCell account
- Application created with tCell (Admin > Applications)
- Outbound HTTPS connections to the tCell cloud allowed What IPs do tCell agents connect to?
To download the agent and the config file:
- Click on "tCell Admin" in top nav bar.
- Click "Download Agent".
- Select "Ruby" agent.
- Select "Create New API Key" (default).
- Click "Download Config File" to download the agent's config file (which is pre-populated with the application and API key information).
Installation
- Add the following to your Gemfile:
1gem 'tcell_agent'
- Run bundle install:bundle install1bundle install
- Add tcell_agent.config configuration file to the ./config directory of your project. When you start up your server, tCell will be running. You will see logs created in the ./tcell directory of your project.
Initializer
While configuring the application via the tcell_agent.config static configuration file works for most deployments, sometimes one needs to dynamically configure the application. The Ruby agent supports this via exposing a Rails Initializer proc, configure
.
The configure
Proc is part of the TCellAgent module, and it can be used to configure the values in Server Agent Options. If the value uses the "#{...}
syntax, then as other places, it will be dynamically interpreted as code.
Note
The one exception to the configuration value being the same in the initializer is that the "log_dir" configuration value is actually called "agent_log_dir" in the initializer.
The following is an example of configuring the agent dynamically via an Initializer:
Example of configuring an agent dynamically with an Initializer
1if defined?(TCellAgent)2TCellAgent.configure do |config|3config.app_id = "--APPID VALUE--"4config.api_key = "--APIKEY VALUE--"5config.agent_log_dir = "#{Rails.root.join('log').to_s}"6config.logging_options = {"enabled" => true, "level" => "DEBUG"}7end8end
In the example above, the log dir is dynamically calculated as subdirectory "log" from the application root.
Update the Agent
To update the Ruby agent to the newest version, run:
tCell agent update
1bundle update tcell_agent
Bundler automatically updates the agent to the newest release on Rubygems.org.
Verification
To verify that data are being sent to tCell, go to your tCell console and ensure that the number of app server agents listed for the application you just created is more than 0.
Troubleshooting
You can customize the log level in the tcell_agent.config file by adding a block such as the following:
agent config snippet
1json2"logging_options": {3"enabled": true,4"level": "INFO"5}
See tcell_agent.config.template for an example.
Valid log levels are:
- ERROR
- WARN
- INFO (default)
- DEBUG
- TRACE
The preceding list indicates the precedence among the levels, from top to bottom. When you enable a log level, the higher log levels are also enabled. For example, if you enable WARN, then ERROR is also enabled.
When a log file becomes full, logging continues in a new log file. See Log Rolling for more information.