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 log warnings about missing deps when profiling is not enabled #2542

Merged
merged 2 commits into from
Feb 5, 2025
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
- Revert "[rails] support string errors in error reporter (#2464)" ([#2533](https://github.com/getsentry/sentry-ruby/pull/2533))
- Removed unnecessary warning about missing `stackprof` when Vernier is configured as the profiler ([#2537](https://github.com/getsentry/sentry-ruby/pull/2537))

### Internal

- Introduced `Configuration#validate` to validate configuration in `Sentry.init` block ([#2538](https://github.com/getsentry/sentry-ruby/pull/2538))
- Introduced `Sentry.dependency_installed?` to check if a 3rd party dependency is available ie `Sentry.dependency_installed?(:Vernier)` ([#2542](https://github.com/getsentry/sentry-ruby/pull/2542))

## 5.22.3

### Bug Fixes
Expand Down
5 changes: 5 additions & 0 deletions sentry-ruby/lib/sentry-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,11 @@
def utc_now
Time.now.utc
end

# @!visibility private
def dependency_installed?(name)
Object.const_defined?(name)

Check warning on line 615 in sentry-ruby/lib/sentry-ruby.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry-ruby.rb#L615

Added line #L615 was not covered by tests
end
end
end

Expand Down
4 changes: 2 additions & 2 deletions sentry-ruby/lib/sentry/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,11 @@ def initialize
end

def validate
if profiler_class == Sentry::Profiler && !defined?(StackProf)
if profiler_class == Sentry::Profiler && profiles_sample_rate && !Sentry.dependency_installed?(:StackProf)
log_warn("Please add the 'stackprof' gem to your Gemfile to use the StackProf profiler with Sentry.")
end

if profiler_class == Sentry::Vernier::Profiler && !defined?(Vernier)
if profiler_class == Sentry::Vernier::Profiler && profiles_sample_rate && !Sentry.dependency_installed?(:Vernier)
log_warn("Please add the 'vernier' gem to your Gemfile to use the Vernier profiler with Sentry.")
end

Expand Down
47 changes: 47 additions & 0 deletions sentry-ruby/spec/sentry/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -708,4 +708,51 @@ class SentryConfigurationSample < Sentry::Configuration
expect(subject.profiler_class).to eq(Sentry::Profiler)
end
end

describe "#validate" do
it "logs a warning if StackProf is not installed" do
allow(Sentry).to receive(:dependency_installed?).with(:StackProf).and_return(false)

expect {
Sentry.init do |config|
config.logger = Logger.new($stdout)
config.profiles_sample_rate = 1.0
end
}.to output(/Please add the 'stackprof' gem to your Gemfile/).to_stdout
end

it "doesn't log a warning when StackProf is not installed and profiles_sample_rate is not set" do
allow(Sentry).to receive(:dependency_installed?).with(:StackProf).and_return(false)

expect {
Sentry.init do |config|
config.logger = Logger.new($stdout)
config.profiles_sample_rate = nil
end
}.to_not output(/Please add the 'stackprof' gem to your Gemfile/).to_stdout
end

it "logs a warning if Vernier is not installed" do
allow(Sentry).to receive(:dependency_installed?).with(:Vernier).and_return(false)

expect {
Sentry.init do |config|
config.logger = Logger.new($stdout)
config.profiler_class = Sentry::Vernier::Profiler
config.profiles_sample_rate = 1.0
end
}.to output(/Please add the 'vernier' gem to your Gemfile/).to_stdout
end

it "doesn't log a warning when Vernier is not installed and profiles_sample_rate is not set" do
allow(Sentry).to receive(:dependency_installed?).with(:Vernier).and_return(false)

expect {
Sentry.init do |config|
config.logger = Logger.new($stdout)
config.profiles_sample_rate = nil
end
}.to_not output(/Please add the 'vernier' gem to your Gemfile/).to_stdout
end
end
end
Loading