Skip to content

Commit

Permalink
Don't log warnings about missing deps when profiling is not enabled (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic authored Feb 5, 2025
1 parent 94d302a commit 40877c8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
- Fix regression with CheckInEvent in before_send ([#2541](https://github.com/getsentry/sentry-ruby/pull/2541))
- Fixes [#2540](https://github.com/getsentry/sentry-ruby/issues/2540)

### 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 sdk_meta
def utc_now
Time.now.utc
end

# @!visibility private
def dependency_installed?(name)
Object.const_defined?(name)
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

0 comments on commit 40877c8

Please sign in to comment.