Skip to content

Commit 81b3e59

Browse files
authored
Merge pull request #566 from nateberkopec/heroku-detection
Heroku detection works on /etc/dyno
2 parents 11fe4cc + 2a22808 commit 81b3e59

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

docs/config.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Optional settings
2626
Using a thread to send events will be adequate for truly parallel Ruby platforms such as JRuby, though the benefit on MRI/CRuby will be limited. Threads also won't report any exceptions raised inside of them, so be careful!
2727

2828
If the async callback raises an exception, Raven will attempt to send synchronously.
29-
29+
3030
We recommend creating a background job, using your background job processor, that will send Sentry notifications in the background. Rather than enqueuing an entire Raven::Event object, we recommend providing the Hash representation of an event as a job argument. Here's an example for ActiveJob:
3131

3232
.. code-block:: ruby
@@ -156,9 +156,9 @@ Optional settings
156156

157157
We guess the release intelligently in the following order of preference:
158158

159-
* Heroku's HEROKU_SLUG_COMMIT environment variable
160-
* Reading from the REVISION file in the app root
161159
* Commit SHA of the last commit (git)
160+
* Reading from the REVISION file in the app root
161+
* Heroku's dyno metadata (must have enabled via Heroku Labs)
162162

163163
.. code-block:: ruby
164164

lib/raven/configuration.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,24 @@ def project_root=(root_dir)
267267
end
268268

269269
def detect_release
270-
detect_release_from_heroku ||
270+
detect_release_from_git ||
271271
detect_release_from_capistrano ||
272-
detect_release_from_git
272+
detect_release_from_heroku
273273
end
274274

275275
private
276276

277277
def detect_release_from_heroku
278-
ENV['HEROKU_SLUG_COMMIT']
278+
sys_dyno_info = `cat /etc/heroku/dyno` rescue nil
279+
return unless sys_dyno_info && sys_dyno_info != ""
280+
281+
# being overly cautious, because if we raise an error Raven won't start
282+
begin
283+
hash = JSON.parse(sys_dyno_info)
284+
hash && hash["release"] && hash["release"]["commit"]
285+
rescue JSON::JSONError
286+
logger.error "Cannot parse Heroku JSON: #{sys_dyno_info}"
287+
end
279288
end
280289

281290
def detect_release_from_capistrano

0 commit comments

Comments
 (0)