-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1489 from DataDog/fix/rails_controller_error_dete…
…ction Fix ActionPack instrumentation #starts_with? error
- Loading branch information
Showing
4 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
spec/ddtrace/contrib/action_pack/action_controller/instrumentation_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
require 'ddtrace/contrib/support/spec_helper' | ||
|
||
require 'action_controller' | ||
require 'ddtrace' | ||
|
||
# TODO: We plan on rewriting much of this instrumentation to bring it up to | ||
# present day patterns/conventions. For now, just test a few known cases. | ||
RSpec.describe Datadog::Contrib::ActionPack::ActionController::Instrumentation do | ||
describe '::finish_processing' do | ||
subject(:finish_processing) { described_class.finish_processing(payload) } | ||
|
||
context 'given a payload that been started' do | ||
before { described_class.start_processing(payload) } | ||
after { span.finish } | ||
|
||
let(:action_dispatch_exception) { nil } | ||
let(:action_name) { 'index' } | ||
let(:controller_class) { stub_const('TestController', Class.new(ActionController::Base)) } | ||
let(:env) { { 'rack.url_scheme' => 'http' } } | ||
let(:payload) do | ||
{ | ||
controller: controller_class, | ||
action: action_name, | ||
env: env, | ||
headers: { | ||
# The exception this controller was given in the request, | ||
# which is typical if the controller is configured to handle exceptions. | ||
request_exception: action_dispatch_exception | ||
}, | ||
tracing_context: {} | ||
} | ||
end | ||
|
||
let(:span) { payload[:tracing_context][:dd_request_span] } | ||
|
||
context 'with a 200 OK response' do | ||
before do | ||
expect(Datadog.logger).to_not receive(:error) | ||
finish_processing | ||
end | ||
|
||
describe 'the Datadog span' do | ||
it do | ||
expect(span).to_not have_error | ||
end | ||
end | ||
end | ||
|
||
context 'with a 500 Server Error response' do | ||
let(:error) do | ||
begin | ||
raise 'Test error' | ||
rescue StandardError => e | ||
e | ||
end | ||
end | ||
|
||
let(:payload) do | ||
super().merge( | ||
exception: [error.class.name, error.message], | ||
exception_object: error | ||
) | ||
end | ||
|
||
before do | ||
expect(Datadog.logger).to_not receive(:error) | ||
finish_processing | ||
end | ||
|
||
describe 'the Datadog span' do | ||
it do | ||
expect(span).to have_error | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |