From 2f73dc9742aeb38d1cc49818885c171dc937b775 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Sun, 1 Sep 2024 23:15:39 +0100 Subject: [PATCH 1/2] Simplify Attachment#infer_filename --- sentry-ruby/lib/sentry/attachment.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sentry-ruby/lib/sentry/attachment.rb b/sentry-ruby/lib/sentry/attachment.rb index 71a2b2b76..847d58c47 100644 --- a/sentry-ruby/lib/sentry/attachment.rb +++ b/sentry-ruby/lib/sentry/attachment.rb @@ -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 @@ -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 From abf48260276b59cc5b123638a1f5e4790dbc2913 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Sun, 1 Sep 2024 23:38:05 +0100 Subject: [PATCH 2/2] Small refactor on Profiler's frames collection --- sentry-ruby/lib/sentry/profiler.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sentry-ruby/lib/sentry/profiler.rb b/sentry-ruby/lib/sentry/profiler.rb index ee6590357..400cab5da 100644 --- a/sentry-ruby/lib/sentry/profiler.rb +++ b/sentry-ruby/lib/sentry/profiler.rb @@ -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]) @@ -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