Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ public struct SentrySDKWrapper {
}
#endif // !os(macOS) && !os(tvOS) && !os(watchOS) && !os(visionOS)

options.enableLogs = true

// Experimental features
options.experimental.enableFileManagerSwizzling = !SentrySDKOverrides.Other.disableFileManagerSwizzling.boolValue
options.experimental.enableUnhandledCPPExceptionsV2 = true
options.experimental.enableLogs = true
}

func configureInitialScope(scope: Scope, options: Options) -> Scope {
Expand Down
7 changes: 7 additions & 0 deletions Sources/Sentry/Public/SentryOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ NS_SWIFT_NAME(Options)
*/
@property (nullable, nonatomic, copy) SentryBeforeSendSpanCallback beforeSendSpan NS_SWIFT_SENDABLE;

/**
* When enabled, the SDK sends logs to Sentry. Logs can be captured using the @c SentrySDK.logger
* API, which provides structured logging with attributes.
* @note Default value is @c NO .
*/
@property (nonatomic, assign) BOOL enableLogs;

#if !SWIFT_PACKAGE
/**
* Use this callback to drop or modify a log before the SDK sends it to Sentry. Return @c nil to
Expand Down
1 change: 1 addition & 0 deletions Sources/Sentry/SentryOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ - (instancetype)init
self.enableNetworkTracking = YES;
self.enableFileIOTracing = YES;
self.enableNetworkBreadcrumbs = YES;
self.enableLogs = NO;
self.tracesSampleRate = nil;
#if SENTRY_TARGET_PROFILING_SUPPORTED
# if !SDK_V9
Expand Down
8 changes: 8 additions & 0 deletions Sources/Sentry/SentyOptionsInternal.m
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ + (BOOL)validateOptions:(NSDictionary<NSString *, id> *)options
sentryOptions.maxBreadcrumbs = [options[@"maxBreadcrumbs"] unsignedIntValue];
}

[self setBool:options[@"enableLogs"] block:^(BOOL value) { sentryOptions.enableLogs = value; }];

[self setBool:options[@"enableNetworkBreadcrumbs"]
block:^(BOOL value) { sentryOptions.enableNetworkBreadcrumbs = value; }];

Expand All @@ -176,6 +178,12 @@ + (BOOL)validateOptions:(NSDictionary<NSString *, id> *)options
sentryOptions.beforeSend = options[@"beforeSend"];
}

#if !SWIFT_PACKAGE
if ([self isBlock:options[@"beforeSendLog"]]) {
sentryOptions.beforeSendLog = options[@"beforeSendLog"];
}
#endif // !SWIFT_PACKAGE

if ([self isBlock:options[@"beforeSendSpan"]]) {
sentryOptions.beforeSendSpan = options[@"beforeSendSpan"];
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Swift/Helper/SentrySDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import Foundation
}
let hub = SentryDependencyContainerSwiftHelper.currentHub()
var batcher: SentryLogBatcher?
if let client = hub.getClient(), client.options.experimental.enableLogs {
if let client = hub.getClient(), client.options.enableLogs {
batcher = SentryLogBatcher(client: client, dispatchQueue: Dependencies.dispatchQueueWrapper)
}
let logger = SentryLogger(
Expand Down
5 changes: 0 additions & 5 deletions Sources/Swift/SentryExperimentalOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ public final class SentryExperimentalOptions: NSObject {
*/
public var enableUnhandledCPPExceptionsV2 = false

/**
* Logs are considered beta.
*/
public var enableLogs = false

@_spi(Private) public func validateOptions(_ options: [String: Any]?) {
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SentryTests/SentryLogBatcherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class SentryLogBatcherTests: XCTestCase {
super.setUp()

options = Options()
options.experimental.enableLogs = true
options.enableLogs = true

testClient = TestClient(options: options)
testDispatchQueue = TestSentryDispatchQueueWrapper()
Expand Down
2 changes: 1 addition & 1 deletion Tests/SentryTests/SentryLoggerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ final class SentryLoggerTests: XCTestCase {
}

func testCaptureLog_SetsTraceIdFromPropagationContext() {
fixture.options.experimental.enableLogs = true
fixture.options.enableLogs = true

let expectedTraceId = SentryId()
let propagationContext = SentryPropagationContext(trace: expectedTraceId, spanId: SpanId())
Expand Down
32 changes: 32 additions & 0 deletions Tests/SentryTests/SentryOptionsTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ - (void)testEnableNetworkBreadcrumbs
[self testBooleanField:@"enableNetworkBreadcrumbs"];
}

- (void)testEnableLogs
{
[self testBooleanField:@"enableLogs" defaultValue:NO];
}

- (void)testEnableAutoBreadcrumbTracking
{
[self testBooleanField:@"enableAutoBreadcrumbTracking"];
Expand Down Expand Up @@ -306,6 +311,30 @@ - (void)testNSNullBeforeSend_ReturnsNil
XCTAssertFalse([options.beforeSend isEqual:[NSNull null]]);
}

#if !SWIFT_PACKAGE
- (void)testBeforeSendLog
{
SentryBeforeSendLogCallback callback = ^(SentryLog *log) { return log; };
SentryOptions *options = [self getValidOptions:@{ @"beforeSendLog" : callback }];

XCTAssertEqual(callback, options.beforeSendLog);
}

- (void)testDefaultBeforeSendLog
{
SentryOptions *options = [self getValidOptions:@{}];

XCTAssertNil(options.beforeSendLog);
}

- (void)testGarbageBeforeSendLog_ReturnsNil
{
SentryOptions *options = [self getValidOptions:@{ @"beforeSendLog" : @"fault" }];

XCTAssertNil(options.beforeSendLog);
}
#endif // !SWIFT_PACKAGE

- (void)testBeforeSendSpan
{
SentryBeforeSendSpanCallback callback = ^(id<SentrySpan> span) { return span; };
Expand Down Expand Up @@ -615,6 +644,9 @@ - (void)testNSNull_SetsDefaultValue
@"maxCacheItems" : [NSNull null],
@"cacheDirectoryPath" : [NSNull null],
@"beforeSend" : [NSNull null],
#if !SWIFT_PACKAGE
@"beforeSendLog" : [NSNull null],
#endif
@"beforeBreadcrumb" : [NSNull null],
@"onCrashedLastRun" : [NSNull null],
@"integrations" : [NSNull null],
Expand Down
6 changes: 3 additions & 3 deletions Tests/SentryTests/SentrySDKInternalTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ class SentrySDKInternalTests: XCTestCase {

@available(*, deprecated, message: "This is deprecated because SentryOptions integrations is deprecated")
func testLogger_WithLogsEnabled_CapturesLog() {
fixture.client.options.experimental.enableLogs = true
fixture.client.options.enableLogs = true
givenSdkWithHub()

SentrySDK.logger.error(String(repeating: "S", count: 1_024 * 1_024))
Expand All @@ -716,7 +716,7 @@ class SentrySDKInternalTests: XCTestCase {
}

func testLogger_WithNoClient_DoesNotCaptureLog() {
fixture.client.options.experimental.enableLogs = true
fixture.client.options.enableLogs = true
let hubWithoutClient = SentryHub(client: nil, andScope: nil)
SentrySDKInternal.setCurrentHub(hubWithoutClient)

Expand All @@ -733,7 +733,7 @@ class SentrySDKInternalTests: XCTestCase {

@available(*, deprecated, message: "This is deprecated because SentryOptions integrations is deprecated")
func testLogger_WithLogsDisabled_DoesNotCaptureLog() {
fixture.client.options.experimental.enableLogs = false
fixture.client.options.enableLogs = false
givenSdkWithHub()

SentrySDK.logger.error("foo")
Expand Down
8 changes: 4 additions & 4 deletions Tests/SentryTests/SentrySDKTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ class SentrySDKTests: XCTestCase {
// MARK: - Logger Flush Tests

func testFlush_CallsLoggerCaptureLogs() {
fixture.client.options.experimental.enableLogs = true
fixture.client.options.enableLogs = true
SentrySDKInternal.setCurrentHub(fixture.hub)
SentrySDKInternal.setStart(with: fixture.client.options)

Expand All @@ -462,7 +462,7 @@ class SentrySDKTests: XCTestCase {
}

func testClose_CallsLoggerCaptureLogs() {
fixture.client.options.experimental.enableLogs = true
fixture.client.options.enableLogs = true
SentrySDKInternal.setCurrentHub(fixture.hub)
SentrySDKInternal.setStart(with: fixture.client.options)

Expand All @@ -484,7 +484,7 @@ class SentrySDKTests: XCTestCase {
let loggerBeforeStart = SentrySDK.logger

// Now properly start the SDK using internal APIs
fixture.client.options.experimental.enableLogs = true
fixture.client.options.enableLogs = true
SentrySDKInternal.setCurrentHub(fixture.hub)
SentrySDKInternal.setStart(with: fixture.client.options)

Expand All @@ -506,7 +506,7 @@ class SentrySDKTests: XCTestCase {

func testLogger_WhenLogsDisabled() {
// Start SDK with logs disabled
fixture.client.options.experimental.enableLogs = false
fixture.client.options.enableLogs = false
SentrySDKInternal.setCurrentHub(fixture.hub)
SentrySDKInternal.setStart(with: fixture.client.options)

Expand Down
Loading
Loading