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

Only instantiate SessionFlusher when the SDK is enabled under the current env #2245

Merged
merged 2 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
- Fix warning about default gems on Ruby 3.3.0 ([#2225](https://github.com/getsentry/sentry-ruby/pull/2225))
- Add `hint:` support to `Sentry::Rails::ErrorSubscriber` [#2235](https://github.com/getsentry/sentry-ruby/pull/2235)

### Bug Fixes

- Only instantiate SessionFlusher when the SDK is enabled under the current env [#2245](https://github.com/getsentry/sentry-ruby/pull/2245)
- Fixes [#2234](https://github.com/getsentry/sentry-ruby/issues/2234)

## 5.16.1

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def init(&block)
Thread.current.thread_variable_set(THREAD_LOCAL, hub)
@main_hub = hub
@background_worker = Sentry::BackgroundWorker.new(config)
@session_flusher = config.auto_session_tracking ? Sentry::SessionFlusher.new(config, client) : nil
@session_flusher = config.session_tracking? ? Sentry::SessionFlusher.new(config, client) : nil
@backpressure_monitor = config.enable_backpressure_handling ? Sentry::BackpressureMonitor.new(config, client) : nil
exception_locals_tp.enable if config.include_local_variables
at_exit { close }
Expand Down
4 changes: 4 additions & 0 deletions sentry-ruby/lib/sentry/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,10 @@ def sample_allowed?
Random.rand < sample_rate
end

def session_tracking?
auto_session_tracking && enabled_in_current_env?
end

def exception_class_allowed?(exc)
if exc.is_a?(Sentry::Error)
# Try to prevent error reporting loops
Expand Down
37 changes: 37 additions & 0 deletions sentry-ruby/spec/sentry/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,43 @@ class SentryConfigurationSample < Sentry::Configuration
end
end

describe "session_tracking?" do
before do
subject.enabled_environments = %w[production]
end

context "when auto_session_tracking is true" do
before do
subject.auto_session_tracking = true
end

it "returns true when in enabled_environments" do
subject.environment = "production"
expect(subject.session_tracking?).to eq(true)
end

it "returns false when not in enabled_environments" do
subject.environment = "test"
expect(subject.session_tracking?).to eq(false)
end
end

context "when auto_session_tracking is false" do
before do
subject.auto_session_tracking = false
end
it "returns false when in enabled_environments" do
subject.environment = "production"
expect(subject.session_tracking?).to eq(false)
end

it "returns false when not in enabled_environments" do
subject.environment = "test"
expect(subject.session_tracking?).to eq(false)
end
end
end

describe "#trace_propagation_targets" do
it "returns match all by default" do
expect(subject.trace_propagation_targets).to eq([/.*/])
Expand Down
21 changes: 21 additions & 0 deletions sentry-ruby/spec/sentry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,27 @@
current_scope = described_class.get_current_scope
expect(current_scope.breadcrumbs.buffer.size).to eq(1)
end

context "with config.auto_session_tracking = true" do
it "initializes session flusher" do
described_class.init do |config|
config.auto_session_tracking = true
end

expect(described_class.session_flusher).to be_a(Sentry::SessionFlusher)
end

context "when it's not under the enabled environment" do
it "doesn't initialize any session flusher" do
described_class.init do |config|
config.auto_session_tracking = true
config.enabled_environments = ["production"]
end

expect(described_class.session_flusher).to be_nil
end
end
end
end

describe "#clone_hub_to_current_thread" do
Expand Down
Loading