File tree Expand file tree Collapse file tree 3 files changed +76
-0
lines changed
Expand file tree Collapse file tree 3 files changed +76
-0
lines changed Original file line number Diff line number Diff line change 2929gem "rails" , "> 5.0.0"
3030
3131gem "timecop"
32+
33+ if RUBY_VERSION >= "3.2.1"
34+ gem "vernier"
35+ end
Original file line number Diff line number Diff line change @@ -340,4 +340,42 @@ def retry_last_failed_job
340340 )
341341 end
342342 end
343+
344+ context "when profiling is enabled with Vernier" , skip : RUBY_VERSION < "3.2.1" do
345+ before do
346+ perform_basic_setup do |config |
347+ config . traces_sample_rate = 1.0
348+ config . profiles_sample_rate = 1.0
349+ config . profiler_class = Sentry ::Vernier ::Profiler
350+ config . release = "test-release"
351+ end
352+ end
353+
354+ it "captures meaningful profile data from worker with workload" do
355+ execute_worker ( processor , WorkloadWorker )
356+
357+ expect ( transport . events . count ) . to eq ( 1 )
358+ event = transport . events . first
359+
360+ expect ( event ) . to be_a ( Sentry ::TransactionEvent )
361+ profile = event . profile
362+
363+ expect ( profile ) . not_to be_nil
364+ expect ( profile [ :event_id ] ) . not_to be_nil
365+ expect ( profile [ :platform ] ) . to eq ( "ruby" )
366+ expect ( profile [ :version ] ) . to eq ( "1" )
367+ expect ( profile [ :release ] ) . to eq ( "test-release" )
368+
369+ expect ( profile [ :profile ] ) . to include (
370+ :frames ,
371+ :stacks ,
372+ :samples ,
373+ :thread_metadata
374+ )
375+
376+ expect ( profile [ :profile ] [ :samples ] . length ) . to be > 0
377+ expect ( profile [ :profile ] [ :frames ] . length ) . to be > 0
378+ expect ( profile [ :profile ] [ :stacks ] . length ) . to be > 0
379+ end
380+ end
343381end
Original file line number Diff line number Diff line change @@ -195,6 +195,39 @@ class TagsWorker
195195 def perform ; end
196196end
197197
198+ class WorkloadWorker
199+ include Sidekiq ::Worker
200+
201+ def perform
202+ # Create some CPU work that should show up in the profile
203+ calculate_fibonacci ( 25 )
204+ sleep_and_sort
205+ generate_strings
206+ end
207+
208+ private
209+
210+ def calculate_fibonacci ( n )
211+ return n if n <= 1
212+ calculate_fibonacci ( n - 1 ) + calculate_fibonacci ( n - 2 )
213+ end
214+
215+ def sleep_and_sort
216+ # Mix of CPU and IO work
217+ sleep ( 0.01 )
218+ array = ( 1 ..1000 ) . to_a . shuffle
219+ array . sort
220+ end
221+
222+ def generate_strings
223+ # Memory and CPU work
224+ 100 . times do |i |
225+ "test string #{ i } " * 100
226+ Math . sqrt ( i * 1000 )
227+ end
228+ end
229+ end
230+
198231def new_processor
199232 manager =
200233 case
@@ -273,3 +306,4 @@ def perform_basic_setup
273306 yield config if block_given?
274307 end
275308end
309+
You can’t perform that action at this time.
0 commit comments