Skip to content

Commit

Permalink
rack/context: store versions in context/versions
Browse files Browse the repository at this point in the history
`context/versions` was introduced in airbrake-ruby v2.10.0:
https://github.com/airbrake/airbrake-ruby#versions
  • Loading branch information
kyrylo committed May 4, 2018
1 parent 08f104d commit 9007b9f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion airbrake.gemspec
Expand Up @@ -31,7 +31,7 @@ DESC

s.required_ruby_version = '>= 2.0'

s.add_dependency 'airbrake-ruby', '~> 2.5'
s.add_dependency 'airbrake-ruby', '~> 2.10'

s.add_development_dependency 'rspec', '~> 3'
s.add_development_dependency 'rspec-wait', '~> 0'
Expand Down
15 changes: 9 additions & 6 deletions lib/airbrake/rack/context_filter.rb
Expand Up @@ -10,11 +10,14 @@ class ContextFilter
def initialize
@framework_version =
if defined?(::Rails) && ::Rails.respond_to?(:version)
"Rails/#{::Rails.version}"
{ 'rails' => ::Rails.version }
elsif defined?(::Sinatra)
"Sinatra/#{Sinatra::VERSION}"
{ 'sinatra' => Sinatra::VERSION }
else
"Rack.version/#{::Rack.version} Rack.release/#{::Rack.release}"
{
'rack_version' => ::Rack.version,
'rack_release' => ::Rack.release
}
end.freeze
@weight = 99
end
Expand Down Expand Up @@ -44,10 +47,10 @@ def call(notice)
private

def add_framework_version(context)
if context.key?(:version)
context[:version] += " #{@framework_version}"
if context.key?(:versions)
context[:versions].merge!(@framework_version)
else
context[:version] = @framework_version
context[:versions] = @framework_version
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/rails/rails_spec.rb
Expand Up @@ -53,7 +53,7 @@
end

it "includes version" do
wait_for_a_request_with_body(/"context":{.*"version":"1.2.3 Rails/)
wait_for_a_request_with_body(/"context":{.*"versions":{"rails":"\d\./)
end

it "includes session" do
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/sinatra/sinatra_spec.rb
Expand Up @@ -15,7 +15,7 @@
describe "context payload" do
it "includes version" do
get '/crash'
wait_for_a_request_with_body(/"context":{.*"version":"1.2.3 Sinatra/)
wait_for_a_request_with_body(/"context":{.*"versions":{"sinatra":"\d\./)
end
end

Expand Down
6 changes: 4 additions & 2 deletions spec/unit/rack/context_filter_spec.rb
Expand Up @@ -18,8 +18,10 @@ def env_for(url, opts = {})

it "adds framework version to the context" do
subject.call(notice)
expect(notice[:context][:version]).
to match(/\d.\d.\d Rack\.version.+Rack\.release/)
expect(notice[:context][:versions]).to include(
'rack_version' => a_string_matching(/\d.\d/),
'rack_release' => a_string_matching(/\d.\d\.\d/)
)
end

context "when URL is present" do
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/rack/middleware_spec.rb
Expand Up @@ -76,7 +76,7 @@ def wait_for_a_request_with_body(body)
to raise_error(AirbrakeTestError)

wait_for_a_request_with_body(
%r("context":{.*"version":"1.2.3 (Rails|Sinatra|Rack\.version)/.+".+})
/"context":{.*"versions":{"(rails|sinatra|rack_version)"/
)
end
end
Expand Down

0 comments on commit 9007b9f

Please sign in to comment.