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 b22bd63
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 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
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
2 changes: 1 addition & 1 deletion sentry-ruby/spec/sentry/vernier/profiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "sentry/vernier/profiler"

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

before do
Expand Down

0 comments on commit b22bd63

Please sign in to comment.