Skip to content

Commit cfd931e

Browse files
committed
Stub stackprof for rack as well, since results is unreliable
1 parent 7c7139c commit cfd931e

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

sentry-ruby/lib/sentry/profiler.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class StackProfProfiler < NoopProfiler
2525
DEFAULT_INTERVAL = 1e6 / 101
2626
MICRO_TO_NANO_SECONDS = 1e3
2727

28-
attr_reader :sampled, :started, :event_id
28+
attr_reader :sampled, :started, :event_id, :results
2929

3030
def initialize(configuration)
3131
@event_id = SecureRandom.uuid.delete('-')
@@ -96,6 +96,7 @@ def to_hash
9696
return {} unless @started
9797

9898
results = StackProf.results
99+
@results = results
99100
return {} unless results
100101
return {} if results.empty?
101102
return {} if results[:samples] == 0

sentry-ruby/lib/sentry/transaction_event.rb

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class TransactionEvent < Event
2020
# @return [Hash, nil]
2121
attr_accessor :profile
2222

23+
attr_reader :profiler
24+
2325
def initialize(transaction:, **options)
2426
super(**options)
2527

@@ -36,6 +38,7 @@ def initialize(transaction:, **options)
3638
finished_spans = transaction.span_recorder.spans.select { |span| span.timestamp && span != transaction }
3739
self.spans = finished_spans.map(&:to_hash)
3840

41+
@profiler = transaction.profiler
3942
populate_profile(transaction)
4043
end
4144

sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb

+13-8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22

33
require 'spec_helper'
44

5-
module TestApp
6-
def self.foo
7-
sleep 0.1
8-
"ok"
9-
end
10-
end
11-
125
RSpec.describe Sentry::Rack::CaptureExceptions, rack: true do
136
let(:exception) { ZeroDivisionError.new("divided by 0") }
147
let(:additional_headers) { {} }
@@ -658,16 +651,28 @@ def will_be_sampled_by_sdk
658651
end
659652
end
660653

654+
let(:stackprof_results) do
655+
data = StackProf::Report.from_file('spec/support/stackprof_results.json').data
656+
# relative dir differs on each machine
657+
data[:frames].each { |_id, fra| fra[:file].gsub!(/<dir>/, Dir.pwd) }
658+
data
659+
end
660+
661+
before do
662+
allow(StackProf).to receive(:results).and_return(stackprof_results)
663+
end
664+
661665
it "collects a profile" do
662666
app = ->(_) do
663-
[200, {}, [TestApp.foo]]
667+
[200, {}, "ok"]
664668
end
665669

666670
stack = described_class.new(app)
667671
stack.call(env)
668672
event = last_sentry_event
669673

670674
profile = event.profile
675+
puts(event.profiler.inspect)
671676
expect(profile).not_to be_nil
672677

673678
expect(profile[:event_id]).not_to be_nil

0 commit comments

Comments
 (0)