LoginSignup
4
1

More than 5 years have passed since last update.

【個人メモ】Elastic BeanstalkのRailsアプリにRollbarとNew Relicを入れる

Last updated at Posted at 2018-07-15

概要

  • RailsにNew RelicRollbarを入れます
  • ライセンスキーは環境変数で管理

環境

  • Rails 5.2
  • dotenv gem導入済み
  • Elastic Beanstalkでアプリがデプロイされている

手順

Rollbarを導入する

サインインを選択
Image from Gyazo

githubもしくはgoogleのアカウントを選択(もしくは、独自のアカウント作成しても可)
Image from Gyazo

(google アカウントを選ぶ場合の例)
Image from Gyazo

適当に読んで次に進む
Image from Gyazo

プロジェクト名を入力
Image from Gyazo

Railsを選択して次に進む
Image from Gyazo

このページの手順に沿って導入するだけです。下記をそれをなぞります。

Image from Gyazo

gemをインストールする

gem 'rollbar'
bundle install

設定ファイルを作成する。(実際には、ユーザーのライセンスキーが表示されていますのでそれをつかってください)

rails generate rollbar 23de3bbfXXXX454583eeXXXX3601fae

config/initializers/rollbar.rb に設定ファイルが作成される。

ライセンスキーを環境変数にする

config/initializers/rollbar.rb
Rollbar.configure do |config|
  # Without configuration, Rollbar is enabled in all environments.
  # To disable in specific environments, set config.enabled=false.

  config.access_token = ENV['ROLLBAR_ACCESS_TOKEN']

  # Here we'll disable in 'test':

.env に書き込む

ROLLBAR_ACCESS_TOKEN=23de3bbfXXXX454583eeXXXX3601fae

テストする

rake rollbar:test

うまく行けばrollbarの画面で下記の様な表示が出ているはずです。

Image from Gyazo

Elastic Beanstalkの環境変数を設定する

Image from Gyazo

デプロイする

eb deploy

rollbarはこれで完了です。

New Relicを導入する

ここからアカウントを作成します。
https://newrelic.com/signup

Image from Gyazo

右下から設定ファイルをダウンロードする。

Image from Gyazo

ダウンロードしたファイルをこちらに保存します。config/newrelic.yml

new relicのgemをインストールします。

gem 'newrelic_rpm'

インストールする。

bundle install

ライセンスキー等を環境変数で置き換えます

config/newrelic.yml
common: &default_settings
  # Required license key associated with your New Relic account.
  license_key: <%= ENV["NEW_RELIC_LICENSE_KEY"] %>

  # Your application name. Renaming here affects where data displays in New
  # Relic.  For more details, see https://docs.newrelic.com/docs/apm/new-relic-apm/maintenance/renaming-applications
  app_name: <%= ENV["NEW_RELIC_APP_NAME"] %>

  # To disable the agent regardless of other settings, uncomment the following:
  # agent_enabled: false

  # Logging level for log/newrelic_agent.log
  log_level: info


# Environment-specific settings are in this section.
# RAILS_ENV or RACK_ENV (as appropriate) is used to determine the environment.
# If your application has other named environments, configure them here.
development:
  <<: *default_settings
  app_name: <%= ENV["NEW_RELIC_APP_NAME"] %> (Development)

test:
  <<: *default_settings
  # It doesn't make sense to report to New Relic from automated test runs.
  monitor_mode: false

staging:
  <<: *default_settings
  app_name: <%= ENV["NEW_RELIC_APP_NAME"] %> (Staging)

production:
  <<: *default_settings

.envに環境変数を入力します。

NEW_RELIC_APP_NAME=QRnote
NEW_RELIC_LICENSE_KEY=d40c6474c7fxxxxxxe4902f228xxxxxxfbd5b3
ROLLBAR_ACCESS_TOKEN=f744f9c58ce0492d818981c966db62f1

Elastic Beanstalkの環境変数を設定する

Image from Gyazo

デプロイする

eb deploy

New Relicもこれで完了です。

以上。

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1