Skip to content

Commit

Permalink
Merge pull request #41 from airbrake/hostname
Browse files Browse the repository at this point in the history
notice: attach hostname information by default
  • Loading branch information
kyrylo committed Feb 2, 2016
2 parents 9416bae + 80c6ba2 commit 8c7d051
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Airbrake Ruby Changelog

### master

* Started attaching the hostname information by default
([#41](https://github.com/airbrake/airbrake-ruby/pull/41))

### [v1.0.3][v1.0.3] (January 18, 2016)

* Improved parsing of backtraces
Expand Down
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 8c7d051

Please sign in to comment.