Skip to content

Commit

Permalink
Minor refactors (#2392)
Browse files Browse the repository at this point in the history
* Simplify Attachment#infer_filename

* Small refactor on Profiler's frames collection
  • Loading branch information
st0012 authored Sep 2, 2024
1 parent 5980531 commit c3bcfa0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
6 changes: 2 additions & 4 deletions sentry-ruby/lib/sentry/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Attachment

def initialize(bytes: nil, filename: nil, content_type: nil, path: nil)
@bytes = bytes
@filename = infer_filename(filename, path)
@filename = filename || infer_filename(path)
@path = path
@content_type = content_type
end
Expand All @@ -29,9 +29,7 @@ def payload

private

def infer_filename(filename, path)
return filename if filename

def infer_filename(path)
if path
File.basename(path)
else
Expand Down
7 changes: 3 additions & 4 deletions sentry-ruby/lib/sentry/profiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,12 @@ def to_hash

frame_map = {}

frames = results[:frames].to_enum.with_index.map do |frame, idx|
frame_id, frame_data = frame

frames = results[:frames].map.with_index do |(frame_id, frame_data), idx|
# need to map over stackprof frame ids to ours
frame_map[frame_id] = idx

file_path = frame_data[:file]
lineno = frame_data[:line]
in_app = in_app?(file_path)
filename = compute_filename(file_path, in_app)
function, mod = split_module(frame_data[:name])
Expand All @@ -109,7 +108,7 @@ def to_hash
}

frame_hash[:module] = mod if mod
frame_hash[:lineno] = frame_data[:line] if frame_data[:line] && frame_data[:line] >= 0
frame_hash[:lineno] = lineno if lineno && lineno >= 0

frame_hash
end
Expand Down

0 comments on commit c3bcfa0

Please sign in to comment.