Skip to content

Commit 4f45d12

Browse files
feat: remove enableLogs option in v10 (#8769)
* feat: remove enableLogs option in v10 In SDK_V10, logs are always on. Gate enableLogs behind #if !SDK_V10 and drop v10 call sites that set or test it. Co-Authored-By: Noah Martin <noah.martin@sentry.io> * style: fix clang-format pragma indent --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Noah Martin <noah.martin@sentry.io>
1 parent 71f6491 commit 4f45d12

16 files changed

Lines changed: 40 additions & 109 deletions

File tree

CHANGELOG_V10.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
- Enable MetricKit integration by default (#8716)
2121
- Enable logging by default (#8717)
22+
- Remove `enableLogs`; logs are always enabled in v10 (#8769)
2223
- Change the default diagnostic level to warning (#8732)
2324
- Enable `swiftAsyncStacktraces` by default (#8718)
2425
- Remove `sendDefaultPii`; use `dataCollection` to configure automatic data collection (#8253)

Samples/SentrySampleShared/SentrySampleShared/SentrySDKWrapper.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ public struct SentrySDKWrapper {
268268
#endif // !os(macOS) && !os(tvOS) && !os(watchOS) && !os(visionOS)
269269

270270
// Integration: Logs
271+
#if !SDK_V10
271272
options.enableLogs = !SentrySDKOverrides.Logs.disable.boolValue
273+
#endif // !SDK_V10
272274

273275
// Integration: Metrics
274276
options.enableMetrics = SentrySDKOverrides.Metrics.enable.boolValue

Samples/iOS-SwiftUI-SPM/Sources/MainApp.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ struct MainApp: App {
1414
options.enableTimeToFullDisplayTracing = true
1515
options.attachScreenshot = true
1616
options.enableMetricKit = true
17+
#if !SDK_V10
1718
options.enableLogs = true
19+
#endif // !SDK_V10
1820

1921
#if targetEnvironment(simulator)
2022
options.enableSpotlight = true

Sources/Sentry/SentryClient.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,10 +1165,12 @@ - (void)_swiftCaptureLog:(NSObject *)log withScope:(SentryScope *)scope
11651165
return;
11661166
}
11671167

1168+
#if !SDK_V10
11681169
if (self.options.enableLogs == NO) {
11691170
SENTRY_LOG_DEBUG(@"Dropping log, because the option enableLogs is false.");
11701171
return;
11711172
}
1173+
#endif // !SDK_V10
11721174

11731175
if (![log isKindOfClass:[SentryLog class]]) {
11741176
return;

Sources/Sentry/SentryDependencyContainerSwiftHelper.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ + (NSString *)environment:(SentryOptions *)options
4242

4343
+ (BOOL)enableLogs:(SentryOptions *)options
4444
{
45+
#if SDK_V10
46+
return YES;
47+
#else
4548
return options.enableLogs;
49+
#endif // SDK_V10
4650
}
4751

4852
+ (NSArray<NSString *> *)enabledFeatures:(SentryOptions *)options

Sources/SentryObjC/Public/SentryObjCOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,15 @@ NS_ASSUME_NONNULL_BEGIN
134134
*/
135135
@property (nonatomic, copy, nullable) SentryObjCSpan *_Nullable (^beforeSendSpan)(SentryObjCSpan *);
136136

137+
#if !SDK_V10
137138
/**
138139
* When enabled, the SDK sends logs to Sentry. Logs can be captured using the
139140
* @c SentryObjCSDK.logger API, which provides structured logging with attributes.
140141
* @note Default value is @c NO.
142+
* @note In v10 and later, logs are always enabled. Remove this option when upgrading.
141143
*/
142144
@property (nonatomic) BOOL enableLogs;
145+
#endif // !SDK_V10
143146

144147
/// This block can be used to modify the breadcrumb before it will be serialized and sent.
145148
@property (nonatomic, copy, nullable) SentryObjCBreadcrumb *_Nullable (^beforeBreadcrumb)

Sources/SentryObjCCompat/SentryObjCOptions.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,12 @@ import Foundation
122122
}
123123
}
124124

125+
#if !SDK_V10
125126
@objc public var enableLogs: Bool {
126127
get { wrapped.enableLogs }
127128
set { wrapped.enableLogs = newValue }
128129
}
130+
#endif // !SDK_V10
129131

130132
@objc public var beforeBreadcrumb: ((SentryObjCBreadcrumb) -> SentryObjCBreadcrumb?)? {
131133
didSet {

Sources/Swift/Options+Dictionary.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ extension Options {
7777
self.maxBreadcrumbs = maxBreadcrumbs.uintValue
7878
}
7979

80+
#if !SDK_V10
8081
if let enableLogs = boolValue(dictionary["enableLogs"]) {
8182
self.enableLogs = enableLogs
8283
}
84+
#endif // !SDK_V10
8385

8486
if let enableMetrics = boolValue(dictionary["enableMetrics"]) {
8587
self.enableMetrics = enableMetrics

Sources/Swift/Options.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,13 @@
142142
/// drop the span.
143143
@objc public var beforeSendSpan: SentryBeforeSendSpanCallback?
144144

145+
#if !SDK_V10
145146
/// When enabled, the SDK sends logs to Sentry. Logs can be captured using the SentrySDK.logger
146147
/// API, which provides structured logging with attributes.
147-
/// @note Default value is @c true in v10, @c false in earlier versions.
148-
@objc public var enableLogs: Bool = {
149-
#if SDK_V10
150-
return true
151-
#else
152-
return false
153-
#endif // SDK_V10
154-
}()
148+
/// @note Default value is @c false.
149+
/// @note In v10 and later, logs are always enabled. Remove this option when upgrading.
150+
@objc public var enableLogs: Bool = false
151+
#endif // !SDK_V10
155152

156153
/// Use this callback to drop or modify a log before the SDK sends it to Sentry. Return nil to
157154
/// drop the log.

Tests/SentryObjCTests/SentryObjCLoggerTests.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ - (void)setUp
1414
[SentryObjCSDK startWithConfigureOptions:^(SentryObjCOptions *options) {
1515
options.dsn = @"https://key@sentry.io/123";
1616
options.enableCrashHandler = NO;
17+
#if !SDK_V10
1718
options.enableLogs = YES;
19+
#endif // !SDK_V10
1820
options.beforeSendLog = ^SentryObjCLog *(SentryObjCLog *log) {
1921
weakSelf.capturedLog = log;
2022
return log;
@@ -858,7 +860,8 @@ - (void)testDebugWithFormat_withTrailingPercent_shouldNotCrash
858860
XCTAssertNil(self.capturedLog.attributes[@"sentry.message.template"]);
859861
}
860862

861-
#pragma mark - logs disabled
863+
#if !SDK_V10
864+
# pragma mark - logs disabled
862865

863866
- (void)testLoggerMethod_whenLogsDisabled_shouldNotCrash
864867
{
@@ -875,5 +878,6 @@ - (void)testLoggerMethod_whenLogsDisabled_shouldNotCrash
875878
[SentryObjCSDK.logger debugWithFormat:@"User %@ count %d", @"test", 5];
876879
[SentryObjCSDK.logger debugWithAttributes:@{ @"k" : @"v" } format:@"Val: %f", 1.0];
877880
}
881+
#endif // !SDK_V10
878882

879883
@end

0 commit comments

Comments
 (0)