Skip to content

Commit

Permalink
Merge branch 'master' into solnic/2124-try-vernier-for-profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Aug 22, 2024
2 parents 03aa6a5 + 6181b7b commit 3d995d8
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/sentry_rails_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ jobs:
- { ruby_version: "2.7", rails_version: 5.2.0 }
- { ruby_version: "2.7", rails_version: 6.0.0 }
- { ruby_version: "2.7", rails_version: 6.1.0 }
- { ruby_version: "3.1", rails_version: 7.2.0 }
- { ruby_version: "3.2", rails_version: 7.2.0 }
- { ruby_version: "3.3", rails_version: 7.2.0 }
- { ruby_version: "jruby", rails_version: 6.1.0 }
- {
ruby_version: "3.2",
Expand Down
34 changes: 18 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased

- Experimental support for multi-threaded debugging using Vernier ([#2372](https://github.com/getsentry/sentry-ruby/pull/2372))
- Add support for $SENTRY_DEBUG and $SENTRY_SPOTLIGHT ([#2374](https://github.com/getsentry/sentry-ruby/pull/2374))

## 5.19.0

Expand All @@ -10,7 +11,7 @@

- Support for tracing Faraday requests ([#2345](https://github.com/getsentry/sentry-ruby/pull/2345))
- Closes [#1795](https://github.com/getsentry/sentry-ruby/issues/1795)
- Please note that the Faraday instrumentation has some limitations in case of async requests: https://github.com/lostisland/faraday/issues/1381
- Please note that the Faraday instrumentation has some limitations in case of async requests: <https://github.com/lostisland/faraday/issues/1381>

Usage:

Expand All @@ -36,6 +37,7 @@
- Inject Sentry meta tags in the Rails application layout automatically in the generator ([#2369](https://github.com/getsentry/sentry-ruby/pull/2369))

To turn this behavior off, use

```bash
bin/rails generate sentry --inject-meta false
```
Expand Down Expand Up @@ -260,6 +262,7 @@
config.cron.default_timezone = 'America/New_York'
end
```
- Clean up logging [#2216](https://github.com/getsentry/sentry-ruby/pull/2216)
- Pick up config.cron.default_timezone from Rails config [#2213](https://github.com/getsentry/sentry-ruby/pull/2213)
- Don't add most scope data (tags/extra/breadcrumbs) to `CheckInEvent` [#2217](https://github.com/getsentry/sentry-ruby/pull/2217)
Expand Down Expand Up @@ -307,6 +310,7 @@
```rb
config.enabled_patches += [:sidekiq_cron]
```

- Add support for [`sidekiq-scheduler`](https://github.com/sidekiq-scheduler/sidekiq-scheduler) [#2172](https://github.com/getsentry/sentry-ruby/pull/2172)

You can opt in to the `sidekiq-scheduler` patch and we will automatically monitor check-ins for all repeating jobs (i.e. `cron`, `every`, and `interval`) specified in the config.
Expand Down Expand Up @@ -335,6 +339,7 @@
config.rails.active_support_logger_subscription_items.delete("sql.active_record")
config.rails.active_support_logger_subscription_items["foo"] = :bar
```

- Enable opting out of patches [#2151](https://github.com/getsentry/sentry-ruby/pull/2151)

### Bug Fixes
Expand Down Expand Up @@ -362,6 +367,7 @@
# do job stuff
Sentry.capture_check_in('job_name', :ok, check_in_id: check_in_id)
```

- Add `Sentry::Cron::MonitorCheckIns` module for automatic monitoring of jobs [#2130](https://github.com/getsentry/sentry-ruby/pull/2130)

Standard job frameworks such as `ActiveJob` and `Sidekiq` can now use this module to automatically capture check ins.
Expand Down Expand Up @@ -392,6 +398,7 @@
```

You can pass in optional attributes to `sentry_monitor_check_ins` as follows.

```rb
# slug defaults to the job class name
sentry_monitor_check_ins slug: 'custom_slug'
Expand Down Expand Up @@ -431,6 +438,7 @@
config.trace_propagation_targets = [/.*/] # default is to all targets
config.trace_propagation_targets = [/example.com/, 'foobar.org/api/v2']
```
- Tracing without Performance
- Implement `PropagationContext` on `Scope` and add `Sentry.get_trace_propagation_headers` API [#2084](https://github.com/getsentry/sentry-ruby/pull/2084)
- Implement `Sentry.continue_trace` API [#2089](https://github.com/getsentry/sentry-ruby/pull/2089)
Expand Down Expand Up @@ -470,7 +478,6 @@
- Use allowlist to filter `ActiveSupport` breadcrumbs' data [#2048](https://github.com/getsentry/sentry-ruby/pull/2048)
- ErrorHandler should cleanup the scope ([#2059](https://github.com/getsentry/sentry-ruby/pull/2059))
## 5.9.0
### Features
Expand All @@ -488,6 +495,7 @@
Sentry.capture_exception(ignored_exception) # won't be sent to Sentry
Sentry.capture_exception(ignored_exception, hint: { ignore_exclusions: true }) # will be sent to Sentry
```

- Support capturing low-level errors propagated to Puma [#2026](https://github.com/getsentry/sentry-ruby/pull/2026)

- Add `spec` to `Backtrace::APP_DIRS_PATTERN` [#2029](https://github.com/getsentry/sentry-ruby/pull/2029)
Expand Down Expand Up @@ -526,7 +534,7 @@

> **Warning**
> Profiling is currently in beta. Beta features are still in-progress and may have bugs. We recognize the irony.
> If you have any questions or feedback, please email us at profiling@sentry.io, reach out via Discord (#profiling), or open an issue.
> If you have any questions or feedback, please email us at <profiling@sentry.io>, reach out via Discord (#profiling), or open an issue.

### Bug Fixes

Expand Down Expand Up @@ -621,19 +629,19 @@
```

- Use `Sentry.with_child_span` in redis and net/http instead of `span.start_child` [#1920](https://github.com/getsentry/sentry-ruby/pull/1920)
- This might change the nesting of some spans and make it more accurate
- Followup fix to set the sentry-trace header in the correct place [#1922](https://github.com/getsentry/sentry-ruby/pull/1922)
- This might change the nesting of some spans and make it more accurate
- Followup fix to set the sentry-trace header in the correct place [#1922](https://github.com/getsentry/sentry-ruby/pull/1922)

- Use `Exception#detailed_message` when generating exception message if applicable [#1924](https://github.com/getsentry/sentry-ruby/pull/1924)
- Make `sentry-sidekiq` compatible with Sidekiq 7 [#1930](https://github.com/getsentry/sentry-ruby/pull/1930)

### Bug Fixes

- `Sentry::BackgroundWorker` will release `ActiveRecord` connection pool only when the `ActiveRecord` connection is established
- Remove bad encoding arguments in redis span descriptions [#1914](https://github.com/getsentry/sentry-ruby/pull/1914)
- Fixes [#1911](https://github.com/getsentry/sentry-ruby/issues/1911)
- Remove bad encoding arguments in redis span descriptions [#1914](https://github.com/getsentry/sentry-ruby/pull/1914)
- Fixes [#1911](https://github.com/getsentry/sentry-ruby/issues/1911)
- Add missing `initialized?` checks to `sentry-rails` [#1919](https://github.com/getsentry/sentry-ruby/pull/1919)
- Fixes [#1885](https://github.com/getsentry/sentry-ruby/issues/1885)
- Fixes [#1885](https://github.com/getsentry/sentry-ruby/issues/1885)
- Update Tracing Span's op names [#1923](https://github.com/getsentry/sentry-ruby/pull/1923)
Currently, Ruby integrations' Span op names aren't aligned with the core specification's convention, so we decided to update them altogether in this PR.
Expand Down Expand Up @@ -710,6 +718,7 @@
1/0 #=> ZeroDivisionError will be reported and re-raised
end
```
- Prepare for Rails 7.1's error reporter API change [#1834](https://github.com/getsentry/sentry-ruby/pull/1834)
- Set `sentry.error_event_id` in request env if the middleware captures errors [#1849](https://github.com/getsentry/sentry-ruby/pull/1849)

Expand Down Expand Up @@ -862,7 +871,6 @@ end

This will help users report size-related issues in the future.


- Automatic session tracking [#1715](https://github.com/getsentry/sentry-ruby/pull/1715)

**Example**:
Expand All @@ -881,7 +889,6 @@ end
To disable this feature, set `config.auto_session_tracking` to `false`.
### Bug Fixes
- Require set library [#1753](https://github.com/getsentry/sentry-ruby/pull/1753)
Expand All @@ -896,7 +903,6 @@ end
- Avoid duplicated capturing on the same exception object [#1738](https://github.com/getsentry/sentry-ruby/pull/1738)
- Fixes [#1731](https://github.com/getsentry/sentry-ruby/issues/1731)
### Refactoring
- Encapsulate extension helpers [#1725](https://github.com/getsentry/sentry-ruby/pull/1725)
Expand Down Expand Up @@ -961,7 +967,6 @@ end

This version removes the dependency of [faraday](https://github.com/lostisland/faraday) and replaces related implementation with the `Net::HTTP` standard library.


#### Why?

Since the old `sentry-raven` SDK, we've been using `faraday` as the HTTP client for years (see [HTTPTransport](https://github.com/getsentry/sentry-ruby/blob/4-9/sentry-ruby/lib/sentry/transport/http_transport.rb)). It's an amazing tool that saved us many work and allowed us to focus on SDK features.
Expand All @@ -976,10 +981,8 @@ And with the release of [faraday 2.0](https://github.com/lostisland/faraday/rele

So we think it's time to say goodbye to it with this release.
#### What's changed?


By default, the SDK used `faraday`'s `net_http` adapter, which is also built on top of `Net::HTTP`. So this change shouldn't impact most of the users.

The only noticeable changes are the removal of 2 faraday-specific transport configurations:
Expand Down Expand Up @@ -1080,7 +1083,6 @@ end
2. Set `config.transport.transport = FaradayTransport`
**Please keep in mind that this may not work in the future when the SDK changes its `HTTPTransport` implementation.**
## 4.9.2
Expand Down Expand Up @@ -1220,7 +1222,6 @@ When `config.send_default_pii` is set as `true`, `:http_logger` will include que
- Start Testing Against Rails 7.0 [#1581](https://github.com/getsentry/sentry-ruby/pull/1581)
## 4.7.3
- Avoid leaking tracing timestamp to breadcrumbs [#1575](https://github.com/getsentry/sentry-ruby/pull/1575)
Expand All @@ -1239,6 +1240,7 @@ When `config.send_default_pii` is set as `true`, `:http_logger` will include que
## 4.7.1

### Bug Fixes

- Send events when report_after_job_retries is true and a job is configured with retry: 0 [#1557](https://github.com/getsentry/sentry-ruby/pull/1557)
- Fixes [#1556](https://github.com/getsentry/sentry-ruby/issues/1556)

Expand Down
6 changes: 4 additions & 2 deletions sentry-rails/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ else
end
end

if rails_version >= Gem::Version.new("7.2.0.alpha")
if rails_version >= Gem::Version.new("8.0.0.alpha")
gem "rails", github: "rails/rails"
gem "rspec-rails"
elsif rails_version >= Gem::Version.new("7.1.0")
gem "rails", "~> #{rails_version}"
gem "rspec-rails"
else
gem "rspec-rails", "~> 4.0"
gem "rails", "~> #{rails_version}"
gem "psych", "~> 3.0.0"
end
Expand All @@ -39,7 +42,6 @@ gem "sprockets-rails"

gem "sidekiq"

gem "rspec-rails", "~> 4.0"

ruby_version = Gem::Version.new(RUBY_VERSION)

Expand Down
9 changes: 8 additions & 1 deletion sentry-rails/spec/dummy/test_rails_app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

require 'sentry/rails'

ActiveSupport::Deprecation.silenced = true
ActiveRecord::Base.logger = Logger.new(nil)
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: "db")

Expand Down Expand Up @@ -50,13 +49,21 @@ def self.name
end
end

app.config.active_support.deprecation = :silence
app.config.action_controller.view_paths = "spec/dummy/test_rails_app"
app.config.hosts = nil
app.config.secret_key_base = "test"
app.config.logger = ActiveSupport::Logger.new(nil)
app.config.eager_load = true
app.config.active_job.queue_adapter = :test

# Eager load namespaces can be accumulated after repeated initializations and make initialization
# slower after each run
# This is especially obvious in Rails 7.2, because of https://github.com/rails/rails/pull/49987, but other constants's
# accumulation can also cause slowdown
# Because this is not necessary for the test, we can simply clear it here
app.config.eager_load_namespaces.clear

configure_app(app)

app.routes.append do
Expand Down
2 changes: 2 additions & 0 deletions sentry-rails/spec/isolated/active_job_activation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# for https://github.com/getsentry/sentry-ruby/issues/1249
require "active_job/railtie"
# Rails 7.2 added HealthCheckController, which requires ActionController
require "action_controller/railtie"
require "active_support/all"
require "sentry/rails"
require "minitest/autorun"
Expand Down
8 changes: 7 additions & 1 deletion sentry-rails/spec/sentry/generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
require "rails/generators/test_case"
require "generators/sentry_generator"

behavior_module = if defined?(Rails::Generators::Testing::Behaviour)
Rails::Generators::Testing::Behaviour
else
Rails::Generators::Testing::Behavior
end

RSpec.describe SentryGenerator do
include ::Rails::Generators::Testing::Behaviour
include behavior_module
include FileUtils
self.destination File.expand_path('../../tmp', __dir__)
self.generator_class = described_class
Expand Down
14 changes: 11 additions & 3 deletions sentry-rails/spec/sentry/rails/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
Sentry.get_current_client.transport
end

let(:expected_initial_active_record_connections_count) do
if Gem::Version.new(Rails.version) < Gem::Version.new('7.2.0')
1
else
0
end
end

before do
expect(ActiveRecord::Base.connection_pool.stat[:busy]).to eq(1)
expect(ActiveRecord::Base.connection_pool.stat[:busy]).to eq(expected_initial_active_record_connections_count)
end

def send_events
Expand Down Expand Up @@ -35,7 +43,7 @@ def send_events

expect(transport.events.count).to eq(5)

expect(ActiveRecord::Base.connection_pool.stat[:busy]).to eq(1)
expect(ActiveRecord::Base.connection_pool.stat[:busy]).to eq(expected_initial_active_record_connections_count)
end
end

Expand All @@ -53,7 +61,7 @@ def send_events

expect(transport.events.count).to eq(5)

expect(ActiveRecord::Base.connection_pool.stat[:busy]).to eq(1)
expect(ActiveRecord::Base.connection_pool.stat[:busy]).to eq(expected_initial_active_record_connections_count)
end
end
end
12 changes: 8 additions & 4 deletions sentry-ruby/lib/sentry/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
require "concurrent/utility/processor_counter"

require "sentry/utils/exception_cause_chain"
require "sentry/utils/custom_inspection"
require 'sentry/utils/custom_inspection'
require 'sentry/utils/env_helper'
require "sentry/dsn"
require "sentry/release_detector"
require "sentry/transport/configuration"
Expand Down Expand Up @@ -354,7 +355,7 @@ def add_post_initialization_callback(&block)

def initialize
self.app_dirs_pattern = nil
self.debug = false
self.debug = Sentry::Utils::EnvHelper.env_to_bool(ENV["SENTRY_DEBUG"])
self.background_worker_threads = (processor_count / 2.0).ceil
self.background_worker_max_queue = BackgroundWorker::DEFAULT_MAX_QUEUE
self.backtrace_cleanup_callback = nil
Expand All @@ -380,8 +381,11 @@ def initialize
self.auto_session_tracking = true
self.enable_backpressure_handling = false
self.trusted_proxies = []
self.dsn = ENV["SENTRY_DSN"]
self.spotlight = false
self.dsn = ENV['SENTRY_DSN']

spotlight_env = ENV['SENTRY_SPOTLIGHT']
spotlight_bool = Sentry::Utils::EnvHelper.env_to_bool(spotlight_env, strict: true)
self.spotlight = spotlight_bool.nil? ? (spotlight_env || false) : spotlight_bool
self.server_name = server_name_from_env
self.instrumenter = :sentry
self.trace_propagation_targets = [PROPAGATION_TARGETS_MATCH_ALL]
Expand Down
21 changes: 21 additions & 0 deletions sentry-ruby/lib/sentry/utils/env_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Sentry
module Utils
module EnvHelper
TRUTHY_ENV_VALUES = %w[t true yes y 1 on].freeze
FALSY_ENV_VALUES = %w[f false no n 0 off].freeze

def self.env_to_bool(value, strict: false)
value = value.to_s
normalized = value.downcase

return false if FALSY_ENV_VALUES.include?(normalized)

return true if TRUTHY_ENV_VALUES.include?(normalized)

strict ? nil : !(value.nil? || value.empty?)
end
end
end
end
Loading

0 comments on commit 3d995d8

Please sign in to comment.