lib/bmc-daemon-lib/conf.rb in bmc-daemon-lib-0.4.1 vs lib/bmc-daemon-lib/conf.rb in bmc-daemon-lib-0.4.2
- old
+ new
@@ -183,34 +183,35 @@
def self.prepare_newrelic
# Disable if no config present
return unless self.feature?(:newrelic)
# Ok, let's start
- section = self[:newrelic]
log :conf, "prepare NewRelic"
+ conf = self[:newrelic]
# Enable GC profiler
GC::Profiler.enable
# Build NewRelic app_name if not provided as-is
- if !section[:app_name]
- stack = []
- stack << (section[:prefix] || @app_name)
- stack << section[:platform] if section[:platform]
- stack << @app_env
- text = stack.join('-')
- section[:app_name] = "#{text}; #{text}-#{host}"
- end
+ self.newrelic_init_app_name(conf)
+ # Set env variables
+ ENV["NEW_RELIC_AGENT_ENABLED"] = "true"
+ ENV["NEW_RELIC_LOG"] = logfile_path(:newrelic)
+ ENV["NEW_RELIC_LICENSE_KEY"] = conf[:license].to_s
+ ENV["NEW_RELIC_APP_NAME"] = conf[:app_name].to_s
+
+ # logger_newrelic = Logger.new('/tmp/newrelic.log')
+ # logger_newrelic.debug Time.now()
# Start the agent
- NewRelic::Agent.manual_start({
- agent_enabled: true,
- log: LoggerPool.instance.get(:newrelic),
- env: @app_env,
- license_key: section[:license].to_s,
- app_name: section[:app_name].to_s,
- })
+ # NewRelic::Agent.manual_start({
+ # agent_enabled: true,
+ # log: logger_newrelic,
+ # env: @app_env,
+ # license_key: conf[:license].to_s,
+ # app_name: conf[:app_name].to_s,
+ # })
end
def self.prepare_rollbar
# Disable if no config present
unless self.feature?(:rollbar)
@@ -219,17 +220,17 @@
end
return
end
# Ok, let's start
- section = self[:rollbar]
log :conf, "prepare Rollbar"
+ conf = self[:rollbar]
# Configure
Rollbar.configure do |config|
config.enabled = true
- config.access_token = section[:token].to_s
+ config.access_token = conf[:token].to_s
config.code_version = @app_version
config.environment = @app_env
config.logger = LoggerPool.instance.get(:rollbar)
config.use_async = true
end
@@ -246,9 +247,24 @@
message
)
end
protected
+
+ def self.newrelic_init_app_name conf
+ # Ignore if already set
+ return if conf[:app_name]
+
+ # Stack all those parts
+ stack = []
+ stack << (conf[:prefix] || @app_name)
+ stack << conf[:platform] if conf[:platform]
+ stack << @app_env
+ text = stack.join('-')
+
+ # Return a composite appname
+ conf[:app_name] = "#{text}; #{text}-#{@host}"
+ end
def self.load_files
load files: @files, namespaces: { environment: @app_env }
end