diff --git a/sentry-ruby/lib/sentry-ruby.rb b/sentry-ruby/lib/sentry-ruby.rb index 3919b9655..c961d732a 100644 --- a/sentry-ruby/lib/sentry-ruby.rb +++ b/sentry-ruby/lib/sentry-ruby.rb @@ -301,6 +301,8 @@ def close if client = get_current_client client.configuration.run_after_close_callbacks client.flush + client.log_event_buffer.kill + client.metric_event_buffer.kill if client.configuration.data_collection.collect_stack_frame_variables? exception_locals_tp.disable diff --git a/sentry-ruby/lib/sentry/client.rb b/sentry-ruby/lib/sentry/client.rb index 5896bd653..a44e0af30 100644 --- a/sentry-ruby/lib/sentry/client.rb +++ b/sentry-ruby/lib/sentry/client.rb @@ -130,8 +130,8 @@ def capture_envelope(envelope) def flush transport.flush if configuration.sending_to_dsn_allowed? spotlight_transport.flush if spotlight_transport - @log_event_buffer&.flush - @metric_event_buffer&.flush + @log_event_buffer.flush + @metric_event_buffer.flush end # Initializes an Event object with the given exception. Returns `nil` if the exception's class is excluded from reporting. diff --git a/sentry-ruby/spec/sentry_spec.rb b/sentry-ruby/spec/sentry_spec.rb index 85cdae3a5..77430216b 100644 --- a/sentry-ruby/spec/sentry_spec.rb +++ b/sentry-ruby/spec/sentry_spec.rb @@ -1594,6 +1594,21 @@ described_class.close end + it "kills telemetry workers" do + client = described_class.get_current_client + client.log_event_buffer.add_item(Sentry::LogEvent.new(level: :info, body: "log")) + client.metric_event_buffer.add_item(Sentry::MetricEvent.new(name: "metric", type: :counter, value: 1)) + log_thread = client.log_event_buffer.thread + metric_thread = client.metric_event_buffer.thread + + described_class.close + + expect(log_thread.join(1)).to eq(log_thread) + expect(metric_thread.join(1)).to eq(metric_thread) + expect(log_thread).not_to be_alive + expect(metric_thread).not_to be_alive + end + it "flushes session flusher" do expect(described_class.session_flusher).to receive(:flush) described_class.close