From 80c6ba2847f234f828fd9f711ec277edcc4122db Mon Sep 17 00:00:00 2001 From: Kyrylo Silin Date: Tue, 2 Feb 2016 16:38:09 +0200 Subject: [PATCH] notice: attach hostname information by default 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. --- CHANGELOG.md | 3 +++ lib/airbrake-ruby.rb | 1 + lib/airbrake-ruby/notice.rb | 9 ++++++++- spec/notice_spec.rb | 5 +++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4777feb9..9bf37d39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/airbrake-ruby.rb b/lib/airbrake-ruby.rb index 5081ff7d..9884f40c 100644 --- a/lib/airbrake-ruby.rb +++ b/lib/airbrake-ruby.rb @@ -4,6 +4,7 @@ require 'thread' require 'set' require 'English' +require 'socket' require 'airbrake-ruby/version' require 'airbrake-ruby/config' diff --git a/lib/airbrake-ruby/notice.rb b/lib/airbrake-ruby/notice.rb index bf177546..c74a8146 100644 --- a/lib/airbrake-ruby/notice.rb +++ b/lib/airbrake-ruby/notice.rb @@ -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 @@ -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 diff --git a/spec/notice_spec.rb b/spec/notice_spec.rb index b847f94e..400880f9 100644 --- a/spec/notice_spec.rb +++ b/spec/notice_spec.rb @@ -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