Skip to content

Commit d9034a0

Browse files
authored
Always set up the StructuredLogger and no-op capture_log_event if logs (#2752)
are disabled
1 parent 4d9c5d1 commit d9034a0

File tree

4 files changed

+6
-20
lines changed

4 files changed

+6
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Remove deprecated `config.capture_exception_frame_locals`, use `include_local_variables` instead ([#2730](https://github.com/getsentry/sentry-ruby/pull/2730))
1111
- Remove deprecated `config.enable_tracing`, use `config.traces_sample_rate = 1.0` instead ([#2731](https://github.com/getsentry/sentry-ruby/pull/2731))
1212
- Remove deprecated `config.logger=`, use `config.sdk_logger=` instead ([#2732](https://github.com/getsentry/sentry-ruby/pull/2732))
13+
- `Sentry.logger` now always points to the `StructuredLogger` ([#2752](https://github.com/getsentry/sentry-ruby/pull/2752))
1314
- Remove deprecated `Sentry::Rails::Tracing::ActionControllerSubscriber` ([#2733](https://github.com/getsentry/sentry-ruby/pull/2733))
1415
- Remove deprecated `Event#configuration` ([#2740](https://github.com/getsentry/sentry-ruby/pull/2740))
1516
- Remove deprecated `Sentry::Client#generate_sentry_trace` and `Sentry::Client#generate_baggage` ([#2741](https://github.com/getsentry/sentry-ruby/pull/2741))

sentry-ruby/lib/sentry-ruby.rb

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -622,24 +622,9 @@ def continue_trace(env, **options)
622622
#
623623
# @see https://develop.sentry.dev/sdk/telemetry/logs/ Sentry SDK Telemetry Logs Protocol
624624
#
625-
# @return [StructuredLogger, nil] The structured logger instance or nil if logs are disabled
625+
# @return [StructuredLogger] The structured logger instance or nil if logs are disabled
626626
def logger
627-
@logger ||=
628-
if configuration.enable_logs
629-
# Initialize the public-facing Structured Logger if logs are enabled
630-
# Use configured structured logger class or default to StructuredLogger
631-
# @see https://develop.sentry.dev/sdk/telemetry/logs/
632-
configuration.structured_logging.logger_class.new(configuration)
633-
else
634-
warn <<~STR
635-
[sentry] `Sentry.logger` will no longer be used as internal SDK logger when `enable_logs` feature is turned on.
636-
Use Sentry.configuration.sdk_logger for SDK-specific logging needs."
637-
638-
Caller: #{caller.first}
639-
STR
640-
641-
configuration.sdk_logger
642-
end
627+
@logger ||= configuration.structured_logging.logger_class.new(configuration)
643628
end
644629

645630
##### Helpers #####

sentry-ruby/lib/sentry/hub.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def capture_check_in(slug, status, **options)
218218
end
219219

220220
def capture_log_event(message, **options)
221-
return unless current_client
221+
return unless current_client && current_client.configuration.enable_logs
222222

223223
event = current_client.event_from_log(message, **options)
224224

sentry-ruby/spec/sentry/structured_logger_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
end
99
end
1010

11-
it "configures default SDK logger" do
12-
expect(Sentry.logger).to be(Sentry.configuration.sdk_logger)
11+
it "initializes" do
12+
expect(Sentry.logger).to be_a(described_class)
1313
end
1414
end
1515

0 commit comments

Comments
 (0)