-
-
Notifications
You must be signed in to change notification settings - Fork 533
Prevent starting Vernier in nested transactions #2528
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,7 +85,11 @@ def initialize( | |
| @effective_sample_rate = nil | ||
| @contexts = {} | ||
| @measurements = {} | ||
| @profiler = @configuration.profiler_class.new(@configuration) | ||
|
|
||
| unless @hub.profiler_running? | ||
| @profiler = @configuration.profiler_class.new(@configuration) | ||
| end | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This thing right here is the heart of the fix, if I remove this conditional the spec I added easily reproduces the crash from the issue: |
||
|
|
||
| init_span_recorder | ||
| end | ||
|
|
||
|
|
@@ -257,7 +261,7 @@ def finish(hub: nil, end_timestamp: nil) | |
| @name = UNLABELD_NAME | ||
| end | ||
|
|
||
| @profiler.stop | ||
| @hub.stop_profiler!(self) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that the hub is responsible for starting a profiler, making this change actually felt like an improvement. Transactions are coupled to hub anyway. |
||
|
|
||
| if @sampled | ||
| event = hub.current_client.event_from_transaction(self) | ||
|
|
@@ -299,6 +303,8 @@ def set_context(key, value) | |
| # Start the profiler. | ||
| # @return [void] | ||
| def start_profiler! | ||
| return unless profiler | ||
|
|
||
| profiler.set_initial_sample_decision(sampled) | ||
| profiler.start | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "spec_helper" | ||
| require 'contexts/with_request_mock' | ||
|
|
||
| RSpec.describe Sentry, 'transactions / profiler', when: [:vernier_installed?, :rack_available?] do | ||
| include_context "with request mock" | ||
|
|
||
| before do | ||
| perform_basic_setup do |config| | ||
| config.traces_sample_rate = 1.0 | ||
| config.profiles_sample_rate = 1.0 | ||
| config.profiler_class = Sentry::Vernier::Profiler | ||
| end | ||
| end | ||
|
|
||
| it 'starts profiler just once inside nested transactions' do | ||
| 10.times do | ||
| parent_transaction = Sentry.start_transaction(name: "parent") | ||
| nested_transaction = Sentry.start_transaction(name: "nested") | ||
|
|
||
| ProfilerTest::Bar.bar | ||
|
|
||
| expect(Sentry.get_current_hub.profiler_running?).to be(true) | ||
|
|
||
| expect(parent_transaction.profiler).to_not be_nil | ||
| expect(nested_transaction.profiler).to be_nil | ||
|
|
||
| nested_transaction.finish | ||
| parent_transaction.finish | ||
| end | ||
| end | ||
| end |
Uh oh!
There was an error while loading. Please reload this page.