Rails - providing a license key for a host-based plugin

I use New Relic for Rails, but I need a new relic to monitor my work environment. However, I have an intermediate server that also works in production mode. The new relic discovers both operational instances of my application (as it should be), but I do not want to pay for monitoring two instances when I only want to monitor it.

The new relic accepts an environment variable for the license key:

license_key: <%= ENV['NEWRELIC_ACCOUNT_KEY'] %>

Is it possible to define the host name in environment files (i.e. config / environment / production.rb) so that I can dynamically define this environment variable?

Both environments are deployed from the same Git repository, the same source code base, so I cannot change it in the code for each deployment - it would be best to somehow dynamically define the environment variable.

Any thoughts would be appreciated! Thanks!

+3
source share
3 answers

The new Relic Ruby agent will parse the configuration file newrelic.ymlas ERB before parsing it as YAML. So you can do a lot of neat tricks, for example:

production:
  license_key: <%= Socket.gethostname == 'mission-critical.example.com' ? 'PAID_ACCOUNT_LICENSE_KEY' : 'FREE_LITE_ACCOUNT_LICENSE_KEY' %>

This parsing occurs during application loading.

RAILS_ENV "production" , " ", , .

+4

? .. , , ? . ...

, config/newrelic.yml

common: &default_settings
  license_key: 'PASTE_YOUR_KEY_HERE'
  â€Ļ

development:
  enabled: false
  â€Ļ

test:
  enabled: false
  â€Ļ

production:
  enabled: true
  â€Ļ

staging: 
  enabled: false
  â€Ļ

..

+2

, , , rails .

I would just set up the deployment of your script queue to copy production.rb to staging.rb and run the application in "staging" mode. Another way is to not save newrelic.yml in your scm and instead copy it or link to it from another location in the current deployment directory.

0
source

Source: https://habr.com/ru/post/1721657/


All Articles