Skip to content

Commit

Permalink
notice: attach hostname information by default
Browse files Browse the repository at this point in the history
The hostname information has to be present in many of our integrations
from the Airbrake gem. This information is just too useful and it
should be retreived by default.
  • Loading branch information
kyrylo committed Feb 2, 2016
1 parent 9416bae commit e2c2070
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/airbrake-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'thread'
require 'set'
require 'English'
require 'socket'

require 'airbrake-ruby/version'
require 'airbrake-ruby/config'
Expand Down
9 changes: 8 additions & 1 deletion lib/airbrake-ruby/notice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class Notice
:params
].freeze

##
# @return [String] the name of the host machine
HOSTNAME = Socket.gethostname.freeze

def initialize(config, exception, params = {})
@config = config

Expand Down Expand Up @@ -145,7 +149,10 @@ def context(params)

# Legacy Airbrake v4 behaviour.
component: params.delete(:component),
action: params.delete(:action)
action: params.delete(:action),

# Make sure we always send hostname.
hostname: HOSTNAME
}.merge(CONTEXT).delete_if { |_key, val| val.nil? || val.empty? }
end

Expand Down
5 changes: 5 additions & 0 deletions spec/notice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
expect(notice.to_json).
to match(/"notifier":{"name":"airbrake-ruby","version":".+","url":".+"}/)
end

it "always contains context/hostname" do
expect(notice.to_json).
to match(/"context":{.*"hostname":".+".*}/)
end
end

describe "#[]" do
Expand Down

0 comments on commit e2c2070

Please sign in to comment.