Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental support for multi-threaded profiling using Vernier #2372

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

solnic
Copy link
Collaborator

@solnic solnic commented Aug 14, 2024

Experimental support for Vernier.

Screenshots

Screenshot 2024-08-21 at 13 41 53 Screenshot 2024-08-21 at 13 37 24 Screenshot 2024-08-21 at 13 38 07 Screenshot 2024-08-21 at 13 39 04 Screenshot 2024-08-21 at 13 39 34

@solnic solnic linked an issue Aug 14, 2024 that may be closed by this pull request
Copy link

codecov bot commented Aug 14, 2024

Codecov Report

Attention: Patch coverage is 99.25558% with 3 lines in your changes missing coverage. Please review.

Project coverage is 98.65%. Comparing base (04e030f) to head (282c3c2).

Files with missing lines Patch % Lines
sentry-ruby/spec/sentry/configuration_spec.rb 71.42% 2 Missing ⚠️
sentry-ruby/lib/sentry/configuration.rb 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2372      +/-   ##
==========================================
- Coverage   98.68%   98.65%   -0.03%     
==========================================
  Files         210      217       +7     
  Lines       13957    14307     +350     
==========================================
+ Hits        13773    14115     +342     
- Misses        184      192       +8     
Components Coverage Δ
sentry-ruby 99.01% <99.25%> (-0.05%) ⬇️
sentry-rails 97.34% <ø> (ø)
sentry-sidekiq 97.07% <ø> (ø)
sentry-resque 96.79% <ø> (ø)
sentry-delayed_job 98.92% <ø> (ø)
sentry-opentelemetry 100.00% <ø> (ø)
Files with missing lines Coverage Δ
sentry-ruby/lib/sentry-ruby.rb 96.72% <100.00%> (+0.01%) ⬆️
sentry-ruby/lib/sentry/profiler.rb 100.00% <100.00%> (+0.88%) ⬆️
sentry-ruby/lib/sentry/profiler/helpers.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/transaction.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/transaction_event.rb 100.00% <ø> (ø)
sentry-ruby/lib/sentry/vernier/output.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/vernier/profiler.rb 100.00% <100.00%> (ø)
sentry-ruby/spec/sentry/profiler_spec.rb 100.00% <100.00%> (ø)
...y-ruby/spec/sentry/rack/capture_exceptions_spec.rb 100.00% <100.00%> (ø)
sentry-ruby/spec/sentry/vernier/profiler_spec.rb 100.00% <100.00%> (ø)
... and 3 more

... and 2 files with indirect coverage changes

@solnic solnic force-pushed the solnic/2124-try-vernier-for-profiling branch 5 times, most recently from 3d995d8 to b45c7f3 Compare August 22, 2024 07:25
@solnic solnic changed the title Beginning of Vernier profiler Experimental support for multi-threaded profiling using Vernier Aug 22, 2024
@solnic solnic force-pushed the solnic/2124-try-vernier-for-profiling branch 5 times, most recently from 5220e97 to bd687cc Compare August 26, 2024 09:39
@solnic solnic marked this pull request as ready for review August 26, 2024 10:13
Copy link
Member

@sl0thentr0py sl0thentr0py left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amazing work @solnic
did a first pass, some questions and comments

will do a detailed test round later in the week

sentry-ruby/Gemfile Outdated Show resolved Hide resolved
sentry-ruby/lib/sentry/vernier/profiler.rb Outdated Show resolved Hide resolved
sentry-ruby/lib/sentry/vernier/profiler.rb Outdated Show resolved Hide resolved
sentry-ruby/lib/sentry/transaction_event.rb Outdated Show resolved Hide resolved
sentry-ruby/lib/sentry/vernier/output.rb Outdated Show resolved Hide resolved
sentry-ruby/lib/sentry/vernier/output.rb Outdated Show resolved Hide resolved
sentry-ruby/lib/sentry/profiler/helpers.rb Show resolved Hide resolved
sentry-ruby/lib/sentry/configuration.rb Outdated Show resolved Hide resolved
sentry-ruby/lib/sentry/vernier/output.rb Outdated Show resolved Hide resolved
sentry-ruby/lib/sentry/vernier/output.rb Outdated Show resolved Hide resolved
@started = false
@sampled = nil

@profiling_enabled = defined?(Vernier) && configuration.profiling_enabled?
Copy link
Collaborator

@st0012 st0012 Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for this part being loaded but Vernier is still not defined?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@st0012 yes, we rescue from LoadError if vernier is not bundled. It's the same with stackprof, its Profiler gets required even if stackprof is not available (see transaction.rb). I think we can make this whole conditional code loading better in the future and limit the amount of files that sentry requires. ie we can have some API for configuring features and then based on its configuration a smart code loader would know what to do.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can return in the rescue block then we won't need to call defined? at all. For example:

begin
  require "foo"
rescue LoadError
  return
end

Foo.bar

Copy link
Member

@sl0thentr0py sl0thentr0py Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry to come back to this, but can we keep both similar? Right now stackprof has one way and vernier has another.

@solnic solnic force-pushed the solnic/2124-try-vernier-for-profiling branch from 579dfef to babc6ed Compare August 31, 2024 08:37
@solnic
Copy link
Collaborator Author

solnic commented Aug 31, 2024

@sl0thentr0py @st0012 thanks for the comments! There are a couple of things that need be fixed. I'll ping you once it's done next week.

@solnic solnic force-pushed the solnic/2124-try-vernier-for-profiling branch from 6cc823c to 3a9367b Compare September 2, 2024 07:16
@solnic solnic force-pushed the solnic/2124-try-vernier-for-profiling branch from 4d2785b to dd7fdf9 Compare September 2, 2024 09:40
Copy link
Collaborator

@st0012 st0012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left another comment wrt the defined? check. But otherwise looks good to me 👍

@solnic solnic force-pushed the solnic/2124-try-vernier-for-profiling branch 5 times, most recently from b22bd63 to 97e21ac Compare September 3, 2024 09:09
@sl0thentr0py sl0thentr0py force-pushed the solnic/2124-try-vernier-for-profiling branch from 2f31b55 to 79c8e62 Compare September 20, 2024 11:50
@sl0thentr0py
Copy link
Member

sl0thentr0py commented Sep 20, 2024

@solnic we're not requiring the new sentry/vernier/profiler anywhere? We should not force end users to require another obscure path from within the gem, they should all be setup internally.

I would also prefer a warning message in Configuration when people try to set the profiler to vernier but vernier is not installed as a peer dependency gem.

@sl0thentr0py
Copy link
Member

I tried on a simple rails controller with some database calls and the profile is not sent due to being oversized.
However, the size limits for a profile payload are much larger (50MB) than for errors/transactions (1MB), so we need to add this logic in Envelope::Item.

@solnic solnic force-pushed the solnic/2124-try-vernier-for-profiling branch from 1b9f47a to 6ca6041 Compare September 20, 2024 16:49
@solnic
Copy link
Collaborator Author

solnic commented Sep 20, 2024

@solnic we're not requiring the new sentry/vernier/profiler anywhere? We should not force end users to require another obscure path from within the gem, they should all be setup internally.

I would also prefer a warning message in Configuration when people try to set the profiler to vernier but vernier is not installed as a peer dependency gem.

@sl0thentr0py OK I made it so that sentry/vernier/profiler is required automatically and if you try to set it in the config when vernier is not available, then you'll get a meaningful error message:

3.1.6 :002 > Sentry::Configuration.new.tap { |c| c.profiler_class = Sentry::Vernier::Profiler }
/workspaces/sentry/sentry-ruby/sentry-ruby/lib/sentry/configuration.rb:506:in `rescue in profiler_class=': Please add the 'vernier' gem to your Gemfile to use the Vernier profiler with Sentry. (ArgumentError)
        from /workspaces/sentry/sentry-ruby/sentry-ruby/lib/sentry/configuration.rb:503:in `profiler_class='
        from (irb):2:in `block in <top (required)>'
        from <internal:kernel>:90:in `tap'
        from (irb):2:in `<main>'

@solnic
Copy link
Collaborator Author

solnic commented Sep 20, 2024

I tried on a simple rails controller with some database calls and the profile is not sent due to being oversized.
However, the size limits for a profile payload are much larger (50MB) than for errors/transactions (1MB), so we need to add this logic in Envelope::Item.

@sl0thentr0py wdym by "this logic" exactly?

@solnic solnic force-pushed the solnic/2124-try-vernier-for-profiling branch from 6ca6041 to 3417545 Compare September 20, 2024 17:45
@solnic solnic force-pushed the solnic/2124-try-vernier-for-profiling branch from 3417545 to 282c3c2 Compare September 20, 2024 17:58
@sl0thentr0py
Copy link
Member

we need to generalize this logic to have different limits according to different envelope item.type but let's make a separate issue/PR for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Try vernier for profiling
3 participants