Skip to content

Commit

Permalink
Merge branch '4-2' into add-ability-to-have-many-post-initialization-…
Browse files Browse the repository at this point in the history
…callbacks
  • Loading branch information
mrexox authored Feb 2, 2021
2 parents 8c2ec4e + 58acd35 commit 1c38359
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 7 deletions.
3 changes: 2 additions & 1 deletion sentry-rails/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
- Allow users to configure ActiveJob adapters to ignore [#1256](https://github.com/getsentry/sentry-ruby/pull/1256)
- Tag `job_id` and `provider_job_id` on ActiveJob events [#1259](https://github.com/getsentry/sentry-ruby/pull/1259)

## Unreleased
## 4.1.7

- Use env to carry original transaction name [#1255](https://github.com/getsentry/sentry-ruby/pull/1255)
- Fix duration of tracing event in Rails 5 [#1254](https://github.com/getsentry/sentry-ruby/pull/1254) (by @abcang)
- Filter out static file transaction [#1247](https://github.com/getsentry/sentry-ruby/pull/1247)

## 4.1.6

Expand Down
1 change: 1 addition & 0 deletions sentry-rails/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gem "jdbc-sqlite3", platform: :jruby
gem "sqlite3", platform: :ruby

gem "rails", "~> #{rails_version}"
gem "sprockets-rails"
gem "rspec-rails", "~> 4.0"
gem "codecov", "0.2.12"

Expand Down
15 changes: 15 additions & 0 deletions sentry-rails/lib/sentry/rails/capture_exceptions.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
module Sentry
module Rails
class CaptureExceptions < Sentry::Rack::CaptureExceptions
def initialize(app)
super

if defined?(::Sprockets::Rails)
@assets_regex = %r(\A/{0,2}#{::Rails.application.config.assets.prefix})
end
end

private

def collect_exception(env)
Expand All @@ -20,6 +28,13 @@ def capture_exception(exception)

Sentry::Rails.capture_exception(exception)
end

def finish_span(span, status_code)
if @assets_regex.nil? || !span.name.match?(@assets_regex)
span.set_http_status(status_code)
span.finish
end
end
end
end
end
16 changes: 16 additions & 0 deletions sentry-rails/lib/sentry/rails/overrides/file_handler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Sentry
module Rails
module Overrides
module FileHandler
def serve(*args)
if Sentry.initialized? && current_transaction = Sentry.get_current_scope.span
# we don't want to expose a setter for @sampled just for this case
current_transaction.instance_variable_set(:@sampled, false)
end

super
end
end
end
end
end
10 changes: 9 additions & 1 deletion sentry-rails/lib/sentry/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require "sentry/rails/controller_methods"
require "sentry/rails/controller_transaction"
require "sentry/rails/overrides/streaming_reporter"
require "sentry/rails/overrides/file_handler"

module Sentry
class Railtie < ::Rails::Railtie
Expand All @@ -16,7 +17,7 @@ class Railtie < ::Rails::Railtie
app.config.middleware.use(Sentry::Rails::RescuedExceptionInterceptor)
end

config.after_initialize do
config.after_initialize do |app|
next unless Sentry.initialized?

configure_project_root
Expand All @@ -25,6 +26,7 @@ class Railtie < ::Rails::Railtie
extend_controller_methods
extend_active_job if defined?(ActiveJob)
override_streaming_reporter
override_file_handler if app.config.public_file_server.enabled
setup_backtrace_cleanup_callback
inject_breadcrumbs_logger
activate_tracing
Expand Down Expand Up @@ -76,6 +78,12 @@ def override_streaming_reporter
end
end

def override_file_handler
ActiveSupport.on_load :action_controller do
ActionDispatch::FileHandler.send(:prepend, Sentry::Rails::Overrides::FileHandler)
end
end

def activate_tracing
if Sentry.configuration.tracing_enabled?
Sentry::Rails::Tracing.subscribe_tracing_events
Expand Down
41 changes: 36 additions & 5 deletions sentry-rails/spec/sentry/rails/tracing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

after do
transport.events = []

described_class.unsubscribe_tracing_events
described_class.remove_active_support_notifications_patch
end

context "with traces_sample_rate set" do
Expand All @@ -22,11 +25,6 @@
end
end

after do
described_class.unsubscribe_tracing_events
described_class.remove_active_support_notifications_patch
end

it "records transaction with exception" do
get "/posts"

Expand Down Expand Up @@ -83,7 +81,40 @@
expect(second_span[:op]).to eq("process_action.action_controller")
expect(second_span[:description]).to eq("PostsController#show")
expect(second_span[:parent_span_id]).to eq(parent_span_id)
end
end

context "with sprockets-rails" do
before do
require "sprockets/railtie"

make_basic_app do |config, app|
app.config.public_file_server.enabled = true
config.traces_sample_rate = 1.0
end
end

it "doesn't record requests for asset files" do
get "/assets/application-ad022df6f1289ec07a560bb6c9a227ecf7bdd5a5cace5e9a8cdbd50b454931fb.css"

expect(response).to have_http_status(:not_found)
expect(transport.events).to be_empty
end
end

context "with config.public_file_server.enabled = true" do
before do
make_basic_app do |config, app|
app.config.public_file_server.enabled = true
config.traces_sample_rate = 1.0
end
end

it "doesn't record requests for static files" do
get "/static.html"

expect(response).to have_http_status(:ok)
expect(transport.events).to be_empty
end

it "doesn't get messed up by previous exception" do
Expand Down
Empty file.
Empty file.
Empty file.

0 comments on commit 1c38359

Please sign in to comment.