-
Notifications
You must be signed in to change notification settings - Fork 600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NEW_RELIC_LICENSE_KEY
stopped taking priority over newrelic.yml
#1800
Comments
Hi @sqbell! Sorry to hear you're running into trouble and thanks for submitting an issue. We've been unsuccessful in reproducing what you're seeing. From our investigation, the environment variable To help us figure out what may be happening, we created a gist we'd love for you to run. This is a simple script that will help pinpoint what could be different in your application from what we're testing. Can you double-check that your license key environment variable is set and then run this script and see if we're grabbing the correct value? |
@hannahramadan Thank you for the time. I am sorry but I forgot to mention we also use dotenv to load the variables, so the original script would not work. I modified it like so: #!/usr/bin/env ruby
# frozen_string_literal: true
# 1. Download which_license_key.rb and place it in the same repository as your application
# 2. Run this script with `ruby which_license_key.rb`
# 3. See the terminal output for the license key that New Relic is using
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'dotenv'
gem 'newrelic_rpm'
end
Dotenv.load('../.env.local', "../.env.production", '../.env')
puts "License key is #{NewRelic::Agent.config[:license_key]}"
puts "ENV var: #{ENV['NEW_RELIC_LICENSE_KEY']}"
# Output:
License key is
ENV var: (our license key) I'll try to spend more time figuring this one out this week. |
Thanks for the additional information! Using dotenv is a different situation than using just environment variables as the ruby agent does not have any code specific to dotenv that would ensure environment variables loaded by dotenv are available to the agent. This appears to be a load order issue. The agent needs to have environment variables available to it when the it is first loaded (which happens because it is also required by I was able to confirm the same behavior you described using the script you provided. I have modified the script to delay the agent being loaded until after dotenv has run, and was able to see everything working as expected.
Adding Alternatively, dotenv has some information in their README about how to allow dotenv to work with gems that require environment variables to be set before being loaded. Also, I tried several ruby agent versions with your original script was not able to see any change in behavior between 8.13.1 and 8.16. I took a look, but I'm not aware of any changes we made in any of the versions (8.14, 8.15, 8.16) that would affect load order or anything that would explain what you're seeing. As far as I can tell, this seems like it should have always worked this way, so I'm not sure what could be going on with that. If you're able to narrow it down to a specific version bump where the behavior changes, I could take a closer look again. Hopefully that helps! Please let me know if you run into any issues. |
That works, however I still think something changed. I tried adding the debug statements directly into our Rails app: require_relative 'boot'
require 'active_record/railtie'
require 'action_controller/railtie'
require 'action_view/railtie'
require 'action_mailer/railtie'
require 'active_job/railtie'
require 'action_cable/engine'
require 'rails/test_unit/railtie'
require 'sprockets/railtie'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module OurApp
class Application < Rails::Application
config.load_defaults 6.1
root = OurApp::Engine.root
Dotenv.load(root.join('../.env.local'), root.join("../.env.#{Rails.env}"), root.join('../.env'))
puts "New Relic agent version #{NewRelic::VERSION::STRING}"
puts "License key is #{NewRelic::Agent.config[:license_key]}"
puts "ENV var: #{ENV['NEW_RELIC_LICENSE_KEY']}"
# ... I see the following:
I also looked at specific commits and pinpointed it to 1e989f1.
|
@sqbell Thank you for finding the specific version and commit that changed the behavior you're seeing! That is very helpful for me. I'll take a look at this to see why this changed things, since this change was intended to not alter the existing default behavior. |
@sqbell It looks like this change in behavior was caused by the agent using configuration values earlier in the agent loading process than it did previously. Since we were using a new config for I was able to reproduce that same output in a rails test app using your code snippet on 8.16 (thank you for providing that!), and switching to the |
closed by PR #1791 merge |
After an upgrade from 8.13.1 to 8.16.0 we noticed no logs being shipped.
Description
The error was:
The file was present but had empty
license_key
field as we set it using environmental variableNEW_RELIC_LICENSE_KEY
which, according to https://docs.newrelic.com/docs/apm/agents/ruby-agent/configuration/ruby-agent-configuration/, should take precedence.Expected Behavior
As per https://docs.newrelic.com/docs/apm/agents/ruby-agent/configuration/ruby-agent-configuration/, we expect
NEW_RELIC_LICENSE_KEY
to take precedence overnewrelic.yml
setting.Your Environment
Ruby: 3.1.2
Rails: 7.0.4.1
NR agent: 8.13.1 (works) => 8.16.0 (stopped working)
For Maintainers Only or Hero Triaging this bug
Suggested Priority (P1,P2,P3,P4,P5):
Suggested T-Shirt size (S, M, L, XL, Unknown):
The text was updated successfully, but these errors were encountered: