Commit 6ef6993760d493bac88b2de39ab24721f40e0485

Authored by Stephen Crosby
2 parents 13faed55 8b6cae2b
Exists in master

Merge pull request #1075 from aminin/patch-1

Get hostname from the hostname key
lib/airbrake_api/v3/notice_parser.rb
... ... @@ -84,7 +84,7 @@ module AirbrakeApi
84 84 end
85 85  
86 86 def hostname
87   - URI.parse(url).hostname
  87 + context['hostname'] || URI.parse(url).hostname
88 88 rescue URI::InvalidURIError
89 89 ''
90 90 end
... ...
spec/lib/airbrake_api/v3/notice_parser_spec.rb
... ... @@ -91,6 +91,14 @@ describe AirbrakeApi::V3::NoticeParser do
91 91 expect(parser.attributes[:notifier]).to eq(notifier_params)
92 92 end
93 93  
  94 + it 'takes the hostname from the context' do
  95 + parser = described_class.new(
  96 + 'errors' => ['MyError'],
  97 + 'context' => { 'hostname' => 'app01.infra.example.com', 'url' => 'http://example.com/some-page' },
  98 + 'environment' => {})
  99 + expect(parser.attributes[:server_environment]['hostname']).to eq('app01.infra.example.com')
  100 + end
  101 +
94 102 def build_params_for(fixture, options = {})
95 103 json = Rails.root.join('spec', 'fixtures', fixture).read
96 104 data = JSON.parse(json)
... ...