Skip to content

Commit 4ab296b

Browse files
committed
Speedup Heroku detection, generalize sys_command
1 parent 81b3e59 commit 4ab296b

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

lib/raven/base.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,13 @@ def safely_prepend(module_name, opts = {})
9090
opts[:to].send(:include, opts[:from].const_get("Old" + module_name))
9191
end
9292
end
93+
94+
def sys_command(unix_command, win_command = nil)
95+
unix_result = `#{unix_command} 2>&1` rescue nil # redirect stderr to stdout
96+
return unix_result if unix_result != "" && unix_result
97+
return if win_command.nil?
98+
win_result = `#{win_command}` rescue nil
99+
win_result != "" && win_result
100+
end
93101
end
94102
end

lib/raven/configuration.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,15 @@ def detect_release
275275
private
276276

277277
def detect_release_from_heroku
278-
sys_dyno_info = `cat /etc/heroku/dyno` rescue nil
279-
return unless sys_dyno_info && sys_dyno_info != ""
278+
sys_dyno_info = File.read("/etc/heroku/dyno").strip if File.directory?("/etc/heroku") rescue nil
279+
return unless sys_dyno_info
280280

281281
# being overly cautious, because if we raise an error Raven won't start
282282
begin
283283
hash = JSON.parse(sys_dyno_info)
284284
hash && hash["release"] && hash["release"]["commit"]
285285
rescue JSON::JSONError
286-
logger.error "Cannot parse Heroku JSON: #{sys_dyno_info}"
286+
Raven.logger.error "Cannot parse Heroku JSON: #{sys_dyno_info}"
287287
end
288288
end
289289

lib/raven/context.rb

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ def initialize
2424
class << self
2525
def os_context
2626
@os_context ||= {
27-
"name" => sys_command("uname -s") || RbConfig::CONFIG["host_os"],
28-
"version" => sys_command("uname -v"),
29-
"build" => sys_command("uname -r"),
30-
"kernel_version" => sys_command("uname -a", "ver")
27+
"name" => Raven.sys_command("uname -s") || RbConfig::CONFIG["host_os"],
28+
"version" => Raven.sys_command("uname -v"),
29+
"build" => Raven.sys_command("uname -r"),
30+
"kernel_version" => Raven.sys_command("uname -a", "ver")
3131
}
3232
end
3333

@@ -37,13 +37,6 @@ def runtime_context
3737
"version" => RbConfig::CONFIG["ruby_version"]
3838
}
3939
end
40-
41-
def sys_command(unix_command, win_command = nil)
42-
unix_result = `#{unix_command}` rescue nil
43-
return unix_result if unix_result != "" && unix_result
44-
win_result = `#{win_command}` rescue nil
45-
win_result != "" && win_result
46-
end
4740
end
4841
end
4942
end

0 commit comments

Comments
 (0)