Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't report middleware event for Rails #1124

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/appsignal/rack/abstract_middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ def call(env)
#
# @see {#instrument_app_call_with_exception_handling}
def instrument_app_call(env)
Appsignal.instrument(@instrument_span_name) do
if @instrument_span_name
Appsignal.instrument(@instrument_span_name) do
@app.call(env)
end
else
@app.call(env)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/appsignal/rack/rails_instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class RailsInstrumentation < Appsignal::Rack::AbstractMiddleware
def initialize(app, options = {})
options[:request_class] ||= ActionDispatch::Request
options[:params_method] ||= :filtered_parameters
options[:instrument_span_name] ||= "middleware.rails"
options[:instrument_span_name] = nil
options[:report_errors] = true
super
end
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/appsignal/rack/abstract_middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ def make_request_with_error(env, error_class, error_message)
)
end

context "when instrument_span_name option is nil" do
let(:options) { { :instrument_span_name => nil } }

it "does not report an event" do
make_request(env)

expect(last_transaction.to_h).to include(
"events" => []
)
end
end

it "completes the transaction" do
make_request(env)
expect(last_transaction).to be_completed
Expand Down
10 changes: 10 additions & 0 deletions spec/lib/appsignal/rack/rails_instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ def make_request_with_error(env, error_class, error_message)
expect { make_request(env) }.to raise_error(error_class, error_message)
end

context "with a request without an error" do
it "does not report an event" do
make_request(env)

expect(last_transaction.to_h).to include(
"events" => []
)
end
end

context "with a request that raises an error" do
let(:app) { lambda { |_env| raise ExampleException, "error message" } }

Expand Down