Skip to content

Commit

Permalink
Add early-return so that Vernier::Profiler won't be defined if vernie…
Browse files Browse the repository at this point in the history
…r is not bundled
  • Loading branch information
solnic committed Sep 3, 2024
1 parent 8b82c49 commit 97e21ac
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion sentry-ruby/lib/sentry/vernier/profiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
begin
require "vernier"
rescue LoadError
return

Check warning on line 10 in sentry-ruby/lib/sentry/vernier/profiler.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/vernier/profiler.rb#L10

Added line #L10 was not covered by tests
end

module Sentry
Expand All @@ -22,7 +23,7 @@ def initialize(configuration)
@started = false
@sampled = nil

@profiling_enabled = defined?(Vernier) && configuration.profiling_enabled?
@profiling_enabled = configuration.profiling_enabled?
@profiles_sample_rate = configuration.profiles_sample_rate
@project_root = configuration.project_root
@app_dirs_pattern = configuration.app_dirs_pattern
Expand Down
9 changes: 6 additions & 3 deletions sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,13 @@ def will_be_sampled_by_sdk
expect(profile[:transaction][:trace_id]).to eq(event.contexts[:trace][:trace_id])

thread_id_mapping = {
Sentry::Profiler => "0",
Sentry::Vernier::Profiler => Thread.current.object_id.to_s
Sentry::Profiler => "0"
}

if defined?(Sentry::Vernier::Profiler)
thread_id_mapping[Sentry::Vernier::Profiler] = Thread.current.object_id.to_s
end

expect(profile[:transaction][:active_thread_id]).to eq(thread_id_mapping[Sentry.configuration.profiler_class])

# detailed checking of content is done in profiler_spec,
Expand All @@ -734,7 +737,7 @@ def will_be_sampled_by_sdk
let(:app) do
->(_) do
[200, {}, "ok"]
end
end
end

let(:stackprof_results) do
Expand Down
4 changes: 2 additions & 2 deletions sentry-ruby/spec/sentry/vernier/profiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

require "sentry/vernier/profiler"

RSpec.describe Sentry::Vernier::Profiler, when: { ruby_version?: [:>=, "3.2.1"] } do
subject(:profiler) { described_class.new(Sentry.configuration) }
RSpec.describe "Sentry::Vernier::Profiler", when: { ruby_version?: [:>=, "3.2.1"] } do
subject(:profiler) { Sentry::Vernier::Profiler.new(Sentry.configuration) }

before do
# TODO: replace with some public API once available
Expand Down

0 comments on commit 97e21ac

Please sign in to comment.