This guide provides step-by-step instructions on how to send logs from a Ruby on Rails application to Axiom using the Faraday library. By following this guide, you configure your Rails app to send logs to Axiom, allowing you to monitor and analyze your application logs effectively.Documentation Index
Fetch the complete documentation index at: https://axiom-mano-sample-app.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
- Create an Axiom account.
- Create a dataset where you want to send data.
- Create an API token in Axiom with permissions to ingest and query data.
- Install a Ruby version manager like
rbenvand use it to install the latest Ruby version. - Install Ruby on Rails using the
gem install railscommand.
Set up the Ruby on Rails application
-
Create a new Rails app using the
rails new myappcommand. -
Navigate to the app directory:
cd myapp
Setting up the Gemfile
Open theGemfile in your Rails app, and then add the following gems:
bundle install.
Create and configure the Axiom logger
-
Create a new file named
axiom_logger.rbin theapp/servicesdirectory of your Rails app. -
Add the following code to
axiom_logger.rb:
- Replace
API_TOKENwith your Axiom API key. - Replace
DATASET_NAMEwith the name of the Axiom dataset where you want to send data.
Test with the Axiom logger
-
Create a new file named
axiom_logger_test.rbin theconfig/initializersdirectory. -
Add the following code to
axiom_logger_test.rb:
-
Info logs:
- Application started successfully
- User authentication successful
- Data fetched from external API
- Email notification sent
-
Warn logs:
- API request took longer than expected (including duration)
- User authentication token expiring soon (including user ID)
- Low disk space warning (including disk usage percentage)
- Non-critical configuration issue detected
-
Error logs:
- Database connection error (including error message)
- Failed to process payment (including user ID and error message)
- Unhandled exception occurred (including exception type)
- Third-party API returned an error (including status code)
-
Debug logs:
- Request parameters (including parameter values)
- Response headers (including header key-value pairs)
- User object details (including user attributes)
- Cache hit for key (including cache key)
Create the log.rake tasks
- Create a new directory named
tasksin thelibdirectory of your Rails app. - Create a new file named
log.rakein thelib/tasksdirectory. - Add the following code to
log.rake:
View logs in Axiom
-
Start your Rails server by running
rails server. -
Go to
http://localhost:3000to trigger the test log from the initializer. -
Run the Rake task to send another test log by executing
rails log:send_test_login your terminal. - In Axiom, go to the Stream tab, and then select the dataset where you send the logs.
- You see the test logs appear allowing you to view and analyze your event data coming from your Ruby on Rails application.