Skip to content

Commit

Permalink
Change stackprof conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py committed Apr 12, 2023
1 parent 207fc04 commit d345a3a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 62 deletions.
2 changes: 1 addition & 1 deletion sentry-ruby/spec/sentry/profiler_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "spec_helper"

return unless defined?(Sentry::Profiler)
return unless defined?(StackProf)

RSpec.describe Sentry::Profiler do
before do
Expand Down
124 changes: 63 additions & 61 deletions sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -641,73 +641,75 @@ def will_be_sampled_by_sdk
end
end

describe "profiling" do
context "when profiling is enabled" do
before do
perform_basic_setup do |config|
config.traces_sample_rate = 1.0
config.profiles_sample_rate = 1.0
config.release = "test-release"
if defined?(StackProf)
describe "profiling" do
context "when profiling is enabled" do
before do
perform_basic_setup do |config|
config.traces_sample_rate = 1.0
config.profiles_sample_rate = 1.0
config.release = "test-release"
end
end
end

let(:stackprof_results) do
data = StackProf::Report.from_file('spec/support/stackprof_results.json').data
# relative dir differs on each machine
data[:frames].each { |_id, fra| fra[:file].gsub!(/<dir>/, Dir.pwd) }
data
end

before do
StackProf.stop
allow(StackProf).to receive(:results).and_return(stackprof_results)
end
let(:stackprof_results) do
data = StackProf::Report.from_file('spec/support/stackprof_results.json').data
# relative dir differs on each machine
data[:frames].each { |_id, fra| fra[:file].gsub!(/<dir>/, Dir.pwd) }
data
end

it "collects a profile" do
app = ->(_) do
[200, {}, "ok"]
before do
StackProf.stop
allow(StackProf).to receive(:results).and_return(stackprof_results)
end

stack = described_class.new(app)
stack.call(env)
event = last_sentry_event
it "collects a profile" do
app = ->(_) do
[200, {}, "ok"]
end

stack = described_class.new(app)
stack.call(env)
event = last_sentry_event

profile = event.profile
expect(profile).not_to be_nil

profile = event.profile
expect(profile).not_to be_nil

expect(profile[:event_id]).not_to be_nil
expect(event.contexts[:profile]).to eq({ profile_id: profile[:event_id] })

expect(profile[:platform]).to eq("ruby")
expect(profile[:version]).to eq("1")
expect(profile[:environment]).to eq("development")
expect(profile[:release]).to eq("test-release")
expect { Time.parse(profile[:timestamp]) }.not_to raise_error

expect(profile[:device]).to include(:architecture)
expect(profile[:os]).to include(:name, :version)
expect(profile[:runtime]).to include(:name, :version)

expect(profile[:transaction]).to include(:id, :name, :trace_id, :active_thead_id)
expect(profile[:transaction][:id]).to eq(event.event_id)
expect(profile[:transaction][:name]).to eq(event.transaction)
expect(profile[:transaction][:trace_id]).to eq(event.contexts[:trace][:trace_id])
expect(profile[:transaction][:active_thead_id]).to eq("0")

# detailed checking of content is done in profiler_spec,
# just check basic structure here
frames = profile[:profile][:frames]
expect(frames).to be_a(Array)
expect(frames.first).to include(:function, :filename, :abs_path, :in_app)

stacks = profile[:profile][:stacks]
expect(stacks).to be_a(Array)
expect(stacks.first).to be_a(Array)
expect(stacks.first.first).to be_a(Integer)

samples = profile[:profile][:samples]
expect(samples).to be_a(Array)
expect(samples.first).to include(:stack_id, :thread_id, :elapsed_since_start_ns)
expect(profile[:event_id]).not_to be_nil
expect(event.contexts[:profile]).to eq({ profile_id: profile[:event_id] })

expect(profile[:platform]).to eq("ruby")
expect(profile[:version]).to eq("1")
expect(profile[:environment]).to eq("development")
expect(profile[:release]).to eq("test-release")
expect { Time.parse(profile[:timestamp]) }.not_to raise_error

expect(profile[:device]).to include(:architecture)
expect(profile[:os]).to include(:name, :version)
expect(profile[:runtime]).to include(:name, :version)

expect(profile[:transaction]).to include(:id, :name, :trace_id, :active_thead_id)
expect(profile[:transaction][:id]).to eq(event.event_id)
expect(profile[:transaction][:name]).to eq(event.transaction)
expect(profile[:transaction][:trace_id]).to eq(event.contexts[:trace][:trace_id])
expect(profile[:transaction][:active_thead_id]).to eq("0")

# detailed checking of content is done in profiler_spec,
# just check basic structure here
frames = profile[:profile][:frames]
expect(frames).to be_a(Array)
expect(frames.first).to include(:function, :filename, :abs_path, :in_app)

stacks = profile[:profile][:stacks]
expect(stacks).to be_a(Array)
expect(stacks.first).to be_a(Array)
expect(stacks.first.first).to be_a(Integer)

samples = profile[:profile][:samples]
expect(samples).to be_a(Array)
expect(samples.first).to include(:stack_id, :thread_id, :elapsed_since_start_ns)
end
end
end
end
Expand Down

0 comments on commit d345a3a

Please sign in to comment.