Skip to content
Open
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
6 changes: 1 addition & 5 deletions sentry-rails/lib/sentry/rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ class Configuration
end
end
end

after(:configured) do
rails.structured_logging.enabled = enable_logs if rails.structured_logging.enabled.nil?
end
end

module Rails
Expand Down Expand Up @@ -218,7 +214,7 @@ class StructuredLoggingConfiguration
}.freeze

def initialize
@enabled = nil
@enabled = false
@subscribers = DEFAULT_SUBSCRIBERS.dup
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module LogSubscribers
# @example Usage
# # Enable structured logging for ActionController
# Sentry.init do |config|
# config.enable_logs = true
# config.rails.structured_logging = true
# config.rails.structured_logging.subscribers = { action_controller: Sentry::Rails::LogSubscribers::ActionControllerSubscriber }
# end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module LogSubscribers
# @example Usage
# # Enable structured logging for ActionMailer
# Sentry.init do |config|
# config.enable_logs = true
# config.rails.structured_logging = true
# config.rails.structured_logging.subscribers = { action_mailer: Sentry::Rails::LogSubscribers::ActionMailerSubscriber }
# end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module LogSubscribers
# @example Usage
# # Enable structured logging for ActiveJob
# Sentry.init do |config|
# config.enable_logs = true
# config.rails.structured_logging = true
# config.rails.structured_logging.subscribers = { active_job: Sentry::Rails::LogSubscribers::ActiveJobSubscriber }
# end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module LogSubscribers
# @example Usage
# # Automatically attached when structured logging is enabled for :active_record
# Sentry.init do |config|
# config.enable_logs = true
# config.rails.structured_logging = true
# config.rails.structured_logging.subscribers = { active_record: Sentry::Rails::LogSubscribers::ActiveRecordSubscriber }
# end
Expand Down
2 changes: 1 addition & 1 deletion sentry-rails/lib/sentry/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def activate_tracing
end

def activate_structured_logging
if Sentry.configuration.rails.structured_logging.enabled? && Sentry.configuration.enable_logs
if Sentry.configuration.rails.structured_logging.enabled?
Sentry::Rails::StructuredLogging.attach(Sentry.configuration.rails.structured_logging)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
RSpec.shared_examples "an ActiveJob backend that produces structured logs" do
let(:configure_sentry) do
proc do |config, _app|
config.enable_logs = true
config.rails.structured_logging.enabled = true
config.rails.structured_logging.subscribers = {
active_job: Sentry::Rails::LogSubscribers::ActiveJobSubscriber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
proc do |config|
config.traces_sample_rate = 1.0
config.send_default_pii = true
config.enable_logs = true
end
end

Expand Down
2 changes: 1 addition & 1 deletion sentry-rails/spec/active_job/support/harness.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def perform(*_args, **_kwargs)
Sentry::Rails::Tracing.patch_active_support_notifications
end

if Sentry.configuration.rails.structured_logging.enabled? && Sentry.configuration.enable_logs
if Sentry.configuration.rails.structured_logging.enabled?
Sentry::Rails::StructuredLogging.attach(Sentry.configuration.rails.structured_logging)
end

Expand Down
2 changes: 0 additions & 2 deletions sentry-rails/spec/isolated/rails_logger_patch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
context "when :logger patch is enabled" do
before do
make_basic_app do |config, app|
config.enable_logs = true
config.enabled_patches = [:logger]
config.max_log_events = 10
config.sdk_logger = Logger.new(nil)
Expand Down Expand Up @@ -202,7 +201,6 @@
let(:broadcast_logger) { ActiveSupport::BroadcastLogger.new(logger1, logger2) }
let(:broadcast_app) do
make_basic_app do |config|
config.enable_logs = true
config.enabled_patches = [:logger]
config.max_log_events = 10
config.sdk_logger = Logger.new(nil)
Expand Down
17 changes: 3 additions & 14 deletions sentry-rails/spec/sentry/rails/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,15 @@ class MySubscriber; end
expect(config.structured_logging.subscribers).to be_a(Hash)
end

it "auto-enables when enable_logs is true and not explicitly set" do
make_basic_app do |config|
config.enable_logs = true
end

expect(config.structured_logging.enabled?).to be(true)
end

it "remains disabled when enable_logs is false" do
make_basic_app do |config|
config.enable_logs = false
end
it "disables structured logging by default" do
make_basic_app

expect(config.structured_logging.enabled?).to be(false)
end

it "respects explicit disable even when enable_logs is true" do
it "respects explicit disable" do
make_basic_app do |config|
config.rails.structured_logging.enabled = false
config.enable_logs = true
end

expect(config.structured_logging.enabled?).to be(false)
Expand Down
2 changes: 0 additions & 2 deletions sentry-rails/spec/sentry/rails/log_subscriber_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def error_test_event(event)

before do
make_basic_app do |config|
config.enable_logs = true
config.structured_logging.logger_class = Sentry::DebugStructuredLogger
# Disable default structured logging subscribers to avoid interference
config.rails.structured_logging.enabled = false
Expand Down Expand Up @@ -243,7 +242,6 @@ def filtering_event(event)

before do
make_basic_app do |config, app|
config.enable_logs = true
config.structured_logging.logger_class = Sentry::DebugStructuredLogger
config.send_default_pii = true
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
context "when logging is enabled" do
before do
make_basic_app do |config, app|
config.enable_logs = true

config.rails.structured_logging.enabled = true
config.rails.structured_logging.subscribers = { action_controller: Sentry::Rails::LogSubscribers::ActionControllerSubscriber }
end
Expand Down Expand Up @@ -380,9 +378,7 @@
context "when logging is disabled" do
before do
make_basic_app do |config|
config.enable_logs = false

config.rails.structured_logging.enabled = true
config.rails.structured_logging.enabled = false
config.rails.structured_logging.subscribers = { action_controller: Sentry::Rails::LogSubscribers::ActionControllerSubscriber }
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
context "when logging is enabled" do
before do
make_basic_app do |config|
config.enable_logs = true

config.rails.structured_logging.enabled = true
config.rails.structured_logging.subscribers = { action_mailer: Sentry::Rails::LogSubscribers::ActionMailerSubscriber }
end
Expand Down Expand Up @@ -230,9 +228,7 @@
context "when logging is disabled" do
before do
make_basic_app do |config|
config.enable_logs = false

config.rails.structured_logging.enabled = true
config.rails.structured_logging.enabled = false
config.rails.structured_logging.subscribers = { action_mailer: Sentry::Rails::LogSubscribers::ActionMailerSubscriber }
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
context "when logging is enabled" do
before do
make_basic_app do |config|
config.enable_logs = true

config.rails.structured_logging.enabled = true
config.rails.structured_logging.subscribers = { active_job: Sentry::Rails::LogSubscribers::ActiveJobSubscriber }
end
Expand Down Expand Up @@ -329,9 +327,7 @@ def perform(*args, **kwargs)
context "when logging is disabled" do
before do
make_basic_app do |config|
config.enable_logs = false

config.rails.structured_logging.enabled = true
config.rails.structured_logging.enabled = false
config.rails.structured_logging.subscribers = { active_job: Sentry::Rails::LogSubscribers::ActiveJobSubscriber }
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
context "when logging is enabled" do
before do
make_basic_app do |config|
config.enable_logs = true

config.rails.structured_logging.enabled = true
config.rails.structured_logging.subscribers = { active_record: Sentry::Rails::LogSubscribers::ActiveRecordSubscriber }
end
Expand Down Expand Up @@ -62,7 +60,7 @@
sentry_transport.events.clear
sentry_transport.envelopes.clear

created_at = Time.new(2025, 10, 28, 13, 11, 44)
created_at = Time.utc(2025, 10, 28, 13, 11, 44)
Post.where(id: post.id, title: post.title, created_at: created_at).to_a

Sentry.get_current_client.flush
Expand Down Expand Up @@ -350,8 +348,6 @@
context "when logger is silenced" do
before do
make_basic_app do |config, app|
config.enable_logs = true

config.rails.structured_logging.enabled = true
config.rails.structured_logging.subscribers = {
active_record: Sentry::Rails::LogSubscribers::ActiveRecordSubscriber
Expand Down Expand Up @@ -380,9 +376,7 @@
context "when logging is disabled" do
before do
make_basic_app do |config|
config.enable_logs = false

config.rails.structured_logging.enabled = true
config.rails.structured_logging.enabled = false
config.rails.structured_logging.subscribers = { active_record: Sentry::Rails::LogSubscribers::ActiveRecordSubscriber }
end
end
Expand Down
26 changes: 3 additions & 23 deletions sentry-rails/spec/sentry/rails/structured_logging_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,9 @@
require "spec_helper"

RSpec.describe Sentry::Rails::StructuredLogging, type: :request do
context "when sentry structured logging is disabled" do
before do
make_basic_app do |config|
config.enable_logs = false
config.rails.structured_logging.enabled = true
end
end

it "does not capture structured logs" do
get "/posts"

Post.first

Sentry.get_current_client.flush

expect(sentry_logs).to be_empty
end
end

context "when rails structured logging is disabled" do
before do
make_basic_app do |config|
config.enable_logs = true
config.rails.structured_logging.enabled = false
end
end
Expand All @@ -41,14 +21,14 @@
end
end

context "when enable_logs is true and structured logging is auto-enabled" do
context "when structured logging is enabled" do
before do
make_basic_app do |config|
config.enable_logs = true
config.rails.structured_logging.enabled = true
end
end

it "captures structured logs automatically" do
it "captures structured logs" do
get "/posts"

Post.first
Expand Down
3 changes: 3 additions & 0 deletions sentry-rails/spec/sentry/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@
end

it "doesn't cause error if Rails::Logger is not present during SDK initialization" do
rails_logger = Rails.logger
Rails.logger = nil

Sentry.init

expect(Sentry.configuration.sdk_logger).to be_a(Sentry::Logger)
ensure
Rails.logger = rails_logger
end
end

Expand Down
12 changes: 2 additions & 10 deletions sentry-ruby/lib/sentry-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def capture_check_in(slug, status, **options)
# Sentry.capture_log("User logged in", level: :info, user_id: 123)
#
# @see https://develop.sentry.dev/sdk/telemetry/logs/ Sentry SDK Telemetry Logs Protocol
# @return [LogEvent, nil] The created log event or nil if logging is disabled
# @return [LogEvent, nil] The created log event or nil if Sentry is not initialized
def capture_log(message, **options)
return unless initialized?
get_current_hub.capture_log_event(message, **options)
Expand Down Expand Up @@ -639,14 +639,6 @@ def continue_trace(env, **options)

# Returns the structured logger instance that implements Sentry's SDK telemetry logs protocol.
#
# This logger is only available when logs are enabled in the configuration.
#
# @example Enable logs in configuration
# Sentry.init do |config|
# config.dsn = "YOUR_DSN"
# config.enable_logs = true
# end
#
# @example Basic usage
# Sentry.logger.info("User logged in successfully", user_id: 123)
# Sentry.logger.error("Failed to process payment",
Expand All @@ -656,7 +648,7 @@ def continue_trace(env, **options)
#
# @see https://develop.sentry.dev/sdk/telemetry/logs/ Sentry SDK Telemetry Logs Protocol
#
# @return [StructuredLogger] The structured logger instance or nil if logs are disabled
# @return [StructuredLogger] The structured logger instance
def logger
@logger ||= configuration.structured_logging.logger_class.new(configuration)
end
Expand Down
4 changes: 1 addition & 3 deletions sentry-ruby/lib/sentry/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ def initialize(configuration)

@spotlight_transport = SpotlightTransport.new(configuration) if configuration.spotlight

if configuration.enable_logs
@log_event_buffer = LogEventBuffer.new(configuration, self)
end
@log_event_buffer = LogEventBuffer.new(configuration, self)

if configuration.enable_metrics
@metric_event_buffer = MetricEventBuffer.new(configuration, self)
Expand Down
5 changes: 0 additions & 5 deletions sentry-ruby/lib/sentry/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,6 @@ class Configuration
# @return [Proc]
attr_accessor :traces_sampler

# Enable Structured Logging
# @return [Boolean]
attr_accessor :enable_logs

# Structured logging configuration.
# @return [StructuredLoggingConfiguration]
attr_reader :structured_logging
Expand Down Expand Up @@ -578,7 +574,6 @@ def initialize
self.std_lib_logger_filter = nil
self.rack_env_whitelist = RACK_ENV_WHITELIST_DEFAULT
self.traces_sampler = nil
self.enable_logs = false
self.enable_metrics = true

self.profiler_class = Sentry::Profiler
Expand Down
Loading
Loading